No issue - implement js::NativeDefineDataProperty helper

This commit is contained in:
Martok 2023-01-19 21:26:49 +01:00 committed by roytam1
commit 2db0386e65
2 changed files with 47 additions and 0 deletions

View file

@ -1675,6 +1675,41 @@ js::NativeDefineProperty(ExclusiveContext* cx, HandleNativeObject obj, PropertyN
return NativeDefineProperty(cx, obj, id, value, getter, setter, attrs);
}
bool
js::NativeDefineDataProperty(JSContext* cx, Handle<NativeObject*> obj, HandleId id, HandleValue value,
unsigned attrs, ObjectOpResult& result)
{
Rooted<PropertyDescriptor> desc(cx);
desc.initFields(nullptr, value, attrs, nullptr, nullptr);
return NativeDefineProperty(cx, obj, id, desc, result);
}
bool
js::NativeDefineDataProperty(JSContext* cx, Handle<NativeObject*> obj, HandleId id, HandleValue value,
unsigned attrs)
{
ObjectOpResult result;
if (!NativeDefineDataProperty(cx, obj, id, value, attrs, result)) {
return false;
}
if (!result) {
// Off-thread callers should not get here: they must call this
// function only with known-valid arguments. Populating a new
// PlainObject with configurable properties is fine.
MOZ_ASSERT(!cx->isHelperThreadContext());
result.reportError(cx, obj, id);
return false;
}
return true;
}
bool
js::NativeDefineDataProperty(JSContext* cx, Handle<NativeObject*> obj, PropertyName* name, HandleValue value,
unsigned attrs)
{
RootedId id(cx, NameToId(name));
return NativeDefineDataProperty(cx, obj, id, value, attrs);
}
/*** [[HasProperty]] *****************************************************************************/

View file

@ -1399,6 +1399,18 @@ NativeDefineProperty(ExclusiveContext* cx, HandleNativeObject obj, PropertyName*
HandleValue value, JSGetterOp getter, JSSetterOp setter,
unsigned attrs);
bool
NativeDefineDataProperty(JSContext* cx, Handle<NativeObject*> obj, HandleId id, HandleValue value,
unsigned attrs, ObjectOpResult& result);
extern bool
NativeDefineDataProperty(JSContext* cx, Handle<NativeObject*> obj, HandleId id,
HandleValue value, unsigned attrs);
extern bool
NativeDefineDataProperty(JSContext* cx, Handle<NativeObject*> obj, PropertyName* name,
HandleValue value, unsigned attrs);
extern bool
NativeHasProperty(JSContext* cx, HandleNativeObject obj, HandleId id, bool* foundp);