const globalProxy = new Proxy(win.window, {
get(target, p, receiver){
// return undefined
return Reflect.get(target, p, receiver);
// there is a value
// return Reflect.get(target, p);
}
})
In Node.js version 20.18, when using Reflect.get with the receiver parameter, it returns undefined, while without the receiver parameter, there is a value. Based on my limited understanding of the Reflect.get function (which only affects the this pointer of getters), I really can't figure out why this is the case. I even asked Claude, but it didn't provide me with a reproducible example.
On Node.js version 16.20, there is a value. So, could it be a bug in V8?
code of image comes from vitest lib
when debugging in VSCode, when monitoring the target and expanding the list of member variables, there is no property named p (including expanding the [[Prototype]] prototype layer by layer). However, it exists on __proto__, and hasOwnProperty returns true, which also indicates that it shouldn't be on the prototype.
I can reproduce with this:
const myObj = {
aa: 'aa'
}
Object.defineProperty(myObj, 'a', {
get () {
return this.aa
}
})
const myProxyObj = new Proxy({
a: 'a'
}, {
get(target, prop, receiver) {
return Reflect.get(target, prop, receiver)
}
})
console.log(Reflect.get(myObj, 'a', myProxyObj))
console.log('a' in myObj)
console.log('a' in myProxyObj)
console.log(Object.hasOwn(myObj, 'a'))
console.log(Object.hasOwn(myProxyObj, 'a'))
but, in vscode debuger control panel, I get this:
// target === win.window
Object.entries(target).length // 183
Object.keys(target).length // 186
addEventListener aka p is not exists in entries function returns, besides, removeEventListener and dispatchEvent don't exist either
there is a reproduce demo may help: https://codesandbox.io/p/devbox/kc2h2l
steps:
- add breakpoint in line 4 of dom.test.js file
npm run testin js debug terminal- watch
windowin debug panel, will get a proxy object - go to definition of proxy [[Handler]]'s get function then add a breakpoint(source map incorrect maybe)
- if previous step not work, try to step in (Alt+F11) 2 - 4 times, will reach to line 317 of
/node_modules/vitest/dist/vendor-entry.5c1e6d94.jsfile - now, you can watch
targetandreceiverand reproduce above demo