You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After importing a transcrypt module, various prototypes such as Array, String, Uint8Array are polluted with python specific helper functions. These appear to be coming from the org.transcrypt.runtime.js module such as
Array.prototype.extend = function (aList) {
this.push.apply (this, aList);
};
Unfortunately these functions are listed as enumerable resulting in unexpected behaviour in external code ran later when its iterating even when the array wasn't created in the python code. Executing the following in the js console after simply importing the module
FixesTranscryptOrg#816
Assigning functions directly to the prototypes of Number, Array, String, etc., causes them to be enumerable, meaning they can show up in "for .. in .." loops and cause unexpected behavior!
Instead we can use `Object.defineProperty` (which we already have a helper for called `__setproperty__`. With this method, i) new props are non-enumerable by default, and ii) we can avoid unnecessarily reassigning the same methods, in case there are multiple instances of Transcrypt running.
JGreenlee
added a commit
to JGreenlee/Transcrypt
that referenced
this issue
Aug 23, 2024
FixesTranscryptOrg#816
Assigning functions directly to the prototypes of Number, Array, String, etc., causes them to be enumerable, meaning they can show up in "for .. in .." loops and cause unexpected behavior!
Instead we can use `Object.defineProperty` (which we already have a helper for called `__setproperty__`. With this method, i) new props are non-enumerable by default, and ii) we can avoid unnecessarily reassigning the same methods, in case there are multiple instances of Transcrypt running.
After importing a transcrypt module, various prototypes such as Array, String, Uint8Array are polluted with python specific helper functions. These appear to be coming from the org.transcrypt.runtime.js module such as
Unfortunately these functions are listed as enumerable resulting in unexpected behaviour in external code ran later when its iterating even when the array wasn't created in the python code. Executing the following in the js console after simply importing the module
results in all these items being output
Changing it to be defined as the following appears to resolve the issue and doesn't appear to impact the functionality in my test case
The text was updated successfully, but these errors were encountered: