Skip to content

Commit 9babc04

Browse files
committed
replace monkey patching prooperty with WeakSet
1 parent bab060a commit 9babc04

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/util.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
const wrappedMethods = new WeakSet();
23

34
exports.getBooleanOption = (options, key) => {
45
let value = false;
@@ -13,8 +14,9 @@ exports.wrap = (Class, methodName, wrapper) => {
1314
if (typeof originalMethod !== 'function') {
1415
throw new TypeError(`Missing method ${methodName}`);
1516
}
16-
if (!originalMethod.alreadyWrapped) {
17-
Class.prototype[methodName] = wrapper(originalMethod);
18-
Class.prototype[methodName].alreadyWrapped = true;
17+
if (!wrappedMethods.has(originalMethod)) {
18+
const wrapped = wrapper(originalMethod);
19+
wrappedMethods.add(wrapped);
20+
Class.prototype[methodName] = wrapped;
1921
}
2022
};

0 commit comments

Comments
 (0)