Proxied functions can't be passed to Function.prototype.toString.call()
Reported by
john.dav...@gmail.com,
Feb 22 2018
|
||
Issue description
var a = function() {}
var p = new Proxy(a, {})
Function.prototype.toString.call(p)
// VM108:9 Uncaught TypeError: Function.prototype.toString requires that 'this' be a
// Function
// at Proxy.toString (<anonymous>)
// at <anonymous>:9:29
typeof p // "function"
Object.prototype.toString.call(p) // [object Function]
With at least Safari passing it to Function.prototype.toString.call will work.
,
Feb 22 2018
Cool. It's a bummer proxies don't just auto unwrap for situations like this to use the unwrapped function.
,
Feb 22 2018
The following revision refers to this bug: https://chromium.googlesource.com/v8/v8.git/+/f7d7b5c6a4a55baa8984525fba6d0d5e1355b3b0 commit f7d7b5c6a4a55baa8984525fba6d0d5e1355b3b0 Author: Adam Klein <adamk@chromium.org> Date: Thu Feb 22 22:55:50 2018 ToString of a Proxied function should not throw Without --harmony-function-tostring, anything other than a JSFunction or JSBoundFunction throw when Function.prototype.toString is called on them. But with the toString revision, anything callable allows toString (and for non-Functions returns the good old "function () { [native code] }" string). Bug: v8:7484 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: I3540e213a40992151761b59666fe36e0510da908 Reviewed-on: https://chromium-review.googlesource.com/932825 Commit-Queue: Adam Klein <adamk@chromium.org> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Cr-Commit-Position: refs/heads/master@{#51489} [modify] https://crrev.com/f7d7b5c6a4a55baa8984525fba6d0d5e1355b3b0/src/builtins/builtins-function.cc [modify] https://crrev.com/f7d7b5c6a4a55baa8984525fba6d0d5e1355b3b0/src/heap-symbols.h [modify] https://crrev.com/f7d7b5c6a4a55baa8984525fba6d0d5e1355b3b0/src/objects.cc [modify] https://crrev.com/f7d7b5c6a4a55baa8984525fba6d0d5e1355b3b0/test/mjsunit/es6/proxies.js [add] https://crrev.com/f7d7b5c6a4a55baa8984525fba6d0d5e1355b3b0/test/mjsunit/es6/proxy-function-tostring.js [modify] https://crrev.com/f7d7b5c6a4a55baa8984525fba6d0d5e1355b3b0/test/mjsunit/harmony/function-tostring.js
,
Feb 22 2018
Regarding unwrapping, I'm not sure how happy folks would be about that, but please raise an issue against the spec if you feel strongly. I believe with my patch we now match the newly-specced behavior.
,
Feb 22 2018
Thank you Adam! |
||
►
Sign in to add a comment |
||
Comment 1 by adamk@chromium.org
, Feb 22 2018Owner: adamk@chromium.org
Status: Assigned (was: Untriaged)
This used to be spec'd as a TypeError, but with the Function.prototype.toString revision, it seems we're supposed to generate something like "function() { [native code] }" This is step 3 of the new proposal: ``` If Type(func) is Object and IsCallable(func) is true, then return an implementation-dependent String source code representation of func. The representation must have the syntax of a NativeFunction. ```