Closed Bug 482381 Opened 15 years ago Closed 15 years ago

Add a JS_GetPropertyDescriptorById

Categories

(Core :: JavaScript Engine, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9.1b4

People

(Reporter: mrbkap, Assigned: mrbkap)

References

Details

(Keywords: fixed1.9.1)

Attachments

(1 file, 3 obsolete files)

Currently, getting a property's attributes, getter and setter anywhere on the prototype chain involves calling JS_LookupPropertyWithFlagsById, followed by JS_GetPropertyAttrsGetterAndSetter. Having to call two functions is less than ideal. Here's a patch to add it.
Attached patch patch v1 (obsolete) — Splinter Review
Attachment #366478 - Flags: review?(brendan)
Comment on attachment 366478 [details] [diff] [review]
patch v1

>+    JS_ASSERT((foundp != NULL) ^ (objp != NULL));

Some find != less obscure than ^ here. YMMV, look for other such assertions.

>+            if (vp)
>+                *vp = NULL;

Oops -- JSVAL_VOID, not NULL.

>+/*
>+ * Like JS_GetPropertyAttrsGetterAndSetterById but will return a property on
>+ * an object on the prototype chain (returned in objp). If objp is null, then
>+ * this property was not found on the prototype chain.
>+ */
>+extern JS_PUBLIC_API(JSBool)
>+JS_LookupPropertyInfoById(JSContext *cx, JSObject *obj, jsid id, uintN flags,
>+                          JSObject **objp, uintN *attrsp,
>+                          JSPropertyOp *getterp, JSPropertyOp *setterp,
>+                          jsval *vp);

My only misgiving about adding this now is that we might prefer JS_GetOwnPropertyDescriptor based on ES3.1 in the long run, and a C-ish version of it might look a lot like this, but with a struct out param (a la stat(2)). Or maybe not. Thoughts welcome from you, jorendorff, and bugwatchers.

/be
This might be too cute, but C++ does have trigraphs (?), and xor would be clearer there than ^.
Waldo: your (?) came thru like that, but let's not use trigraphs. Either != or ^. This is not the obfuscated C programming contest you know :-P.

/be
Attached patch patch v2 (obsolete) — Splinter Review
Attachment #366478 - Attachment is obsolete: true
Attachment #366490 - Flags: review?(brendan)
Attachment #366478 - Flags: review?(brendan)
Attached patch patch v3 (obsolete) — Splinter Review
Attachment #366490 - Attachment is obsolete: true
Attachment #366496 - Flags: review?(brendan)
Attachment #366490 - Flags: review?(brendan)
Summary: Add a JS_LookupPropertyInfo → Add a JS_GetPropertyDescriptorById
Comment on attachment 366496 [details] [diff] [review]
patch v3

>+struct JSPropertyDescriptor {
>+    JSObject *obj;
>+    uintN attrs;
>+    JSPropertyOp getter;
>+    JSPropertyOp setter;
>+    jsval v;
>+};

Nits: s/v/value/ and tabulate so declarators (including * for obj) start in same column.

/be
Attachment #366496 - Flags: review?(brendan) → review+
Attached patch patch v3+Splinter Review
This is what I'll check in tomorrow.
Attachment #366496 - Attachment is obsolete: true
Attachment #366507 - Flags: review+
This is a fine idea.  It does seem weird to have structs named JSPropertyDesc and JSPropertyDescriptor though.

mrbkap, please document this on MDC.

Instead of "value" it could be "slotValue" or "storedValue" (which has the dubious advantage of being the term I use in the documentation; see https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/Stored_value and links to that page in places like https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JS_LookupProperty ).
JSPropertyDesc and JSPropertyDescArray hide in jsdbgapi.h. This is not the worst such name near-miss in the history of long-lived code (see Unix system calls, or the Windows API). But we could deprecate or rename them more easily. For ES3.1 brainprint reduction, the new API in this bug should use Property Descriptor as directly as possible.

With a C++ API we could lose the JS prefix and make a js namespace. Purty!

/be
http://hg.mozilla.org/mozilla-central/rev/14677a61f29d
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Blocks: 480185
I would rather just "value" -- docs can say "stored", value matches ES3.1's [[Value]]. It's the word the engine uses everywhere, and abbreviates via v and vp. The fact that it's stored becomes implicit if it isn't the first few times you run across it.

/be
Flags: in-testsuite-
Flags: blocking1.9.1?
Flags: blocking1.9.1? → blocking1.9.1+
Target Milestone: --- → mozilla1.9.1b4
The documentation for this method is sadly lacking in usefulness (https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyDescriptorById).
Keywords: dev-doc-needed
I've added an initial table here, but could use some help filling out details. Can anyone help?

https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyDescriptorById#The_JSPropertyDescriptor_structure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: