Closed
Bug 712608
Opened 13 years ago
Closed 1 year ago
need an API to get the JSClass* of standard classes
Categories
(Core :: JavaScript Engine, enhancement)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
People
(Reporter: soubok, Unassigned)
Details
I previously used JS_GetClassObject() then FUN_CLASP(GET_FUNCTION_PRIVATE(cx, ctor) but since these macros has been removed and js::Class *getConstructorClass() is not public, I cannot replace my code.
My function looked like this:
JSClass* GetStandardClassByProtoKey(JSContext *cx, JSProtoKey protoKey) {
return JS_GetClassObject(cx, JS_GetGlobalObject(cx), protoKey, &ctor) && ctor ? js::Jsvalify(FUN_CLASP(GET_FUNCTION_PRIVATE(cx, ctor))) : NULL;
}
![]() |
||
Comment 2•13 years ago
|
||
I believe the JSClass* of engine-created objects is an implementation detail and should not be relied upon. Off the top of my head, there are two ways this breaks at the moment (dense/sparse arrays have different classes, transparent compartment wrappers inject a Proxy) and I would not be surprised if there are more or will be more in the future.
Would it work instead to have a predicate:
JSBool JS_ObjectClassIs(JSContext *cx, JSObject *obj, JSProtoKey protoKey);
?
Yes, it will work in almost all my cases. I mainly used GetStandardClassByProtoKey to check if an object is a Number, a Date, a Boolean, ...
However I have one case where GetStandardClassByProtoKey helps me to create an error of a given type:
CreateErrorException( JSContext *cx, JSExnType exn, JSObject **obj )
But it is maybe the topic for another bug.
Comment 4•13 years ago
|
||
Probably we should add JS_IsNumberObject APIs and similar, then, the way we've done so for Array and RegExp.
We should have a JS_CreateErrorObject(..., JSExnType, ...) method. It shouldn't be necessary to use hackarounds to do that.
Assignee | ||
Updated•11 years ago
|
Assignee: general → nobody
Updated•2 years ago
|
Severity: normal → S3
Comment 5•1 year ago
|
||
GetBuiltinClass() seems to be what :Franck is looking for.
Giving the existence of GetBuiltinClass()
and the age of the bug, I'm going to close this bug.
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•