Skip to content

Commit 86c084a

Browse files
committed
Use a symbol for the this pointer on wrapped loader classes, see AssemblyScript#363
1 parent 429435c commit 86c084a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/loader/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
const hasBigInt64 = typeof BigUint64Array !== "undefined";
4+
const thisPtr = Symbol();
45

56
/** Gets a string from an U32 and an U16 view on a memory. */
67
function getStringImpl(U32, U16, ptr) {
@@ -269,7 +270,7 @@ function demangle(exports, baseModule) {
269270
};
270271
ctor.prototype = {};
271272
ctor.wrap = function(thisValue) {
272-
return Object.create(ctor.prototype, { "this": { value: thisValue, writable: false } });
273+
return Object.create(ctor.prototype, { [thisPtr]: { value: thisValue, writable: false } });
273274
};
274275
if (classElem) Object.getOwnPropertyNames(classElem).forEach(name =>
275276
Object.defineProperty(ctor, name, Object.getOwnPropertyDescriptor(classElem, name))
@@ -283,8 +284,8 @@ function demangle(exports, baseModule) {
283284
let getter = exports[internalName.replace("set:", "get:")];
284285
let setter = exports[internalName.replace("get:", "set:")];
285286
Object.defineProperty(curr, name, {
286-
get: function() { return getter(this.this); },
287-
set: function(value) { setter(this.this, value); },
287+
get: function() { return getter(this[thisPtr]); },
288+
set: function(value) { setter(this[thisPtr], value); },
288289
enumerable: true
289290
});
290291
}
@@ -295,7 +296,7 @@ function demangle(exports, baseModule) {
295296
Object.defineProperty(curr, name, {
296297
value: function (...args) {
297298
setargc(args.length);
298-
return elem(this.this, ...args);
299+
return elem(this[thisPtr], ...args);
299300
}
300301
});
301302
}

0 commit comments

Comments
 (0)