Attachment #8450035: proxyConstructOnly.patch for bug #945566

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

(-)a/js/src/jit-test/tests/proxy/testDirectProxyConstructor.js (-7 / +3 lines)
Line     Link Here 
 Lines 1-23    Link Here 
1
load(libdir + "asserts.js");
1
load(libdir + "asserts.js");
2
2
3
// Throw a TypeError if Proxy is not called as a constructor
4
assertThrowsInstanceOf(function () { Proxy({}, {}); }, TypeError);
5
3
// Throw a TypeError if Proxy is called with less than two arguments
6
// Throw a TypeError if Proxy is called with less than two arguments
4
assertThrowsInstanceOf(function () { Proxy(); }, TypeError);
5
assertThrowsInstanceOf(function () { new Proxy(); }, TypeError);
7
assertThrowsInstanceOf(function () { new Proxy(); }, TypeError);
6
assertThrowsInstanceOf(function () { Proxy({}); }, TypeError);
7
assertThrowsInstanceOf(function () { new Proxy({}); }, TypeError);
8
assertThrowsInstanceOf(function () { new Proxy({}); }, TypeError);
8
9
9
// Throw a TypeError if the first argument is not a non-null object
10
// Throw a TypeError if the first argument is not a non-null object
10
assertThrowsInstanceOf(function () { Proxy(0, {}); }, TypeError);
11
assertThrowsInstanceOf(function () { new Proxy(0, {}); }, TypeError);
11
assertThrowsInstanceOf(function () { new Proxy(0, {}); }, TypeError);
12
assertThrowsInstanceOf(function () { Proxy(null, {}); }, TypeError);
13
assertThrowsInstanceOf(function () { new Proxy(null, {}); }, TypeError);
12
assertThrowsInstanceOf(function () { new Proxy(null, {}); }, TypeError);
14
13
15
// Throw a TypeError if the second argument is not a non-null object
14
// Throw a TypeError if the second argument is not a non-null object
16
assertThrowsInstanceOf(function () { Proxy({}, 0); }, TypeError);
17
assertThrowsInstanceOf(function () { new Proxy({}, 0); }, TypeError);
15
assertThrowsInstanceOf(function () { new Proxy({}, 0); }, TypeError);
18
assertThrowsInstanceOf(function () { Proxy({}, null); }, TypeError);
19
assertThrowsInstanceOf(function () { new Proxy({}, null); }, TypeError);
16
assertThrowsInstanceOf(function () { new Proxy({}, null); }, TypeError);
20
17
21
// Result of the call should be an object
18
// Result of the call should be an object
22
assertEq(typeof Proxy({}, {}), 'object');
23
assertEq(typeof new Proxy({}, {}), 'object');
19
assertEq(typeof new Proxy({}, {}), 'object');
(-)a/js/src/jsproxy.cpp (-5 / +17 lines)
Line     Link Here 
 Lines 2955-2973   ProxyObject::renew(JSContext *cx, BasePr Link Here 
2955
2955
2956
    setSlot(HANDLER_SLOT, PrivateValue(handler));
2956
    setSlot(HANDLER_SLOT, PrivateValue(handler));
2957
    setCrossCompartmentSlot(PRIVATE_SLOT, priv);
2957
    setCrossCompartmentSlot(PRIVATE_SLOT, priv);
2958
    setSlot(EXTRA_SLOT + 0, UndefinedValue());
2958
    setSlot(EXTRA_SLOT + 0, UndefinedValue());
2959
    setSlot(EXTRA_SLOT + 1, UndefinedValue());
2959
    setSlot(EXTRA_SLOT + 1, UndefinedValue());
2960
}
2960
}
2961
2961
2962
static bool
2962
static bool
2963
proxy(JSContext *cx, unsigned argc, jsval *vp)
2963
NewScriptedProxy(JSContext *cx, CallArgs &args)
2964
{
2964
{
2965
    CallArgs args = CallArgsFromVp(argc, vp);
2966
    if (args.length() < 2) {
2965
    if (args.length() < 2) {
2967
        JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
2966
        JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
2968
                             "Proxy", "1", "s");
2967
                             "Proxy", "1", "s");
2969
        return false;
2968
        return false;
2970
    }
2969
    }
2971
    RootedObject target(cx, NonNullObject(cx, args[0]));
2970
    RootedObject target(cx, NonNullObject(cx, args[0]));
2972
    if (!target)
2971
    if (!target)
2973
        return false;
2972
        return false;
 Lines 2984-2999   proxy(JSContext *cx, unsigned argc, jsva Link Here 
2984
    if (!proxy)
2983
    if (!proxy)
2985
        return false;
2984
        return false;
2986
    proxy->setExtra(ScriptedDirectProxyHandler::HANDLER_EXTRA, ObjectValue(*handler));
2985
    proxy->setExtra(ScriptedDirectProxyHandler::HANDLER_EXTRA, ObjectValue(*handler));
2987
    args.rval().setObject(*proxy);
2986
    args.rval().setObject(*proxy);
2988
    return true;
2987
    return true;
2989
}
2988
}
2990
2989
2991
static bool
2990
static bool
2991
proxy(JSContext *cx, unsigned argc, jsval *vp)
2992
{
2993
    CallArgs args = CallArgsFromVp(argc, vp);
2994
2995
    if (!args.isConstructing()) {
2996
        JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NOT_FUNCTION, "Proxy");
2997
        return false;
2998
    }
2999
3000
    return NewScriptedProxy(cx, args);
3001
}
3002
3003
static bool
2992
RevokeProxy(JSContext *cx, unsigned argc, Value *vp)
3004
RevokeProxy(JSContext *cx, unsigned argc, Value *vp)
2993
{
3005
{
2994
    CallReceiver rec = CallReceiverFromVp(vp);
3006
    CallReceiver rec = CallReceiverFromVp(vp);
2995
3007
2996
    RootedFunction func(cx, &rec.callee().as<JSFunction>());
3008
    RootedFunction func(cx, &rec.callee().as<JSFunction>());
2997
    RootedObject p(cx, func->getExtendedSlot(ScriptedDirectProxyHandler::REVOKE_SLOT).toObjectOrNull());
3009
    RootedObject p(cx, func->getExtendedSlot(ScriptedDirectProxyHandler::REVOKE_SLOT).toObjectOrNull());
2998
3010
2999
    if (p) {
3011
    if (p) {
 Lines 3007-3025   RevokeProxy(JSContext *cx, unsigned argc Link Here 
3007
3019
3008
    rec.rval().setUndefined();
3020
    rec.rval().setUndefined();
3009
    return true;
3021
    return true;
3010
}
3022
}
3011
3023
3012
static bool
3024
static bool
3013
proxy_revocable(JSContext *cx, unsigned argc, Value *vp)
3025
proxy_revocable(JSContext *cx, unsigned argc, Value *vp)
3014
{
3026
{
3015
    CallReceiver args = CallReceiverFromVp(vp);
3027
    CallArgs args = CallArgsFromVp(argc, vp);
3016
3028
3017
    if (!proxy(cx, argc, vp))
3029
    if (!NewScriptedProxy(cx, args))
3018
        return false;
3030
        return false;
3019
3031
3020
    RootedValue proxyVal(cx, args.rval());
3032
    RootedValue proxyVal(cx, args.rval());
3021
    MOZ_ASSERT(proxyVal.toObject().is<ProxyObject>());
3033
    MOZ_ASSERT(proxyVal.toObject().is<ProxyObject>());
3022
3034
3023
    RootedObject revoker(cx, NewFunctionWithReserved(cx, RevokeProxy, 0, 0, cx->global(),
3035
    RootedObject revoker(cx, NewFunctionWithReserved(cx, RevokeProxy, 0, 0, cx->global(),
3024
    "RevokeProxy"));
3036
    "RevokeProxy"));
3025
    if (!revoker) {
3037
    if (!revoker) {
(-)a/js/src/tests/ecma_6/Generators/delegating-yield-7.js (-1 / +1 lines)
Line     Link Here 
 Lines 9-25   function results(results) { Link Here 
9
        return results[i++];
9
        return results[i++];
10
    }
10
    }
11
    var ret = { next: next }
11
    var ret = { next: next }
12
    ret[std_iterator] = iterator;
12
    ret[std_iterator] = iterator;
13
    return ret;
13
    return ret;
14
}
14
}
15
15
16
function* yield_results(expected) {
16
function* yield_results(expected) {
17
    return yield* Proxy(results(expected), {});
17
    return yield* new Proxy(results(expected), {});
18
}
18
}
19
19
20
function collect_results(iter) {
20
function collect_results(iter) {
21
    var ret = [];
21
    var ret = [];
22
    var result;
22
    var result;
23
    do {
23
    do {
24
        result = iter.next();
24
        result = iter.next();
25
        ret.push(result);
25
        ret.push(result);

Return to bug 945566