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
{{ message }}
This repository was archived by the owner on Oct 21, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 21, 2022. It is now read-only.
Forward native prototype extensions through require #5
If I try to evaluate a program that uses a library extending native prototypes, LightTable loses connection with the Node process, saying it crashed, and the console reads the following:
…/LightTable/LightTable.app/Contents/Resources/app.nw/plugins/javascript/node/ltnodeclient.js:99
vm.runInContext(cleanCode(fs.readFileSync(path)), sb, path);
^
TypeError: Object function Object() { [native code] } has no method 'extend'
at …/Watai/src/lib/mootools-additions.js:3:8
Indeed, it seems that the sbRequire function wraps original require calls without sharing prototypes, since all modules are evaluated in their own (shared) context, not in the global context.
For reference, this behavior can be tested by trying to evaluate stuff in Watai’s src/index.js.
Just now getting a chance to look at this. On node 0.10.32 on a mac, when I eval index.js line by line, I see an early exit due to validateParams and the number of console args and not a require. Could you explain what evals you did to get the above?
Wow, it's been a while… No, I wouldn't be able to tell you how I tried to call code back then :-/
You should be able to test that on a project that has mootools installed, and have:
require('mootools');
Object.extend({}, {}); // <-- I guess this should crash since it's an extension to the native Object
[1, 2].each(function(val) { console.log(val) }); // <-- if not, then this should (extension of proto)
I'm able to require mootools in your project but can't execute either of the lines after it successfully. Any specific recommendations on sharing prototypes within sbRequire?
Ok. We don't have the bandwidth to look into this more currently but leaving this open for a while to see if others are interested in adding support for this
changed the title [-]Native prototype extensions are not forwarded through `require`[/-][+]Forward native prototype extensions through `require`[/+]on Dec 10, 2014
Activity
cldwalker commentedon Dec 9, 2014
Just now getting a chance to look at this. On node 0.10.32 on a mac, when I eval index.js line by line, I see an early exit due to validateParams and the number of console args and not a require. Could you explain what evals you did to get the above?
MattiSG commentedon Dec 9, 2014
Wow, it's been a while… No, I wouldn't be able to tell you how I tried to call code back then :-/
You should be able to test that on a project that has
mootoolsinstalled, and have:cldwalker commentedon Dec 9, 2014
I'm able to require mootools in your project but can't execute either of the lines after it successfully. Any specific recommendations on sharing prototypes within
sbRequire?MattiSG commentedon Dec 9, 2014
Well, perhaps you could iterate over all natives and inject them in the context you're creating.
Unfortunately, I am not currently at a time where I can experiment with this :(
cldwalker commentedon Dec 10, 2014
Ok. We don't have the bandwidth to look into this more currently but leaving this open for a while to see if others are interested in adding support for this
[-]Native prototype extensions are not forwarded through `require`[/-][+]Forward native prototype extensions through `require`[/+]