This sample program shows the issue:
http://gist.github.com/107056
Any help would be appreciated.
-Eliot
Eliot came on IRC to ask about this. The problem is confusion between the
class' constructor (passed into JS_InitClass) and the JSClass hook
'construct'.
For reference, the constructor function passed into JS_InitClass tells
SpiderMonkey to expose a function object named the same as the passed-in
class' name member and whose .prototype property is the class prototype (the
same one returned by JS_InitClass). If constructor is null, then the property
that is defined is the prototype object itself.
In contrast the class hook is called when someone attempts to construct an
instantiation of the given object. That is, given:
JSBool
construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
printf("In construct\n");
return JS_TRUE;
}
static JSClass clazz = {
"mine", 0,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
NULL, NULL, NULL, construct, NULL, NULL, NULL, NULL
};
JSBool
class_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
printf("In class_construct\n");
return JS_TRUE;
}
JS_InitClass(cx, global, NULL, &clazz, class_construct,
0, NULL, NULL, NULL, NULL);
Then evaluating the JS:
m = new mine();
new m();
should output:
In class_construct
In construct
--
Blake Kaplan