Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

vm: context created from global is missing all properties #7140

Closed
timbertson opened this issue Feb 17, 2014 · 11 comments
Closed

vm: context created from global is missing all properties #7140

timbertson opened this issue Feb 17, 2014 · 11 comments

Comments

@timbertson
Copy link

The StratifiedJS (http://onilabs.com/stratifiedjs) runtime makes use of nodejs' vm module, and things are breaking in node v0.11.

Something we are doing which works fine in 0.10 and below is:

var vm = require('vm');
var c = vm.createContext(global);
vm.runInContext("console.log('hi')", c, '[sandbox]');

But in v0.11.10, this fails with "TypeError: Cannot call method 'log' of undefined".

I did look through the other open issues relating to the vm module, but those are all quite specific, so it's hard for me to know whether this is the same issue without much knowledge of the vm module internals. I'm happy for this to be marked as a dupe if someone more knowledgeable thinks it is, though.

@obastemur
Copy link

@gfxmonk it works with the master

@timbertson
Copy link
Author

@obastemur you sure? I compiled e746bbd locally this morning to test, and it still acts as above for me.

@indutny
Copy link
Member

indutny commented Feb 25, 2014

@gfxmonk confirming.

@indutny
Copy link
Member

indutny commented Feb 25, 2014

The answer is that console isn't actually a property, but is a getter.

> Object.getOwnPropertyDescriptor(global, 'console')
{ get: [Function],
  set: undefined,
  enumerable: true,
  configurable: true }

@domenic is it intentional or bug?

@domenic
Copy link

domenic commented Feb 25, 2014

Well if it's a regression, it's a bug. But I thought we had a test for getters. https://github.com/joyent/node/blob/master/test/simple/test-vm-create-context-accessors.js

@indutny
Copy link
Member

indutny commented Feb 25, 2014

Perhaps, it is some sort of v8 trickery...

@migounette
Copy link

Well I am not sure that we don't have a curious issue with Windows:

After a hardwork from moving my stuff to 0.10.x to 0.11.11 with NaN for my native modules, I have a similar problem with module instances, I have this when I use VM functions, in fact I found multiple entries in the Module._cache of the same module...

You will appreciate the C uppercase and c lower case....

C:\\_SVN\hpoc-config-tools\src\framework\kernel\toolbox.js
c:\\_SVN\hpoc-config-tools\src\framework\kernel\toolbox.js

I am using require('..\kernel\toolbox.js') for instance

My 2 cents

@migounette
Copy link

It comes from : path.normalize() that does not respect the case !
So, it has an indirect impact on the Module._cache if your parent was loaded with a full path or relative path.

Shall I need to enter an issue or do you think it's a normal behavior ?

> require('path').normalize("C:\test")
'c:\test'

Code: path.js

// If device is a drive letter, we'll normalize to lower case.
if (device && device.charAt(1) === ':') {
  device = device[0].toLowerCase() + device.substr(1);
}

Question : Why ?

@indutny
Copy link
Member

indutny commented Feb 26, 2014

I guess this is duplicate of #7031

@indutny
Copy link
Member

indutny commented Feb 26, 2014

@migounette could you please not discuss off-topic stuff in the issue?

indutny added a commit to indutny/node that referenced this issue Mar 18, 2014
By default, each `v8::Context` has a different Security Token, which
prevents access to one context from another.

fix nodejs#7140
@indutny
Copy link
Member

indutny commented Mar 18, 2014

Should be fixed by #7328

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

No branches or pull requests

6 participants