felixge / node-sandboxed-module

A sandboxed node.js module loader that lets you inject dependencies into your modules.
MIT License
342 stars 42 forks source link

Enable requiring modules that rely on strict mode. #16

Closed tristanls closed 11 years ago

tristanls commented 11 years ago

This is my solution to a problem where I wanted to sandbox a module that used ES6 Harmony features such as let.

I can now enable v8 "extended mode" by running tests using --harmony flag and requiring sandboxed modules with "use strict"; by providing strictMode : true options when requiring.

domenic commented 11 years ago

Hmm yeah so obviously we have a bug; if the original module is strict, the sandboxed one should be also. But this is not the correct solution.

I guess the issue is the line:

'global = GLOBAL = root = (function() { return this; })();' +

which is interfering with the pragma's positioning rules.

You should be able to move global, GLOBAL, and root (is that a real thing?) into localVariables instead, to get the desired behavior.

Also, a test would be nice :).

Thanks!

tristanls commented 11 years ago

Fair enough, I did take the shortest path :D. At least it's documented now.