#30985·Node.js

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

Author: underflow00Created Dec 16, 2019Updated Sep 28, 2026
Labelsvmv8 enginestale
  • Version: v12.13.1
  • Platform: Windows 10

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

javascript
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}