You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Illegal invocation error using ES6 Proxy and node.js #11629
This issue isn't reproducible on master or v7.x-staging, probably as a side effect of #11564. Either way, the next release of v7.x will have this fixed.
cpus is only one function affected by this bug. Other methods that directly call C++ bindings are also vulnerable. On the V8 level, it is probably because the API call helper cannot find a compatible receiver in a Proxy object.
This bug has already been reported upstream by as issue 5773.
This is still an issue as of Node v9.8.0. Can/should anyone push for a v8 fix, or should there be any sort of Node workaround? Or are users expected to rebind to the unproxied contexts for all of these calls?
Even if this is fully compliant with the spec, it's quite a pain. As Proxies become a more widely adopted feature I expect many more people will run into this. At the very least, there should be a workaround on the Node side.
That invokes Buffer.prototype.toString() with the proxy as the receiver and fails the way it is expected to.
Talk of "there should be a workaround on the Node side" is misguided because it's not a sensible construct. Write it like this and note the .bind() call:
Activity
vsemozhetbyt commentedon Mar 1, 2017
Maybe it is because the
Mathmethods are static, while the Node.js modules' methods could require an appropriate receiver. This works:vsemozhetbyt commentedon Mar 1, 2017
See also: Exploring ES6 by Dr. Axel Rauschmayer: 28. Metaprogramming with proxies: 28.3.2 Intercepting method calls
FranckFreiburger commentedon Mar 5, 2017
receiver for the default get proxy handler is handled with
Reflect.get(target, property, receiver)FranckFreiburger commentedon Mar 5, 2017
This case is also weird (note that I use node.js v7.7.1):
vsemozhetbyt commentedon Mar 5, 2017
@FranckFreiburger
Maybe this is somehow connected with C++ bindings, This works:
os.arch()does not use bindings.os.cpus()does use them.TimothyGu commentedon Mar 6, 2017
This issue isn't reproducible on master or v7.x-staging, probably as a side effect of #11564. Either way, the next release of v7.x will have this fixed.
TimothyGu commentedon Mar 6, 2017
cpusis only one function affected by this bug. Other methods that directly call C++ bindings are also vulnerable. On the V8 level, it is probably because the API call helper cannot find a compatible receiver in aProxyobject.This bug has already been reported upstream by as issue 5773.
/cc @nodejs/v8
FranckFreiburger commentedon Mar 6, 2017
Note that all
binding.*functions seems to be affected by this bug.new Proxy(require('os'), {}).hostname() // Illegal invocation...Trott commentedon Jul 30, 2017
Is there anything Node.js can/should do about this other than await https://bugs.chromium.org/p/v8/issues/detail?id=5773 getting fixed in V8? Should this issue remain open?
targos commentedon Aug 3, 2017
This is still an issue but AFAICT there is nothing Node.js can do about it.
Repro on v8.x:
mappum commentedon Mar 11, 2018
This is still an issue as of Node v9.8.0. Can/should anyone push for a v8 fix, or should there be any sort of Node workaround? Or are users expected to rebind to the unproxied contexts for all of these calls?
mappum commentedon Mar 12, 2018
BTW, this comes up in surprisingly common places, e.g. trying to stringify a Proxied Buffer.
devsnek commentedon Mar 12, 2018
fwiw this is intended behavior on the side of proxies. check out https://github.com/nodejs/node/pull/18131/files#diff-cc63475f116262e9cbea02374e344c01R671 for an example of a proxy that covers this use case.
mappum commentedon Mar 12, 2018
Even if this is fully compliant with the spec, it's quite a pain. As Proxies become a more widely adopted feature I expect many more people will run into this. At the very least, there should be a workaround on the Node side.
devsnek commentedon Mar 12, 2018
@mappum that's the general idea of the membrane concept: https://www.npmjs.com/package/es7-membrane
bnoordhuis commentedon Mar 13, 2018
The examples listed in this issue work with master so I think this can be closed out.
As to this example (edited for brevity):
That invokes
Buffer.prototype.toString()with the proxy as the receiver and fails the way it is expected to.Talk of "there should be a workaround on the Node side" is misguided because it's not a sensible construct. Write it like this and note the
.bind()call:- https://bugs.chromium.org/p/v8/issues/detail?id=5773 and nodejs/nod…
kamil-kielczewski commentedon May 31, 2023
On chrome I have same problem for events (eg. click event) - here is solution
working editable example here which shows how to add your code before/after original function execution