Closed
Bug 482381
Opened 16 years ago
Closed 16 years ago
Add a JS_GetPropertyDescriptorById
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
FIXED
mozilla1.9.1b4
People
(Reporter: mrbkap, Assigned: mrbkap)
References
Details
(Keywords: fixed1.9.1)
Attachments
(1 file, 3 obsolete files)
7.81 KB,
patch
|
mrbkap
:
review+
|
Details | Diff | Splinter Review |
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.
Assignee | ||
Comment 1•16 years ago
|
||
Attachment #366478 -
Flags: review?(brendan)
Comment 2•16 years ago
|
||
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
Comment 3•16 years ago
|
||
This might be too cute, but C++ does have trigraphs (?), and xor would be clearer there than ^.
Comment 4•16 years ago
|
||
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
Assignee | ||
Comment 5•16 years ago
|
||
Attachment #366478 -
Attachment is obsolete: true
Attachment #366490 -
Flags: review?(brendan)
Attachment #366478 -
Flags: review?(brendan)
Assignee | ||
Comment 6•16 years ago
|
||
Attachment #366490 -
Attachment is obsolete: true
Attachment #366496 -
Flags: review?(brendan)
Attachment #366490 -
Flags: review?(brendan)
Assignee | ||
Updated•16 years ago
|
Summary: Add a JS_LookupPropertyInfo → Add a JS_GetPropertyDescriptorById
Comment 7•16 years ago
|
||
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+
Assignee | ||
Comment 8•16 years ago
|
||
This is what I'll check in tomorrow.
Attachment #366496 -
Attachment is obsolete: true
Attachment #366507 -
Flags: review+
Comment 9•16 years ago
|
||
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 ).
Comment 10•16 years ago
|
||
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
Assignee | ||
Comment 11•16 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
Comment 12•16 years ago
|
||
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
Assignee | ||
Comment 13•16 years ago
|
||
Updated•16 years ago
|
Flags: in-testsuite-
Updated•16 years ago
|
Flags: blocking1.9.1?
Updated•16 years ago
|
Flags: blocking1.9.1? → blocking1.9.1+
Updated•16 years ago
|
Target Milestone: --- → mozilla1.9.1b4
Assignee | ||
Comment 14•16 years ago
|
||
http://hg.mozilla.org/releases/mozilla-1.9.1/rev/248ba0559930 and http://hg.mozilla.org/releases/mozilla-1.9.1/rev/a81ce137b944 fixed this on the 1.9 branch.
Keywords: fixed1.9.1
Comment 15•14 years ago
|
||
The documentation for this method is sadly lacking in usefulness (https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyDescriptorById).
Keywords: dev-doc-needed
Comment 16•13 years ago
|
||
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
Updated•5 years ago
|
Keywords: dev-doc-needed
You need to log in
before you can comment on or make changes to this bug.
Description
•