'use strict';

exports.getBooleanOption = (options, key) => {
	let value = false;
	if (key in options && typeof (value = options[key]) !== 'boolean') {
		throw new TypeError(`Expected the "${key}" option to be a boolean`);
	}
	return value;
};

exports.wrap = (Class, methodName, wrapper) => {
	const originalMethod = Class.prototype[methodName];
	if (typeof originalMethod !== 'function') {
		throw new TypeError(`Missing method ${methodName}`);
	}
	if (!originalMethod.alreadyWrapped) {
		Class.prototype[methodName] = wrapper(originalMethod);
		Class.prototype[methodName].alreadyWrapped = true;
	}
};

@@ -6,16 +6,54 @@
 strict';
+%0Aconst wrappedMethods = new WeakSet();
 %0A%0Aexport
@@ -491,94 +491,116 @@
 f (!
-originalMethod.alreadyWrapped) %7B%0A%09%09Class.prototype%5BmethodName%5D = wrapper(originalMetho
+wrappedMethods.has(originalMethod)) %7B%0A%09%09const wrapped = wrapper(originalMethod);%0A%09%09wrappedMethods.add(wrappe
 d);%0A
@@ -632,30 +632,18 @@
 ame%5D
-.alreadyWrapped = true
+ = wrapped
 ;%0A%09%7D

replace monkey patching prooperty with WeakSet