Bug 807623 - Reimplement obj_toString and fun_toString traps on BaseProxyHandler. r=ejpbruel

Looks like these got lost in the Direct Proxy Handler refactor.
This commit is contained in:
Bobby Holley 2012-11-08 14:05:49 -08:00
parent b90082aa95
commit dff96799f4
2 changed files with 27 additions and 10 deletions

View File

@ -0,0 +1,12 @@
var objectProxy = Proxy.create({});
var functionProxy = Proxy.createFunction({}, function() {}, function() {});
assertEq(Object.prototype.toString.call(objectProxy), '[object Object]');
assertEq(Object.prototype.toString.call(functionProxy), '[object Function]');
assertEq(Function.prototype.toString.call(functionProxy), 'function () {}');
try {
Function.prototype.toString.call(objectProxy);
assertEq(true, false);
} catch (e) {
assertEq(!!/incompatible/.exec(e), true);
}

View File

@ -282,21 +282,26 @@ BaseProxyHandler::construct(JSContext *cx, JSObject *proxy, unsigned argc,
JSString *
BaseProxyHandler::obj_toString(JSContext *cx, JSObject *proxy)
{
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO,
js_Object_str, js_toString_str,
"object");
return NULL;
return JS_NewStringCopyZ(cx, IsFunctionProxy(proxy)
? "[object Function]"
: "[object Object]");
}
JSString *
BaseProxyHandler::fun_toString(JSContext *cx, JSObject *proxy, unsigned indent)
{
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO,
js_Function_str, js_toString_str,
"object");
return NULL;
Value fval = GetCall(proxy);
if (IsFunctionProxy(proxy) &&
(fval.isPrimitive() || !fval.toObject().isFunction())) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO,
js_Function_str, js_toString_str,
"object");
return NULL;
}
RootedObject obj(cx, &fval.toObject());
return fun_toStringHelper(cx, obj, indent);
}
bool