This repository has been archived by the owner. 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

Comments

Projects
None yet
6 participants

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.

@trevnorris trevnorris added vm labels Feb 18, 2014

@gfxmonk it works with the master

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

Owner

indutny commented Feb 25, 2014

@gfxmonk confirming.

Owner

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?

Member

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

Owner

indutny commented Feb 25, 2014

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

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

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 ?

Owner

indutny commented Feb 26, 2014

I guess this is duplicate of joyent#7031

Owner

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

vm: share security token between contexts
By default, each `v8::Context` has a different Security Token, which
prevents access to one context from another.

fix #7140
Owner

indutny commented Mar 18, 2014

Should be fixed by joyent#7328

@indutny indutny closed this in b76a1ff Mar 21, 2014

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