From 86c084a519889d44f0f91ada09a3d2adaffb3d0a Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Fri, 7 Dec 2018 17:55:31 +0100 Subject: [PATCH] Use a symbol for the this pointer on wrapped loader classes, see #363 --- lib/loader/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/loader/index.js b/lib/loader/index.js index 847f7e8b..7f79027b 100644 --- a/lib/loader/index.js +++ b/lib/loader/index.js @@ -1,6 +1,7 @@ "use strict"; const hasBigInt64 = typeof BigUint64Array !== "undefined"; +const thisPtr = Symbol(); /** Gets a string from an U32 and an U16 view on a memory. */ function getStringImpl(U32, U16, ptr) { @@ -269,7 +270,7 @@ function demangle(exports, baseModule) { }; ctor.prototype = {}; ctor.wrap = function(thisValue) { - return Object.create(ctor.prototype, { "this": { value: thisValue, writable: false } }); + return Object.create(ctor.prototype, { [thisPtr]: { value: thisValue, writable: false } }); }; if (classElem) Object.getOwnPropertyNames(classElem).forEach(name => Object.defineProperty(ctor, name, Object.getOwnPropertyDescriptor(classElem, name)) @@ -283,8 +284,8 @@ function demangle(exports, baseModule) { let getter = exports[internalName.replace("set:", "get:")]; let setter = exports[internalName.replace("get:", "set:")]; Object.defineProperty(curr, name, { - get: function() { return getter(this.this); }, - set: function(value) { setter(this.this, value); }, + get: function() { return getter(this[thisPtr]); }, + set: function(value) { setter(this[thisPtr], value); }, enumerable: true }); } @@ -295,7 +296,7 @@ function demangle(exports, baseModule) { Object.defineProperty(curr, name, { value: function (...args) { setargc(args.length); - return elem(this.this, ...args); + return elem(this[thisPtr], ...args); } }); }