зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1259877 - Update various builtins to use js::Call, not js::Invoke. r=efaust
--HG-- extra : rebase_source : 48a39d68dfbda641fbf1ace43864d70716bf145b
This commit is contained in:
Родитель
0fe8132890
Коммит
32071a25f8
|
@ -1475,23 +1475,18 @@ js::InitSelfHostingCollectionIteratorFunctions(JSContext* cx, HandleObject obj)
|
|||
|
||||
/*** JS static utility functions *********************************************/
|
||||
|
||||
static
|
||||
bool
|
||||
static bool
|
||||
forEach(const char* funcName, JSContext *cx, HandleObject obj, HandleValue callbackFn, HandleValue thisArg)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
|
||||
RootedId forEachId(cx, NameToId(cx->names().forEach));
|
||||
RootedFunction forEachFunc(cx, JS::GetSelfHostedFunction(cx, funcName, forEachId, 2));
|
||||
if (!forEachFunc)
|
||||
return false;
|
||||
InvokeArgs args(cx);
|
||||
if (!args.init(2))
|
||||
return false;
|
||||
args.setCallee(JS::ObjectValue(*forEachFunc));
|
||||
args.setThis(JS::ObjectValue(*obj));
|
||||
args[0].set(callbackFn);
|
||||
args[1].set(thisArg);
|
||||
return Invoke(cx, args);
|
||||
|
||||
RootedValue fval(cx, ObjectValue(*forEachFunc));
|
||||
return Call(cx, fval, obj, callbackFn, thisArg, &fval);
|
||||
}
|
||||
|
||||
// Handles Clear/Size for public jsapi map/set access
|
||||
|
|
|
@ -1144,7 +1144,8 @@ ArrayJoinKernel(JSContext* cx, SeparatorOp sepOp, HandleObject obj, uint32_t len
|
|||
RootedValue fun(cx);
|
||||
if (!GetProperty(cx, v, cx->names().toLocaleString, &fun))
|
||||
return false;
|
||||
if (!Invoke(cx, v, fun, 0, nullptr, &v))
|
||||
|
||||
if (!Call(cx, fun, v, &v))
|
||||
return false;
|
||||
}
|
||||
if (!ValueToStringBuffer(cx, v, sb))
|
||||
|
@ -1833,8 +1834,7 @@ js::array_sort(JSContext* cx, unsigned argc, Value* vp)
|
|||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
RootedValue fvalRoot(cx);
|
||||
Value& fval = fvalRoot.get();
|
||||
RootedValue fval(cx);
|
||||
|
||||
if (args.hasDefined(0)) {
|
||||
if (args[0].isPrimitive()) {
|
||||
|
@ -1871,20 +1871,7 @@ js::array_sort(JSContext* cx, unsigned argc, Value* vp)
|
|||
MOZ_ASSERT(selfHostedSortValue.isObject());
|
||||
MOZ_ASSERT(selfHostedSortValue.toObject().is<JSFunction>());
|
||||
|
||||
InvokeArgs iargs(cx);
|
||||
|
||||
if (!iargs.init(1))
|
||||
return false;
|
||||
|
||||
iargs.setCallee(selfHostedSortValue);
|
||||
iargs.setThis(args.thisv());
|
||||
iargs[0].set(fval);
|
||||
|
||||
if (!Invoke(cx, iargs))
|
||||
return false;
|
||||
|
||||
args.rval().set(iargs.rval());
|
||||
return true;
|
||||
return Call(cx, selfHostedSortValue, args.thisv(), fval, args.rval());
|
||||
}
|
||||
|
||||
uint32_t len;
|
||||
|
|
|
@ -2553,17 +2553,7 @@ date_toJSON(JSContext* cx, unsigned argc, Value* vp)
|
|||
}
|
||||
|
||||
/* Step 6. */
|
||||
InvokeArgs args2(cx);
|
||||
if (!args2.init(0))
|
||||
return false;
|
||||
|
||||
args2.setCallee(toISO);
|
||||
args2.setThis(ObjectValue(*obj));
|
||||
|
||||
if (!Invoke(cx, args2))
|
||||
return false;
|
||||
args.rval().set(args2.rval());
|
||||
return true;
|
||||
return Call(cx, toISO, obj, args.rval());
|
||||
}
|
||||
|
||||
/* for Date.toLocaleFormat; interface to PRMJTime date struct.
|
||||
|
|
|
@ -3017,7 +3017,8 @@ MaybeCallMethod(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue
|
|||
vp.setObject(*obj);
|
||||
return true;
|
||||
}
|
||||
return Invoke(cx, ObjectValue(*obj), vp, 0, nullptr, vp);
|
||||
|
||||
return js::Call(cx, vp, obj, vp);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -3127,18 +3128,19 @@ js::ToPrimitiveSlow(JSContext* cx, JSType preferredType, MutableHandleValue vp)
|
|||
|
||||
// Step 6.
|
||||
if (!method.isUndefined()) {
|
||||
// Step 6 of GetMethod. Invoke() below would do this check and throw a
|
||||
// Step 6 of GetMethod. js::Call() below would do this check and throw a
|
||||
// TypeError anyway, but this produces a better error message.
|
||||
if (!IsCallable(method))
|
||||
return ReportCantConvert(cx, JSMSG_TOPRIMITIVE_NOT_CALLABLE, obj, preferredType);
|
||||
|
||||
// Steps 1-3.
|
||||
RootedValue hint(cx, StringValue(preferredType == JSTYPE_STRING ? cx->names().string :
|
||||
preferredType == JSTYPE_NUMBER ? cx->names().number :
|
||||
cx->names().default_));
|
||||
// Steps 1-3, 6.a-b.
|
||||
RootedValue arg0(cx, StringValue(preferredType == JSTYPE_STRING
|
||||
? cx->names().string
|
||||
: preferredType == JSTYPE_NUMBER
|
||||
? cx->names().number
|
||||
: cx->names().default_));
|
||||
|
||||
// Steps 6.a-b.
|
||||
if (!Invoke(cx, vp, method, 1, hint.address(), vp))
|
||||
if (!js::Call(cx, method, vp, arg0, vp))
|
||||
return false;
|
||||
|
||||
// Steps 6.c-d.
|
||||
|
|
|
@ -237,17 +237,9 @@ PreprocessValue(JSContext* cx, HandleObject holder, KeyType key, MutableHandleVa
|
|||
if (!keyStr)
|
||||
return false;
|
||||
|
||||
InvokeArgs args(cx);
|
||||
if (!args.init(1))
|
||||
RootedValue arg0(cx, StringValue(keyStr));
|
||||
if (!js::Call(cx, toJSON, vp, arg0, vp))
|
||||
return false;
|
||||
|
||||
args.setCallee(toJSON);
|
||||
args.setThis(vp);
|
||||
args[0].setString(keyStr);
|
||||
|
||||
if (!Invoke(cx, args))
|
||||
return false;
|
||||
vp.set(args.rval());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,18 +251,10 @@ PreprocessValue(JSContext* cx, HandleObject holder, KeyType key, MutableHandleVa
|
|||
return false;
|
||||
}
|
||||
|
||||
InvokeArgs args(cx);
|
||||
if (!args.init(2))
|
||||
RootedValue arg0(cx, StringValue(keyStr));
|
||||
RootedValue replacerVal(cx, ObjectValue(*scx->replacer));
|
||||
if (!js::Call(cx, replacerVal, holder, arg0, vp, vp))
|
||||
return false;
|
||||
|
||||
args.setCallee(ObjectValue(*scx->replacer));
|
||||
args.setThis(ObjectValue(*holder));
|
||||
args[0].setString(keyStr);
|
||||
args[1].set(vp);
|
||||
|
||||
if (!Invoke(cx, args))
|
||||
return false;
|
||||
vp.set(args.rval());
|
||||
}
|
||||
|
||||
/* Step 4. */
|
||||
|
@ -848,19 +832,8 @@ Walk(JSContext* cx, HandleObject holder, HandleId name, HandleValue reviver, Mut
|
|||
if (!key)
|
||||
return false;
|
||||
|
||||
InvokeArgs args(cx);
|
||||
if (!args.init(2))
|
||||
return false;
|
||||
|
||||
args.setCallee(reviver);
|
||||
args.setThis(ObjectValue(*holder));
|
||||
args[0].setString(key);
|
||||
args[1].set(val);
|
||||
|
||||
if (!Invoke(cx, args))
|
||||
return false;
|
||||
vp.set(args.rval());
|
||||
return true;
|
||||
RootedValue keyVal(cx, StringValue(key));
|
||||
return js::Call(cx, reviver, holder, keyVal, val, vp);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
|
@ -2893,10 +2893,11 @@ js::ValueToSource(JSContext* cx, HandleValue v)
|
|||
if (!GetProperty(cx, obj, obj, cx->names().toSource, &fval))
|
||||
return nullptr;
|
||||
if (IsCallable(fval)) {
|
||||
RootedValue rval(cx);
|
||||
if (!Invoke(cx, ObjectValue(*obj), fval, 0, nullptr, &rval))
|
||||
RootedValue v(cx);
|
||||
if (!js::Call(cx, fval, obj, &v))
|
||||
return nullptr;
|
||||
return ToString<CanGC>(cx, rval);
|
||||
|
||||
return ToString<CanGC>(cx, v);
|
||||
}
|
||||
|
||||
return ObjectToSource(cx, obj);
|
||||
|
|
|
@ -569,19 +569,19 @@ class TypedArrayObjectTemplate : public TypedArrayObject
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
InvokeArgs args(cx);
|
||||
if (!args.init(3))
|
||||
return nullptr;
|
||||
FixedInvokeArgs<3> args(cx);
|
||||
|
||||
args.setCallee(cx->compartment()->maybeGlobal()->createArrayFromBuffer<NativeType>());
|
||||
args.setThis(ObjectValue(*bufobj));
|
||||
args[0].setNumber(byteOffset);
|
||||
args[1].setInt32(lengthInt);
|
||||
args[2].setObject(*protoRoot);
|
||||
|
||||
if (!Invoke(cx, args))
|
||||
RootedValue fval(cx, cx->global()->createArrayFromBuffer<NativeType>());
|
||||
RootedValue thisv(cx, ObjectValue(*bufobj));
|
||||
RootedValue rval(cx);
|
||||
if (!js::Call(cx, fval, thisv, args, &rval))
|
||||
return nullptr;
|
||||
return &args.rval().toObject();
|
||||
|
||||
return &rval.toObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1457,18 +1457,15 @@ DataViewObject::constructWrapped(JSContext* cx, HandleObject bufobj, const CallA
|
|||
return false;
|
||||
}
|
||||
|
||||
InvokeArgs args2(cx);
|
||||
if (!args2.init(3))
|
||||
return false;
|
||||
args2.setCallee(global->createDataViewForThis());
|
||||
args2.setThis(ObjectValue(*bufobj));
|
||||
FixedInvokeArgs<3> args2(cx);
|
||||
|
||||
args2[0].set(PrivateUint32Value(byteOffset));
|
||||
args2[1].set(PrivateUint32Value(byteLength));
|
||||
args2[2].setObject(*proto);
|
||||
if (!Invoke(cx, args2))
|
||||
return false;
|
||||
args.rval().set(args2.rval());
|
||||
return true;
|
||||
|
||||
RootedValue fval(cx, global->createDataViewForThis());
|
||||
RootedValue thisv(cx, ObjectValue(*bufobj));
|
||||
return js::Call(cx, fval, thisv, args2, args.rval());
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
Загрузка…
Ссылка в новой задаче