Bug 921448 - Implement sane default behavior for fun_toString for all proxies. r=ejpbruel

This commit is contained in:
Bobby Holley 2013-10-04 13:29:33 +02:00
parent 581d9cf944
commit bab206627b
2 changed files with 7 additions and 8 deletions

View File

@ -782,7 +782,7 @@ JSString *
fun_toStringHelper(JSContext *cx, HandleObject obj, unsigned indent)
{
if (!obj->is<JSFunction>()) {
if (obj->is<FunctionProxyObject>())
if (obj->is<ProxyObject>())
return Proxy::fun_toString(cx, obj, indent);
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO,

View File

@ -308,7 +308,10 @@ BaseProxyHandler::className(JSContext *cx, HandleObject proxy)
JSString *
BaseProxyHandler::fun_toString(JSContext *cx, HandleObject proxy, unsigned indent)
{
MOZ_ASSUME_UNREACHABLE("callable proxies should implement fun_toString trap");
if (proxy->isCallable())
return JS_NewStringCopyZ(cx, "function () {\n [native code]\n}");
ReportIsNotFunction(cx, ObjectValue(*proxy));
return NULL;
}
bool
@ -2691,12 +2694,8 @@ Proxy::fun_toString(JSContext *cx, HandleObject proxy, unsigned indent)
AutoEnterPolicy policy(cx, handler, proxy, JSID_VOIDHANDLE,
BaseProxyHandler::GET, /* mayThrow = */ false);
// Do the safe thing if the policy rejects.
if (!policy.allowed()) {
if (proxy->isCallable())
return JS_NewStringCopyZ(cx, "function () {\n [native code]\n}");
ReportIsNotFunction(cx, ObjectValue(*proxy));
return NULL;
}
if (!policy.allowed())
return handler->BaseProxyHandler::fun_toString(cx, proxy, indent);
return handler->fun_toString(cx, proxy, indent);
}