Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instanceof fails on multiple context #665

Closed
obastemur opened this issue Apr 1, 2015 · 2 comments
Closed

instanceof fails on multiple context #665

obastemur opened this issue Apr 1, 2015 · 2 comments

Comments

@obastemur
Copy link

We started to have this issue on JXcore - under limited memory environments (mobile, mini boards..)

Line: https://github.com/mishoo/UglifyJS2/blob/master/lib/utils.js#L223
Code:

 if (!(words instanceof Array)) words = words.split(" ");

'Array' here targets totally different memory reference when each of the sources run inside the 'vm' individually. This happens due to JavaScript engine optimization under very low resources. JS engine moves the reference of Array to another point while the optimized function code still checks for the same reference. Indeed this is JS engine related issue ( very tricky one ) but I don't know if it's something fixable in a short term. I bet this would also fail on iframe / webworker on browsers.

Suggestion: (not sure if this is cross browser but it does the magic on node/jxcore)

if(!Array.isArray(words)) ....
@obastemur
Copy link
Author

function isSomething(thing, obj) {
  return Object.prototype.toString.call(obj) === '[object '+thing+']';
}

isSomething('Array', words)

This also works and it's cross browser.

If UglifyJS could execute all it's source files under the same VM at once, this wouldn't be a problem. Actually this would be the best way. We may not be sure when JS engine is going to issue a garbage collection and how it will effect the actual memory references / optimizations.

@alexlamsl
Copy link
Collaborator

vm is no longer in use after #636 and 99233c4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants