diff -r fb6253ba7317 js/src/jsproxy.cpp --- a/js/src/jsproxy.cpp Thu Aug 02 23:52:35 2012 +0200 +++ b/js/src/jsproxy.cpp Thu Aug 02 23:53:22 2012 +0200 @@ -1777,18 +1777,18 @@ JS_FRIEND_DATA(Class) js::OuterWindowPro JS_PropertyStub, /* getProperty */ JS_StrictPropertyStub, /* setProperty */ JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, proxy_Finalize, /* finalize */ NULL, /* checkAccess */ NULL, /* call */ + NULL, /* hasInstance */ NULL, /* construct */ - NULL, /* hasInstance */ proxy_TraceObject, /* trace */ { NULL, /* equality */ NULL, /* outerObject */ proxy_innerObject, NULL /* unused */ }, { @@ -1940,16 +1940,58 @@ js::NewProxyObject(JSContext *cx, BasePr /* Mark the new proxy as having singleton type. */ if (clasp == &OuterWindowProxyClass && !obj->setSingletonType(cx)) return NULL; return obj; } static JSBool +proxy(JSContext *cx, unsigned argc, jsval *vp) +{ + if (argc < 1) { + JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED, + "Proxy", "0", "s"); + return false; + } + JSObject *target = NonNullObject(cx, vp[2]); + if (!target) + return false; + JSObject *handler = NULL; + if (argc > 1) + handler = &vp[3].toObject(); + JSObject *proto = target->getProto(); + JSObject *proxy = NewProxyObject(cx, &ScriptedDirectProxyHandler::singleton, + ObjectValue(*target), proto, proto->getParent(), + target, target); + if (!proxy) + return false; + SetProxyExtra(proxy, 0, ObjectOrNullValue(handler)), + vp->setObject(*proxy); + return true; +} + +Class js::ProxyClass = { + "Proxy", + JSCLASS_HAS_CACHED_PROTO(JSProto_Proxy), + JS_PropertyStub, /* addProperty */ + JS_PropertyStub, /* delProperty */ + JS_PropertyStub, /* getProperty */ + JS_StrictPropertyStub, /* setProperty */ + JS_EnumerateStub, + JS_ResolveStub, + JS_ConvertStub, + NULL, /* finalize */ + NULL, /* checkAccess */ + NULL, /* call */ + NULL, /* hasInstance */ + proxy /* construct */ +}; + +static JSBool proxy_create(JSContext *cx, unsigned argc, Value *vp) { if (argc < 1) { JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED, "create", "0", "s"); return false; } JSObject *handler = NonNullObject(cx, vp[2]); @@ -2013,28 +2055,16 @@ proxy_createFunction(JSContext *cx, unsi } static JSFunctionSpec static_methods[] = { JS_FN("create", proxy_create, 2, 0), JS_FN("createFunction", proxy_createFunction, 3, 0), JS_FS_END }; -Class js::ProxyClass = { - "Proxy", - JSCLASS_HAS_CACHED_PROTO(JSProto_Proxy), - JS_PropertyStub, /* addProperty */ - JS_PropertyStub, /* delProperty */ - JS_PropertyStub, /* getProperty */ - JS_StrictPropertyStub, /* setProperty */ - JS_EnumerateStub, - JS_ResolveStub, - JS_ConvertStub -}; - JS_FRIEND_API(JSObject *) js_InitProxyClass(JSContext *cx, JSObject *obj_) { RootedObject obj(cx, obj_); RootedObject module(cx, NewObjectWithClassProto(cx, &ProxyClass, NULL, obj)); if (!module || !module->setSingletonType(cx)) return NULL;