Issue #2142 - Change InitPropertyOperation to accept a PropertyName directy and use DefineDataProperty

Based-on: m-c 1413907, 1547129
This commit is contained in:
Martok 2023-04-09 19:18:03 +02:00 committed by roytam1
commit 627d0da7dc
4 changed files with 11 additions and 12 deletions

View file

@ -4584,7 +4584,7 @@ DoSetPropFallback(JSContext* cx, BaselineFrame* frame, ICSetProp_Fallback* stub_
op == JSOP_INITLOCKEDPROP ||
op == JSOP_INITHIDDENPROP)
{
if (!InitPropertyOperation(cx, op, obj, id, rhs))
if (!InitPropertyOperation(cx, op, obj, name, rhs))
return false;
} else if (op == JSOP_SETNAME ||
op == JSOP_STRICTSETNAME ||

View file

@ -232,8 +232,7 @@ bool
InitProp(JSContext* cx, HandleObject obj, HandlePropertyName name, HandleValue value,
jsbytecode* pc)
{
RootedId id(cx, NameToId(name));
return InitPropertyOperation(cx, JSOp(*pc), obj, id, value);
return InitPropertyOperation(cx, JSOp(*pc), obj, name, value);
}
template<bool Equal>

View file

@ -340,12 +340,15 @@ InitGlobalLexicalOperation(JSContext* cx, LexicalEnvironmentObject* lexicalEnvAr
}
inline bool
InitPropertyOperation(JSContext* cx, JSOp op, HandleObject obj, HandleId id, HandleValue rhs)
InitPropertyOperation(JSContext* cx, JSOp op, HandleObject obj, HandlePropertyName name, HandleValue rhs)
{
if (obj->is<PlainObject>() || obj->is<JSFunction>()) {
RootedId id(cx, NameToId(name));
// {Goanna} DefineProperty works on almost any JSObject, but there's no good way to check what works
// So instead, check what we don't handle explicitly.
if (!obj->is<UnboxedPlainObject>()) {
unsigned propAttrs = GetInitDataPropAttrs(op);
return NativeDefineProperty(cx, obj.as<NativeObject>(), id, rhs, nullptr, nullptr,
propAttrs);
return DefineProperty(cx, obj, id, rhs, nullptr, nullptr, propAttrs);
}
MOZ_ASSERT(obj->as<UnboxedPlainObject>().layout().lookup(id));

View file

@ -3744,12 +3744,9 @@ CASE(JSOP_INITHIDDENPROP)
/* Load the object being initialized into lval/obj. */
ReservedRooted<JSObject*> obj(&rootObject0, &REGS.sp[-2].toObject());
PropertyName* name = script->getName(REGS.pc);
ReservedRooted<PropertyName*> name(&rootName0, script->getName(REGS.pc));
RootedId& id = rootId0;
id = NameToId(name);
if (!InitPropertyOperation(cx, JSOp(*REGS.pc), obj, id, rval))
if (!InitPropertyOperation(cx, JSOp(*REGS.pc), obj, name, rval))
goto error;
REGS.sp--;