It seems to me like JS_InitStandardClasses didn't make it's way into
your runtime scope. I'll share a working example for me. As far as I
can tell, the only difference is you are using EnterCompartment, after
outsourcing your global scope creation, whereas and I am using
AutoCompartment and InitStandardClasses right before defining the JS
function.
If InitStandardClasses isn't applied, that's the only reason I can
think of why something would return undefined but show the correct arg
count. Hope that helps. Try InitStandardClasses after entering the
compartment?
bool Init(runtime_t *rt) {
if (!(rt->cx = JS_NewContext(8L * 1024 * 1024)))
return 1;
if (!JS::InitSelfHostedCode(rt->cx))
return 1;
{
JSAutoRequest ar(rt->cx);
JS::CompartmentOptions options;
if(!(rt->gl = JS::PersistentRooted<JSObject*>
(rt->cx , JS_NewGlobalObject(rt->cx,
&global_class, nullptr,
JS::FireOnNewGlobalHook, options))
))
return 1;
{
JSAutoCompartment ac(rt->cx, rt->gl);
JS_InitStandardClasses(rt->cx,
rt->gl); //!!! <-- try this!
unsigned flags = JSPROP_READONLY |
JSPROP_PERMANENT;
if (!JS_DefineFunction(rt->cx, rt->gl,
"log", &stdout_log, 1, flags))
return 1;
//...
}
}
return 0;
};