Node: `in` operator not working correctly when using Proxy as VM context

Created on 16 Dec 2019  路  4Comments  路  Source: nodejs/node

  • Version: v12.13.1
  • Platform: Windows 10

The in operator does not work correctly when using a Proxy as a VM context.

var o = {};
var p = new Proxy(o, {
    has(target, key) {
        console.log('has', key);
        return Reflect.has(target, key);
    },
    get(target, key, receiver) {
        console.log('get', key);
        return Reflect.get(target, key, receiver);
    },
});
vm.createContext(p);
vm.runInContext(`this.abcInThis = 'abc' in this`, p);
console.log(JSON.stringify(o)); // Prints {"abcInThis":false}

In the above code, the expected output is:

has abc
{"abcInThis":false}

but the actual output is:

get abc
{"abcInThis":true}

If we remove the get(target, key, receiver) function, the still incorrect output is:

{"abcInThis":false}
V8 Engine vm

Most helpful comment

This is a limitation of V8. See: https://github.com/nodejs/node/pull/22390

I'd be interested in fixing this at some point.

All 4 comments

This is a limitation of V8. See: https://github.com/nodejs/node/pull/22390

I'd be interested in fixing this at some point.

This also causes issues when using the with operator, which prevents merging https://github.com/jsdom/webidl2js/pull/167.

I recently took a pretty deep dive into V8 internals to see what it would take to make fix this issue, and the quick answer is quite a lot. The good news is that V8 will need to update the internal global proxy infrastructure for the proposed realms api when they implement it, which will make it easier to fix this issue.

Was this page helpful?
0 / 5 - 0 ratings