Assertion failure on debug, what is wrong?
Mihai Dobrescu <[email protected]> Sat, 27 Aug 2016 02:06:50 -0700 (PDT)
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I've compiled SpiderMonkey 45 against mingw with debug activated.
I have the following error at runtime in my test project, under Windows:
Assertion failure: stackRoots_[i] == nullptr
The code looks like this:
// The class of the global object.
static JSClass global_class = {
"global",
JSCLASS_GLOBAL_FLAGS,
0, //JSAddPropertyOp
0, //JSDeletePropertyOp
0, //JSGetterOp
0, //JSSetterOp
0, //JSEnumerateOp
0, //JSResolveOp
0, //JSMayResolveOp
0, //FinalizeOpType
0, //JSNative
0, //JSHasInstanceOp
0, //JSNative
JS_GlobalObjectTraceHook, //JSTraceOp <-- this is to avoid another assertion failure
};
int main(int argc, const char *argv[])
{
JS::RootedObject *global;
JS_Init();
JSRuntime *rt = JS_NewRuntime(8L * 1024 * 1024);
if (!rt)
return 1;
/*JSErrorReporter er = */JS_SetErrorReporter(rt, &dispatchError);
JSContext *cx = JS_NewContext(rt, 8192);
if (!cx)
return 1;
// Scope for our various stack objects (JSAutoRequest, RootedObject), so they all go
// out of scope before we JS_DestroyContext.
{
JSAutoRequest ar(cx); // In practice, you would want to exit this any
// time you're spinning the event loop
//JS::RootedObject global(cx, JS_NewGlobalObject(cx, &global_class, nullptr, JS::FireOnNewGlobalHook));
global = new JS::RootedObject(cx, JS_NewGlobalObject(cx, &global_class, nullptr, JS::FireOnNewGlobalHook));
if (!global)
return 1;
JS::RootedValue rval(cx);
// Scope for JSAutoCompartment
{
JSAutoCompartment ac(cx, *global);
JS_InitStandardClasses(cx, *global);
//ok = JS_DefineFunction(cx, global, "doit", doit, 2, 0);
/*bool ok = JS_DefineFunctions(cx, *global, my_functions);
if (!ok)
return 1;*/
JSObject *fProtoObj = JS_InitClass(cx, *global, nullptr, &test_class,
/*class_construct*/ NULL, 0,
NULL, test_class_functions, NULL, NULL);
if (!fProtoObj)
return 1;
jsClass::DefineClasses(cx, *global);
//const char *script = "var x = 'hello' + 'world, it is ' + new Date(); y = doit(2, 3); x + '\\n' + String(y); ";
//const char *script = "var x = 'hello' + 'world, it is ' + new Date(); y = doit(2, 3); x + '\\n' + String(y);";
//const char *script = "var x = 'hello' + 'world, it is ' + new Date(); y = TestClass.doit(2, 3); x + '\\n' + String(y);";
//const char *script = "var r = new AIRealPoint(1, 1); String(r.h);";
const char *script = "var r = 2.2; r.toString();";
//
// const char *script = "/*\
//var abruzzi = new person();\
// abruzzi.name = \"abruzzi\";\
// abruzzi.address = \"Huang Quan Road\";\
// */\
//\
// //undefined of course\
// person.print();\
//\
// //person.name = \"abruzzi\";\
// //person.address = \"Huang Quan Road\";\
//\
// person.setName(\"abruzzi\");\
// person.setAddress(\"HuangQuan Road\");\
//\
// person.print();\
//\
// (function() {\
// return person.getName() + \" : \" + person.getAddress();\
// })();\
// ";
const char *filename = "noname";
int lineno = 1;
JS::CompileOptions opts(cx);
opts.setFileAndLine(filename, lineno);
bool ok = JS::Evaluate(cx/*, *global*/, opts, script, strlen(script), &rval);
if (!ok)
return 1;
}
if (rval.isString())
{
JSString *str = rval.toString();
if (str)
printf("%s\n", JS_EncodeString(cx, str));
}
}
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
JS_ShutDown();
global = NULL;
wait();
return 0;
}
What did I do wrong?
Thank you.