The default bug view has changed. See this FAQ.

Drop cx argument from JS_GetClass(cx, obj)

RESOLVED FIXED in mozilla13



JavaScript Engine
5 years ago
5 years ago


(Reporter: Igor Bukanov, Assigned: Igor Bukanov)




Firefox Tracking Flags

(Not tracked)



(1 attachment)



5 years ago
Currently we declare JS_GetClass in jsapi.cpp as:

extern JS_PUBLIC_API(JSClass *)
JS_GetClass(JSContext *cx, JSObject *obj);

#define JS_GET_CLASS(cx,obj) JS_GetClass(cx, obj)
extern JS_PUBLIC_API(JSClass *)
JS_GetClass(JSObject *obj);

#define JS_GET_CLASS(cx,obj) JS_GetClass(obj)

The reason for the cx argument under is JS_THREADSAFE is that when JS_THREADSAFE were introduced to the JS engine, JSObject did not have fixed slots. So the class pointer were stored in the dynamic slots. However, with thread-shared objects, the slot array could have been reallocated when accessing the object. So it was necessary to synchronize the access to the slot array using the request machinery and the cx argument allowed for that.

I suppose the cx argument should have been removed from JS_GetClass right after introduction of fat objects, but is better late then never.

Comment 1

5 years ago
Agreed.  We have also stopped enforcing strict source compatibility (as long as there is an obvious transition path), so I'd be in favor of removing the JS_GET_CLASS macro altogether.

Comment 2

5 years ago
Created attachment 594306 [details] [diff] [review]

The patch drops the cx parameter from JS_GetClass and removes JS_GET_CLASS macro. 

Besides mechanical renaming JS_GET_CLASS into JS_GetClass the patch also propagated removal of the cx argument from the JS_GetClass callers when JS_GET_CLASS was the sole reason to pass the cx.
Attachment #594306 - Flags: review?(luke)


5 years ago
Attachment #594306 - Flags: review?(luke) → review+

Comment 3

5 years ago
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla13

Comment 5

5 years ago
We need to update the documentation that JS_GET_CLASS(JSContext *cx, JSObject *obj) was removed and the code should call JS_GetClass(JSObject *obj) instead.
Keywords: dev-doc-needed

Comment 6

5 years ago
By mistake I landed the patch for the bug 724310 with the commit message that refers to this  bug.
I split JS_GET_CLASS docs into that and one for the method, and I updated both to the current trunk state, also updating links to them to use JS_GetClass.

The JSAPI reference overview now marks the macro as obsolete, and it links to both the macro and the method for completeness and backwards-usability.

Also, the 1.8.8 release notes mention that JS_GetClass's signature changed and that JS_GET_CLASS was removed.
Keywords: dev-doc-needed → dev-doc-complete
OS: Linux → All
Hardware: x86_64 → All
Summary: Drop cx argumrent from JS_GetClass(cx, obj) → Drop cx argument from JS_GetClass(cx, obj)
You need to log in before you can comment on or make changes to this bug.