Bug 1259877 - Update ScriptedDirectProxyHandler code to use js::Call and FixedInvokeArgs. r=evilpie
authorJeff Walden <jwalden@mit.edu>
Mon, 21 Mar 2016 16:17:28 -0700
changeset 293149 69079481ba3a240784613c05e58cd9ed9841afc3
parent 293148 ceeb25518b0c0e7e02867e91de33eb99cc6a7b5e
child 293150 4012e45e502eebdea798846bfd2234aec4ccd6b2
push id30175
push usercbook@mozilla.com
push dateThu, 14 Apr 2016 09:38:40 +0000
treeherdermozilla-central@91115264629d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie
bugs1259877
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1259877 - Update ScriptedDirectProxyHandler code to use js::Call and FixedInvokeArgs. r=evilpie
js/src/proxy/ScriptedDirectProxyHandler.cpp
--- a/js/src/proxy/ScriptedDirectProxyHandler.cpp
+++ b/js/src/proxy/ScriptedDirectProxyHandler.cpp
@@ -232,21 +232,19 @@ ScriptedDirectProxyHandler::preventExten
 
     // Step 6.
     if (trap.isUndefined())
         return PreventExtensions(cx, target, result);
 
     // Step 7.
     bool booleanTrapResult;
     {
-        Value argv[] = {
-            ObjectValue(*target)
-        };
+        RootedValue arg(cx, ObjectValue(*target));
         RootedValue trapResult(cx);
-        if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
+        if (!Call(cx, trap, handler, arg, &trapResult))
             return false;
 
         booleanTrapResult = ToBoolean(trapResult);
     }
 
     // Step 8.
     if (booleanTrapResult) {
         // Step 8a.
@@ -288,24 +286,25 @@ ScriptedDirectProxyHandler::isExtensible
     if (!GetProxyTrap(cx, handler, cx->names().isExtensible, &trap))
         return false;
 
     // Step 6.
     if (trap.isUndefined())
         return IsExtensible(cx, target, extensible);
 
     // Step 7.
-    Value argv[] = {
-        ObjectValue(*target)
-    };
-    RootedValue trapResult(cx);
-    if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
-        return false;
+    bool booleanTrapResult;
+    {
+        RootedValue arg(cx, ObjectValue(*target));
+        RootedValue trapResult(cx);
+        if (!Call(cx, trap, handler, arg, &trapResult))
+            return false;
 
-    bool booleanTrapResult = ToBoolean(trapResult);
+        booleanTrapResult = ToBoolean(trapResult);
+    }
 
     // Steps 8.
     bool targetResult;
     if (!IsExtensible(cx, target, &targetResult))
         return false;
 
     // Step 9.
     if (targetResult != booleanTrapResult) {
@@ -343,22 +342,19 @@ ScriptedDirectProxyHandler::getOwnProper
     if (trap.isUndefined())
         return GetOwnPropertyDescriptor(cx, target, id, desc);
 
     // Step 8.
     RootedValue propKey(cx);
     if (!IdToStringOrSymbol(cx, id, &propKey))
         return false;
 
-    Value argv[] = {
-        ObjectValue(*target),
-        propKey
-    };
     RootedValue trapResult(cx);
-    if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
+    RootedValue targetVal(cx, ObjectValue(*target));
+    if (!Call(cx, trap, handler, targetVal, propKey, &trapResult))
         return false;
 
     // Step 9.
     if (!trapResult.isUndefined() && !trapResult.isObject()) {
         JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_PROXY_GETOWN_OBJORUNDEF);
         return false;
     }
 
@@ -471,24 +467,28 @@ ScriptedDirectProxyHandler::defineProper
     if (!FromPropertyDescriptorToObject(cx, desc, &descObj))
         return false;
 
     // Step 9.
     RootedValue propKey(cx);
     if (!IdToStringOrSymbol(cx, id, &propKey))
         return false;
 
-    Value argv[] = {
-        ObjectValue(*target),
-        propKey,
-        descObj
-    };
     RootedValue trapResult(cx);
-    if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
-        return false;
+    {
+        FixedInvokeArgs<3> args(cx);
+
+        args[0].setObject(*target);
+        args[1].set(propKey);
+        args[2].set(descObj);
+
+        RootedValue thisv(cx, ObjectValue(*handler));
+        if (!Call(cx, trap, thisv, args, &trapResult))
+            return false;
+    }
 
     // Step 10.
     if (!ToBoolean(trapResult))
         return result.fail(JSMSG_PROXY_DEFINE_RETURNED_FALSE);
 
     // Step 11.
     Rooted<PropertyDescriptor> targetDesc(cx);
     if (!GetOwnPropertyDescriptor(cx, target, id, &targetDesc))
@@ -598,21 +598,19 @@ ScriptedDirectProxyHandler::ownPropertyK
     if (!GetProxyTrap(cx, handler, cx->names().ownKeys, &trap))
         return false;
 
     // Step 6.
     if (trap.isUndefined())
         return GetPropertyKeys(cx, target, JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &props);
 
     // Step 7.
-    Value argv[] = {
-        ObjectValue(*target)
-    };
     RootedValue trapResultArray(cx);
-    if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResultArray))
+    RootedValue targetVal(cx, ObjectValue(*target));
+    if (!Call(cx, trap, handler, targetVal, &trapResultArray))
         return false;
 
     // Step 8.
     AutoIdVector trapResult(cx);
     if (!CreateFilteredListFromArrayLike(cx, trapResultArray, trapResult))
         return false;
 
     // Step 9.
@@ -745,22 +743,19 @@ ScriptedDirectProxyHandler::delete_(JSCo
 
     // Step 8.
     bool booleanTrapResult;
     {
         RootedValue value(cx);
         if (!IdToStringOrSymbol(cx, id, &value))
             return false;
 
-        Value argv[] = {
-            ObjectValue(*target),
-            value
-        };
+        RootedValue targetVal(cx, ObjectValue(*target));
         RootedValue trapResult(cx);
-        if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
+        if (!Call(cx, trap, handler, targetVal, value, &trapResult))
             return false;
 
         booleanTrapResult = ToBoolean(trapResult);
     }
 
     // Step 9.
     if (!booleanTrapResult)
         return result.fail(JSMSG_PROXY_DELETE_RETURNED_FALSE);
@@ -804,22 +799,20 @@ ScriptedDirectProxyHandler::has(JSContex
     // Step 7.
     if (trap.isUndefined())
         return HasProperty(cx, target, id, bp);
 
     // Step 8.
     RootedValue value(cx);
     if (!IdToStringOrSymbol(cx, id, &value))
         return false;
-    Value argv[] = {
-        ObjectOrNullValue(target),
-        value
-    };
+
     RootedValue trapResult(cx);
-    if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
+    RootedValue targetVal(cx, ObjectValue(*target));
+    if (!Call(cx, trap, handler, targetVal, value, &trapResult))
         return false;
 
     bool booleanTrapResult = ToBoolean(trapResult);
 
     // Step 9.
     if (!booleanTrapResult) {
         // Step 9a.
         Rooted<PropertyDescriptor> desc(cx);
@@ -876,24 +869,29 @@ ScriptedDirectProxyHandler::get(JSContex
     // Step 7.
     if (trap.isUndefined())
         return GetProperty(cx, target, receiver, id, vp);
 
     // Step 8.
     RootedValue value(cx);
     if (!IdToStringOrSymbol(cx, id, &value))
         return false;
-    Value argv[] = {
-        ObjectOrNullValue(target),
-        value,
-        receiver
-    };
+
     RootedValue trapResult(cx);
-    if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
-        return false;
+    {
+        FixedInvokeArgs<3> args(cx);
+
+        args[0].setObject(*target);
+        args[1].set(value);
+        args[2].set(receiver);
+
+        RootedValue thisv(cx, ObjectValue(*handler));
+        if (!Call(cx, trap, thisv, args, &trapResult))
+            return false;
+    }
 
     // Step 9.
     Rooted<PropertyDescriptor> desc(cx);
     if (!GetOwnPropertyDescriptor(cx, target, id, &desc))
         return false;
 
     // Step 10.
     if (desc.object()) {
@@ -946,25 +944,30 @@ ScriptedDirectProxyHandler::set(JSContex
     // Step 7.
     if (trap.isUndefined())
         return SetProperty(cx, target, id, v, receiver, result);
 
     // Step 8.
     RootedValue value(cx);
     if (!IdToStringOrSymbol(cx, id, &value))
         return false;
-    Value argv[] = {
-        ObjectOrNullValue(target),
-        value,
-        v.get(),
-        receiver.get()
-    };
+
     RootedValue trapResult(cx);
-    if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
-        return false;
+    {
+        FixedInvokeArgs<4> args(cx);
+
+        args[0].setObject(*target);
+        args[1].set(value);
+        args[2].set(v);
+        args[3].set(receiver);
+
+        RootedValue thisv(cx, ObjectValue(*handler));
+        if (!Call(cx, trap, thisv, args, &trapResult))
+            return false;
+    }
 
     // Step 9.
     if (!ToBoolean(trapResult))
         return result.fail(JSMSG_PROXY_SET_RETURNED_FALSE);
 
     // Step 10.
     Rooted<PropertyDescriptor> desc(cx);
     if (!GetOwnPropertyDescriptor(cx, target, id, &desc))
@@ -1012,33 +1015,38 @@ ScriptedDirectProxyHandler::call(JSConte
 
     // Step 5.
     RootedValue trap(cx);
     if (!GetProxyTrap(cx, handler, cx->names().apply, &trap))
         return false;
 
     // Step 6.
     if (trap.isUndefined()) {
-        RootedValue targetv(cx, ObjectValue(*target));
-        return Invoke(cx, args.thisv(), targetv, args.length(), args.array(), args.rval());
+        InvokeArgs iargs(cx);
+        if (!FillArgumentsFromArraylike(cx, iargs, args))
+            return false;
+
+        RootedValue fval(cx, ObjectValue(*target));
+        return js::Call(cx, fval, args.thisv(), iargs, args.rval());
     }
 
     // Step 7.
     RootedObject argArray(cx, NewDenseCopiedArray(cx, args.length(), args.array()));
     if (!argArray)
         return false;
 
     // Step 8.
-    Value argv[] = {
-        ObjectValue(*target),
-        args.thisv(),
-        ObjectValue(*argArray)
-    };
-    RootedValue thisValue(cx, ObjectValue(*handler));
-    return Invoke(cx, thisValue, trap, ArrayLength(argv), argv, args.rval());
+    FixedInvokeArgs<3> iargs(cx);
+
+    iargs[0].setObject(*target);
+    iargs[1].set(args.thisv());
+    iargs[2].setObject(*argArray);
+
+    RootedValue thisv(cx, ObjectValue(*handler));
+    return js::Call(cx, trap, thisv, iargs, args.rval());
 }
 
 // ES7 0c1bd3004329336774cbc90de727cd0cf5f11e93 9.5.14 Proxy.[[Construct]]
 bool
 ScriptedDirectProxyHandler::construct(JSContext* cx, HandleObject proxy, const CallArgs& args) const
 {
     // Steps 1-3.
     RootedObject handler(cx, GetDirectProxyHandlerObject(proxy));
@@ -1073,24 +1081,27 @@ ScriptedDirectProxyHandler::construct(JS
     }
 
     // Step 7.
     RootedObject argArray(cx, NewDenseCopiedArray(cx, args.length(), args.array()));
     if (!argArray)
         return false;
 
     // Steps 8, 10.
-    Value constructArgv[] = {
-        ObjectValue(*target),
-        ObjectValue(*argArray),
-        args.newTarget()
-    };
-    RootedValue thisValue(cx, ObjectValue(*handler));
-    if (!Invoke(cx, thisValue, trap, ArrayLength(constructArgv), constructArgv, args.rval()))
-        return false;
+    {
+        FixedInvokeArgs<3> iargs(cx);
+
+        iargs[0].setObject(*target);
+        iargs[1].setObject(*argArray);
+        iargs[2].set(args.newTarget());
+
+        RootedValue thisv(cx, ObjectValue(*handler));
+        if (!Call(cx, trap, thisv, iargs, args.rval()))
+            return false;
+    }
 
     // Step 9.
     if (!args.rval().isObject()) {
         JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_PROXY_CONSTRUCT_OBJECT);
         return false;
     }
 
     return true;