diff -r 827c023e790b js/src/jsproxy.cpp --- a/js/src/jsproxy.cpp Thu Aug 02 21:30:03 2012 +0200 +++ b/js/src/jsproxy.cpp Thu Aug 02 23:50:58 2012 +0200 @@ -732,21 +732,21 @@ ArrayToIdVector(JSContext *cx, const Val return false; if (!props.append(id)) return false; } return true; } -/* Derived class for all scripted proxy handlers. */ -class ScriptedProxyHandler : public IndirectProxyHandler { +/* Derived class for all scripted indirect proxy handlers. */ +class ScriptedIndirectProxyHandler : public IndirectProxyHandler { public: - ScriptedProxyHandler(); - virtual ~ScriptedProxyHandler(); + ScriptedIndirectProxyHandler(); + virtual ~ScriptedIndirectProxyHandler(); /* ES5 Harmony fundamental proxy traps. */ virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, PropertyDescriptor *desc); virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, PropertyDescriptor *desc); @@ -770,26 +770,27 @@ class ScriptedProxyHandler : public Indi /* Spidermonkey extensions. */ virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args); virtual JSType typeOf(JSContext *cx, JSObject *proxy); virtual bool defaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp); - static ScriptedProxyHandler singleton; + static ScriptedIndirectProxyHandler singleton; }; -static int sScriptedProxyHandlerFamily = 0; +static int sScriptedIndirectProxyHandlerFamily = 0; -ScriptedProxyHandler::ScriptedProxyHandler() : IndirectProxyHandler(&sScriptedProxyHandlerFamily) +ScriptedIndirectProxyHandler::ScriptedIndirectProxyHandler() + : IndirectProxyHandler(&sScriptedIndirectProxyHandlerFamily) { } -ScriptedProxyHandler::~ScriptedProxyHandler() +ScriptedIndirectProxyHandler::~ScriptedIndirectProxyHandler() { } static bool ReturnedValueMustNotBePrimitive(JSContext *cx, JSObject *proxy, JSAtom *atom, const Value &v) { if (v.isPrimitive()) { JSAutoByteString bytes; @@ -798,224 +799,237 @@ ReturnedValueMustNotBePrimitive(JSContex JSDVG_SEARCH_STACK, ObjectOrNullValue(proxy), NULL, bytes.ptr()); } return false; } return true; } static JSObject * -GetProxyHandlerObject(JSContext *cx, JSObject *proxy) +GetIndirectProxyHandlerObject(JSContext *cx, JSObject *proxy) { return GetProxyPrivate(proxy).toObjectOrNull(); } bool -ScriptedProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, bool set, - PropertyDescriptor *desc) +ScriptedIndirectProxyHandler::getPropertyDescriptor(JSContext *cx, + JSObject *proxy_, jsid id_, + bool set, + PropertyDescriptor *desc) { RootedId id(cx, id_); RootedObject proxy(cx, proxy_); - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); RootedValue fval(cx), value(cx); return GetFundamentalTrap(cx, handler, ATOM(getPropertyDescriptor), &fval) && Trap1(cx, handler, fval, id, value.address()) && ((value.get().isUndefined() && IndicatePropertyNotFound(cx, desc)) || (ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), value) && ParsePropertyDescriptorObject(cx, proxy, value, desc))); } bool -ScriptedProxyHandler::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, bool set, - PropertyDescriptor *desc) +ScriptedIndirectProxyHandler::getOwnPropertyDescriptor(JSContext *cx, + JSObject *proxy_, jsid id_, + bool set, + PropertyDescriptor *desc) { RootedId id(cx, id_); RootedObject proxy(cx, proxy_); - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); RootedValue fval(cx), value(cx); return GetFundamentalTrap(cx, handler, ATOM(getOwnPropertyDescriptor), &fval) && Trap1(cx, handler, fval, id, value.address()) && ((value.get().isUndefined() && IndicatePropertyNotFound(cx, desc)) || (ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), value) && ParsePropertyDescriptorObject(cx, proxy, value, desc))); } bool -ScriptedProxyHandler::defineProperty(JSContext *cx, JSObject *proxy, jsid id_, - PropertyDescriptor *desc) +ScriptedIndirectProxyHandler::defineProperty(JSContext *cx, JSObject *proxy, + jsid id_, PropertyDescriptor *desc) { - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); RootedValue fval(cx), value(cx); RootedId id(cx, id_); return GetFundamentalTrap(cx, handler, ATOM(defineProperty), &fval) && NewPropertyDescriptorObject(cx, desc, value.address()) && Trap2(cx, handler, fval, id, value, value.address()); } bool -ScriptedProxyHandler::getOwnPropertyNames(JSContext *cx, JSObject *proxy, AutoIdVector &props) +ScriptedIndirectProxyHandler::getOwnPropertyNames(JSContext *cx, + JSObject *proxy, + AutoIdVector &props) { - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); RootedValue fval(cx), value(cx); return GetFundamentalTrap(cx, handler, ATOM(getOwnPropertyNames), &fval) && Trap(cx, handler, fval, 0, NULL, value.address()) && ArrayToIdVector(cx, value, props); } bool -ScriptedProxyHandler::delete_(JSContext *cx, JSObject *proxy, jsid id_, bool *bp) +ScriptedIndirectProxyHandler::delete_(JSContext *cx, JSObject *proxy, jsid id_, + bool *bp) { - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); RootedId id(cx, id_); RootedValue fval(cx), value(cx); return GetFundamentalTrap(cx, handler, ATOM(delete), &fval) && Trap1(cx, handler, fval, id, value.address()) && ValueToBool(cx, value, bp); } bool -ScriptedProxyHandler::enumerate(JSContext *cx, JSObject *proxy, AutoIdVector &props) +ScriptedIndirectProxyHandler::enumerate(JSContext *cx, JSObject *proxy, + AutoIdVector &props) { - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); RootedValue fval(cx), value(cx); return GetFundamentalTrap(cx, handler, ATOM(enumerate), &fval) && Trap(cx, handler, fval, 0, NULL, value.address()) && ArrayToIdVector(cx, value, props); } bool -ScriptedProxyHandler::has(JSContext *cx, JSObject *proxy_, jsid id_, bool *bp) +ScriptedIndirectProxyHandler::has(JSContext *cx, JSObject *proxy_, jsid id_, + bool *bp) { RootedObject proxy(cx, proxy_); RootedId id(cx, id_); - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); RootedValue fval(cx), value(cx); if (!GetDerivedTrap(cx, handler, ATOM(has), &fval)) return false; if (!js_IsCallable(fval)) return BaseProxyHandler::has(cx, proxy, id, bp); return Trap1(cx, handler, fval, id, value.address()) && ValueToBool(cx, value, bp); } bool -ScriptedProxyHandler::hasOwn(JSContext *cx, JSObject *proxy_, jsid id_, bool *bp) +ScriptedIndirectProxyHandler::hasOwn(JSContext *cx, JSObject *proxy_, jsid id_, + bool *bp) { RootedObject proxy(cx, proxy_); RootedId id(cx, id_); - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); RootedValue fval(cx), value(cx); if (!GetDerivedTrap(cx, handler, ATOM(hasOwn), &fval)) return false; if (!js_IsCallable(fval)) return BaseProxyHandler::hasOwn(cx, proxy, id, bp); return Trap1(cx, handler, fval, id, value.address()) && ValueToBool(cx, value, bp); } bool -ScriptedProxyHandler::get(JSContext *cx, JSObject *proxy_, JSObject *receiver_, jsid id_, Value *vp) +ScriptedIndirectProxyHandler::get(JSContext *cx, JSObject *proxy_, + JSObject *receiver_, jsid id_, Value *vp) { RootedId id(cx, id_); RootedObject proxy(cx, proxy_), receiver(cx, receiver_); - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); JSString *str = ToString(cx, IdToValue(id)); if (!str) return false; RootedValue value(cx, StringValue(str)); Value argv[] = { ObjectOrNullValue(receiver), value }; AutoValueArray ava(cx, argv, 2); RootedValue fval(cx); if (!GetDerivedTrap(cx, handler, ATOM(get), &fval)) return false; if (!js_IsCallable(fval)) return BaseProxyHandler::get(cx, proxy, receiver, id, vp); return Trap(cx, handler, fval, 2, argv, vp); } bool -ScriptedProxyHandler::set(JSContext *cx, JSObject *proxy_, JSObject *receiver_, jsid id_, bool strict, - Value *vp) +ScriptedIndirectProxyHandler::set(JSContext *cx, JSObject *proxy_, + JSObject *receiver_, jsid id_, bool strict, + Value *vp) { RootedId id(cx, id_); RootedObject proxy(cx, proxy_), receiver(cx, receiver_); - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); JSString *str = ToString(cx, IdToValue(id)); if (!str) return false; RootedValue value(cx, StringValue(str)); Value argv[] = { ObjectOrNullValue(receiver), value, *vp }; AutoValueArray ava(cx, argv, 3); RootedValue fval(cx); if (!GetDerivedTrap(cx, handler, ATOM(set), &fval)) return false; if (!js_IsCallable(fval)) return BaseProxyHandler::set(cx, proxy, receiver, id, strict, vp); return Trap(cx, handler, fval, 3, argv, value.address()); } bool -ScriptedProxyHandler::keys(JSContext *cx, JSObject *proxy_, AutoIdVector &props) +ScriptedIndirectProxyHandler::keys(JSContext *cx, JSObject *proxy_, + AutoIdVector &props) { RootedObject proxy(cx, proxy_); - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); RootedValue value(cx); if (!GetDerivedTrap(cx, handler, ATOM(keys), &value)) return false; if (!js_IsCallable(value)) return BaseProxyHandler::keys(cx, proxy, props); return Trap(cx, handler, value, 0, NULL, value.address()) && ArrayToIdVector(cx, value, props); } bool -ScriptedProxyHandler::iterate(JSContext *cx, JSObject *proxy_, unsigned flags, Value *vp) +ScriptedIndirectProxyHandler::iterate(JSContext *cx, JSObject *proxy_, + unsigned flags, Value *vp) { RootedObject proxy(cx, proxy_); - RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); + RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); RootedValue value(cx); if (!GetDerivedTrap(cx, handler, ATOM(iterate), &value)) return false; if (!js_IsCallable(value)) return BaseProxyHandler::iterate(cx, proxy, flags, vp); return Trap(cx, handler, value, 0, NULL, vp) && ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(iterate), *vp); } bool -ScriptedProxyHandler::nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, - CallArgs args) +ScriptedIndirectProxyHandler::nativeCall(JSContext *cx, IsAcceptableThis test, + NativeImpl impl, CallArgs args) { return BaseProxyHandler::nativeCall(cx, test, impl, args); } - JSType -ScriptedProxyHandler::typeOf(JSContext *cx, JSObject *proxy) +ScriptedIndirectProxyHandler::typeOf(JSContext *cx, JSObject *proxy) { /* * This function is only here to prevent a regression in * js1_8_5/extensions/scripted-proxies.js. It will be removed when the * direct proxy refactor is complete. */ return BaseProxyHandler::typeOf(cx, proxy); } bool -ScriptedProxyHandler::defaultValue(JSContext *cx, JSObject *proxy, JSType hint, - Value *vp) +ScriptedIndirectProxyHandler::defaultValue(JSContext *cx, JSObject *proxy, + JSType hint, Value *vp) { /* * This function is only here to prevent bug 757063. It will be removed when * the direct proxy refactor is complete. */ return BaseProxyHandler::defaultValue(cx, proxy, hint, vp); } -ScriptedProxyHandler ScriptedProxyHandler::singleton; +ScriptedIndirectProxyHandler ScriptedIndirectProxyHandler::singleton; bool Proxy::getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, PropertyDescriptor *desc) { JS_CHECK_RECURSION(cx, return false); return GetProxyHandler(proxy)->getPropertyDescriptor(cx, proxy, id, set, desc); } @@ -1792,17 +1806,17 @@ proxy_create(JSContext *cx, unsigned arg proto = &vp[3].toObject(); parent = proto->getParent(); } else { JS_ASSERT(IsFunctionObject(vp[0])); proto = NULL; } if (!parent) parent = vp[0].toObject().getParent(); - JSObject *proxy = NewProxyObject(cx, &ScriptedProxyHandler::singleton, ObjectValue(*handler), + JSObject *proxy = NewProxyObject(cx, &ScriptedIndirectProxyHandler::singleton, ObjectValue(*handler), proto, parent); if (!proxy) return false; vp->setObject(*proxy); return true; } @@ -1829,17 +1843,17 @@ proxy_createFunction(JSContext *cx, unsi return false; JSObject *construct = NULL; if (argc > 2) { construct = ValueToCallable(cx, &vp[4]); if (!construct) return false; } - JSObject *proxy = NewProxyObject(cx, &ScriptedProxyHandler::singleton, + JSObject *proxy = NewProxyObject(cx, &ScriptedIndirectProxyHandler::singleton, ObjectValue(*handler), proto, parent, call, construct); if (!proxy) return false; vp->setObject(*proxy); return true; }