This repository has been archived by the owner. It is now read-only.

reference to context is wrong within the context #1389

liucougar opened this Issue Jul 23, 2011 · 8 comments


None yet
6 participants
var vm=require("vm");
var win = {doc:{}};

win.doc.parent = win;
win.self = win;

var ctx = vm.createContext(win);

//the following line does not change the outcome

var script = vm.createScript('check=[doc.parent===this, self===this];');
console.log('result is', ctx.check);
//I got the following output in nodejs 0.4.9
//result is [ false, true ]

I expect the result to be:
result is [ true, true ]

there is no way to make doc.parent===this true in the context

isaacs commented Jul 23, 2011

Hm, yeah. Setting ctx.doc.parent = win and ctx.doc.parent = ctx don't have an effect either. @Herby, any ideas?


ghost commented Jul 24, 2011

There is no way to make it automagically. Automagic translation of outer self-reference to inner self-reference and back only works for first level.
If you want it deeper, you should set it programmatically (like prepend 'doc.parent=self;' when creating script).

tmpvar commented Jul 27, 2011

Sounds good, thats what we'll do. Thanks guys!

(feel free to close this)

As documented in #1801, I believe I’ve closed this with elliottcable@cf21650. I’d appreciate if you’d clone and compile against that, and see if you can still reproduce this issue. (Many of these issues seem related.)

Ran the test code against v0.8.14, and came out [false, false]. Looks like the bug was fixed in 200df86.


bnoordhuis commented Dec 5, 2012

Looks like the bug was fixed in 200df86.

I don't know.

> var c = {}; c.self = c; vm.runInNewContext('this === self', c);

I expect it to print true. But then, 'this' is the global object, not the context object. I'm not sure if I ought to chalk it down to bad expectations.

@bnoordhuis ah, yeah. as you mentioned in a previous bug, I didn't realize that 200df86 was reverted in 9d27faa.

Following the code logic, I'd expect false to be returned. So is the problem that, as you said, whether it should return true or false is an unknown expectation?


bnoordhuis commented Dec 5, 2012

Let's apply the Noordhuis Principle of Least Expenditure and do nothing. I'll adjust my expectations instead. :-)

@bnoordhuis bnoordhuis closed this Dec 5, 2012

richardlau pushed a commit to ibmruntimes/node that referenced this issue Sep 18, 2015

2015-04-17 io.js v1.8.0 Release
Notable Changes:

* build: Support for building io.js as a static library (Marat Abdullin) #1341
* deps: upgrade openssl to 1.0.2a (Shigeki Ohtsu) #1389
* npm: Upgrade npm to 2.8.3. (Forrest L Norvell) #1448
* src: allow multiple arguments to be passed to process.nextTick (Trevor Norris) #1077
* module: interaction of require('.') with NODE_PATH has been restored and deprecated.
  This functionality will be removed at a later point. (Roman Reiss) #1363
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.