diff options
author | Martok <martok@martoks-place.de> | 2023-01-19 21:26:49 +0100 |
---|---|---|
committer | Martok <martok@martoks-place.de> | 2023-01-21 00:50:37 +0100 |
commit | 0d1d366685b09f4eb4173c563e05637630e20f1a (patch) | |
tree | bbd43a4c7529b01891250d92b2d22df9cb42ff9e /js | |
parent | 9536cf49ce2d9e975fe44951c703a92360ab4036 (diff) | |
download | uxp-0d1d366685b09f4eb4173c563e05637630e20f1a.tar.gz |
No issue - implement js::NativeDefineDataProperty helper
Diffstat (limited to 'js')
-rw-r--r-- | js/src/vm/NativeObject.cpp | 35 | ||||
-rw-r--r-- | js/src/vm/NativeObject.h | 12 |
2 files changed, 47 insertions, 0 deletions
diff --git a/js/src/vm/NativeObject.cpp b/js/src/vm/NativeObject.cpp index 53f7c0bfac..7418d81edf 100644 --- a/js/src/vm/NativeObject.cpp +++ b/js/src/vm/NativeObject.cpp @@ -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]] *****************************************************************************/ diff --git a/js/src/vm/NativeObject.h b/js/src/vm/NativeObject.h index abc84c9fd1..cf6d684ac0 100644 --- a/js/src/vm/NativeObject.h +++ b/js/src/vm/NativeObject.h @@ -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); |