Bug 603201 - Adjust SetPropertyOperation's signature slightly to be more pleasant. r=efaust

--HG--
extra : rebase_source : 42a81852d5d26c8df8973bf3fcc790ff0cea0bb5
This commit is contained in:
Jeff Walden 2014-12-19 14:01:08 -05:00
parent c1e10ae4e6
commit 1ce003ab98

View File

@ -303,39 +303,59 @@ NameOperation(JSContext *cx, InterpreterFrame *fp, jsbytecode *pc, MutableHandle
return FetchName<false>(cx, scopeRoot, pobjRoot, nameRoot, shapeRoot, vp); return FetchName<false>(cx, scopeRoot, pobjRoot, nameRoot, shapeRoot, vp);
} }
static inline bool static bool
SetPropertyOperation(JSContext *cx, HandleScript script, jsbytecode *pc, HandleValue lval, SetObjectProperty(JSContext *cx, JSOp op, HandleValue lval, HandleId id, MutableHandleValue rref)
HandleValue rval)
{ {
MOZ_ASSERT(*pc == JSOP_SETPROP || *pc == JSOP_STRICTSETPROP); MOZ_ASSERT(lval.isObject());
bool strict = *pc == JSOP_STRICTSETPROP; RootedObject obj(cx, &lval.toObject());
RootedObject obj(cx, ToObjectFromStack(cx, lval)); bool strict = op == JSOP_STRICTSETPROP;
if (!obj)
return false;
RootedValue rref(cx, rval);
RootedId id(cx, NameToId(script->getName(pc)));
if (MOZ_LIKELY(!obj->getOps()->setProperty)) { if (MOZ_LIKELY(!obj->getOps()->setProperty)) {
if (!baseops::SetPropertyHelper<SequentialExecution>(cx, if (!baseops::SetPropertyHelper<SequentialExecution>(cx,
obj.as<NativeObject>(), obj.as<NativeObject>(),
obj.as<NativeObject>(), obj.as<NativeObject>(),
id, id,
baseops::Qualified, baseops::Qualified,
&rref, strict)) rref, strict))
{ {
return false; return false;
} }
} else { } else {
if (!JSObject::setGeneric(cx, obj, obj, id, &rref, strict)) if (!JSObject::setGeneric(cx, obj, obj, id, rref, strict))
return false; return false;
} }
return true; return true;
} }
static bool
SetPrimitiveProperty(JSContext *cx, JSOp op, HandleValue lval, HandleId id,
MutableHandleValue rref)
{
MOZ_ASSERT(lval.isPrimitive());
RootedObject obj(cx, ToObjectFromStack(cx, lval));
if (!obj)
return false;
RootedValue receiver(cx, ObjectValue(*obj));
return SetObjectProperty(cx, op, receiver, id, rref);
}
static bool
SetPropertyOperation(JSContext *cx, JSOp op, HandleValue lval, HandleId id, HandleValue rval)
{
MOZ_ASSERT(op == JSOP_SETPROP || op == JSOP_STRICTSETPROP);
RootedValue rref(cx, rval);
if (lval.isPrimitive())
return SetPrimitiveProperty(cx, op, lval, id, &rref);
return SetObjectProperty(cx, op, lval, id, &rref);
}
bool bool
js::ReportIsNotFunction(JSContext *cx, HandleValue v, int numToSkip, MaybeConstruct construct) js::ReportIsNotFunction(JSContext *cx, HandleValue v, int numToSkip, MaybeConstruct construct)
{ {
@ -2403,7 +2423,9 @@ CASE(JSOP_STRICTSETPROP)
HandleValue lval = REGS.stackHandleAt(-2); HandleValue lval = REGS.stackHandleAt(-2);
HandleValue rval = REGS.stackHandleAt(-1); HandleValue rval = REGS.stackHandleAt(-1);
if (!SetPropertyOperation(cx, script, REGS.pc, lval, rval)) RootedId &id = rootId0;
id = NameToId(script->getName(REGS.pc));
if (!SetPropertyOperation(cx, JSOp(*REGS.pc), lval, id, rval))
goto error; goto error;
REGS.sp[-2] = REGS.sp[-1]; REGS.sp[-2] = REGS.sp[-1];