[gjs: 9/15] object: Don't fetch property descriptor on interface
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 9/15] object: Don't fetch property descriptor on interface
- Date: Sun, 16 Jan 2022 21:28:17 +0000 (UTC)
commit 80265ba480f947e25a4e9c6bfe478198404c6c0a
Author: Philip Chimento <philip chimento gmail com>
Date: Fri Jan 14 16:55:00 2022 -0800
object: Don't fetch property descriptor on interface
It seems that nothing is actually used from the property descriptor, we
only check if it exists, which can be done with JS_HasProperty. Contrary
to what the comment says, the old descriptor is not copied (which will be
fixed in the next commit.)
gi/object.cpp | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 9196984d8..294b7dc6b 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -698,14 +698,13 @@ static bool resolve_on_interface_prototype(JSContext* cx,
if (!interface_prototype)
return false;
- JS::Rooted<JS::PropertyDescriptor> desc(cx);
- if (!JS_GetPropertyDescriptorById(cx, interface_prototype, identifier,
- &desc))
+ bool exists = false;
+ if (!JS_HasPropertyById(cx, interface_prototype, identifier, &exists))
return false;
// If the property doesn't exist on the interface prototype, we don't need
// to perform this trick.
- if (!desc.object()) {
+ if (!exists) {
*found = false;
return true;
}
@@ -753,13 +752,12 @@ static bool resolve_on_interface_prototype(JSContext* cx,
// Copy the original descriptor and remove any value, instead
// adding our getter and setter.
- JS::Rooted<JS::PropertyDescriptor> target_desc(cx, desc);
- target_desc.setValue(JS::UndefinedHandleValue);
- target_desc.setAttributes(JSPROP_SETTER | JSPROP_GETTER);
- target_desc.setGetterObject(getter);
- target_desc.setSetterObject(setter);
+ JS::Rooted<JS::PropertyDescriptor> desc(cx);
+ desc.setAttributes(JSPROP_SETTER | JSPROP_GETTER);
+ desc.setGetterObject(getter);
+ desc.setSetterObject(setter);
- if (!JS_DefinePropertyById(cx, class_prototype, identifier, target_desc))
+ if (!JS_DefinePropertyById(cx, class_prototype, identifier, desc))
return false;
*found = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]