Attachment #653293: Part 24 - Implement apply trap for bug #703537

View | Details | Raw Unified | Return to bug 703537
Collapse All | Expand All

(-)a/js/src/jsproxy.cpp (+37 lines)
Line     Link Here 
 Lines 1037-1052   class ScriptedDirectProxyHandler : publi Link Here 
1037
    virtual bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp) MOZ_OVERRIDE;
1037
    virtual bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp) MOZ_OVERRIDE;
1038
    virtual bool get(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id,
1038
    virtual bool get(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id,
1039
                     Value *vp) MOZ_OVERRIDE;
1039
                     Value *vp) MOZ_OVERRIDE;
1040
    virtual bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, bool strict,
1040
    virtual bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, bool strict,
1041
                     Value *vp) MOZ_OVERRIDE;
1041
                     Value *vp) MOZ_OVERRIDE;
1042
    virtual bool keys(JSContext *cx, JSObject *proxy, AutoIdVector &props) MOZ_OVERRIDE;
1042
    virtual bool keys(JSContext *cx, JSObject *proxy, AutoIdVector &props) MOZ_OVERRIDE;
1043
    virtual bool iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp) MOZ_OVERRIDE;
1043
    virtual bool iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp) MOZ_OVERRIDE;
1044
1044
1045
    virtual bool call(JSContext *cx, JSObject *proxy, unsigned argc, Value *vp) MOZ_OVERRIDE;
1046
1045
    static ScriptedDirectProxyHandler singleton;
1047
    static ScriptedDirectProxyHandler singleton;
1046
};
1048
};
1047
1049
1048
static int sScriptedDirectProxyHandlerFamily = 0;
1050
static int sScriptedDirectProxyHandlerFamily = 0;
1049
1051
1050
// Aux.2 FromGenericPropertyDescriptor(Desc)
1052
// Aux.2 FromGenericPropertyDescriptor(Desc)
1051
static bool
1053
static bool
1052
FromGenericPropertyDescriptor(JSContext *cx, PropDesc *desc, MutableHandleValue rval)
1054
FromGenericPropertyDescriptor(JSContext *cx, PropDesc *desc, MutableHandleValue rval)
 Lines 2103-2118   ScriptedDirectProxyHandler::keys(JSConte Link Here 
2103
2105
2104
bool
2106
bool
2105
ScriptedDirectProxyHandler::iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp)
2107
ScriptedDirectProxyHandler::iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp)
2106
{
2108
{
2107
    // FIXME: Provide a proper implementation for this trap
2109
    // FIXME: Provide a proper implementation for this trap
2108
    return DirectProxyHandler::iterate(cx, proxy, flags, vp);
2110
    return DirectProxyHandler::iterate(cx, proxy, flags, vp);
2109
}
2111
}
2110
2112
2113
bool
2114
ScriptedDirectProxyHandler::call(JSContext *cx, JSObject *proxy_, unsigned argc, Value *vp)
2115
{
2116
    RootedObject proxy(cx, proxy_);
2117
2118
    // step 1
2119
    RootedObject handler(cx, GetDirectProxyHandlerObject(proxy));
2120
2121
    // step 2
2122
    RootedObject target(cx, GetProxyTargetObject(proxy));
2123
2124
    // step 3
2125
    RootedObject args(cx, NewDenseCopiedArray(cx, argc, vp + 2));
2126
    if (!args)
2127
        return false;
2128
2129
    // step 4
2130
    RootedValue trap(cx);
2131
    if (!handler->getProperty(cx, ATOM(apply), &trap))
2132
        return false;
2133
2134
    // step 5
2135
    if (trap.isUndefined())
2136
        return DirectProxyHandler::call(cx, proxy_, argc, vp);
2137
2138
    // step 6
2139
    Value argv[] = {
2140
        ObjectValue(*target),
2141
        vp[1],
2142
        ObjectValue(*args)
2143
    };
2144
    RootedValue thisValue(cx, ObjectValue(*handler));
2145
    return Invoke(cx, thisValue, trap, 3, argv, vp);
2146
}
2147
2111
ScriptedDirectProxyHandler ScriptedDirectProxyHandler::singleton;
2148
ScriptedDirectProxyHandler ScriptedDirectProxyHandler::singleton;
2112
2149
2113
#define INVOKE_ON_PROTOTYPE(cx, handler, proxy, protoCall)                   \
2150
#define INVOKE_ON_PROTOTYPE(cx, handler, proxy, protoCall)                   \
2114
    JS_BEGIN_MACRO                                                           \
2151
    JS_BEGIN_MACRO                                                           \
2115
        JSObject *proto;                                                     \
2152
        JSObject *proto;                                                     \
2116
        if (!handler->getPrototypeOf(cx, proxy, &proto))                     \
2153
        if (!handler->getPrototypeOf(cx, proxy, &proto))                     \
2117
            return false;                                                    \
2154
            return false;                                                    \
2118
        if (!proto)                                                          \
2155
        if (!proto)                                                          \

Return to bug 703537