mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-10 02:08:38 +09:00
Issue #1952 - m-c 1440468: Proxied functions can't be passed to Function.prototype.toString.call()
This commit is contained in:
parent
85af7f6e80
commit
887e6d0ab3
4 changed files with 11 additions and 15 deletions
|
|
@ -3,12 +3,7 @@ var functionProxy = new Proxy(function() {}, {});
|
|||
|
||||
assertEq(Object.prototype.toString.call(objectProxy), '[object Object]');
|
||||
assertEq(Object.prototype.toString.call(functionProxy), '[object Function]');
|
||||
try {
|
||||
Function.prototype.toString.call(functionProxy);
|
||||
assertEq(true, false);
|
||||
} catch (e) {
|
||||
assertEq(!!/incompatible/.exec(e), true);
|
||||
}
|
||||
|
||||
try {
|
||||
Function.prototype.toString.call(objectProxy);
|
||||
assertEq(true, false);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
load(libdir + 'asserts.js');
|
||||
|
||||
// Function.prototype.toString doesn't accept ES6 proxies.
|
||||
var nativeCode = "function () {\n [native code]\n}";
|
||||
|
||||
var proxy = new Proxy(function() {}, {});
|
||||
assertThrowsInstanceOf(() => Function.prototype.toString.call(proxy), TypeError);
|
||||
assertEq(Function.prototype.toString.call(proxy), nativeCode);
|
||||
var o = Proxy.revocable(function() {}, {});
|
||||
assertThrowsInstanceOf(() => Function.prototype.toString.call(o.proxy), TypeError);
|
||||
assertEq(Function.prototype.toString.call(o.proxy), nativeCode);
|
||||
o.revoke();
|
||||
assertThrowsInstanceOf(() => Function.prototype.toString.call(o.proxy), TypeError);
|
||||
assertEq(Function.prototype.toString.call(o.proxy), nativeCode);
|
||||
|
|
|
|||
|
|
@ -319,8 +319,9 @@ BaseProxyHandler::fun_toString(JSContext* cx, HandleObject proxy, bool isToSourc
|
|||
{
|
||||
if (proxy->isCallable())
|
||||
return JS_NewStringCopyZ(cx, "function () {\n [native code]\n}");
|
||||
RootedValue v(cx, ObjectValue(*proxy));
|
||||
ReportIsNotFunction(cx, v);
|
||||
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
js_Function_str, js_toString_str, "object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1259,9 +1259,9 @@ ScriptedProxyHandler::className(JSContext* cx, HandleObject proxy) const
|
|||
JSString*
|
||||
ScriptedProxyHandler::fun_toString(JSContext* cx, HandleObject proxy, bool isToSource) const
|
||||
{
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
js_Function_str, js_toString_str, "object");
|
||||
return nullptr;
|
||||
// The BaseProxyHandler has the desired behavior: Throw for non-callable,
|
||||
// otherwise return [native code].
|
||||
return BaseProxyHandler::fun_toString(cx, proxy, isToSource);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue