Merge pull request #1482 from funkaster/gles20

fixed #1517: fixes ScriptingCore for FF 16 API.
This commit is contained in:
James Chen 2012-10-19 18:28:15 -07:00
commit 6e86889338
1 changed files with 68 additions and 64 deletions

View File

@ -367,6 +367,7 @@ JSBool ScriptingCore::evalString(const char *string, jsval *outVal, const char *
if (JS_FALSE == evaluatedOK) {
fprintf(stderr, "(evaluatedOK == JS_FALSE)\n");
}
ac.leave();
return evaluatedOK;
}
return false;
@ -437,29 +438,30 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
if (cx == NULL) {
cx = cx_;
}
// this will always compile the script, we can actually check if the script
// was compiled before, because it can be in the global map
// We can't use this function on android since all the sources are packed into apk file.
// JSScript* script = JS_CompileUTF8File(cx, global, rpath.c_str());
#ifdef ANDROID
unsigned char *content = NULL;
unsigned long contentSize = 0;
content = (unsigned char*)CCString::createWithContentsOfFile(rpath.c_str())->getCString();
contentSize = strlen((char*)content);
JSScript* script = JS_CompileScript(cx, global, (char*)content, contentSize, "noname", 1);
JSScript* script = JS_CompileScript(cx, global, (char*)content, contentSize, path, 1);
#else
JSScript* script = JS_CompileUTF8File(cx, global, rpath.c_str());
#endif
JSBool evaluatedOK = false;
if (script) {
jsval rval;
filename_script[path] = script;
// JSAutoCompartment ac(cx, global);
JSAutoEnterCompartment ac;
ac.enter(cx, global);
evaluatedOK = JS_ExecuteScript(cx, global, script, &rval);
if (JS_FALSE == evaluatedOK) {
fprintf(stderr, "(evaluatedOK == JS_FALSE)\n");
}
ac.leave();
}
return evaluatedOK;
}
@ -1118,14 +1120,16 @@ JSObject* NewGlobalObject(JSContext* cx)
if (!glob) {
return NULL;
}
//JSAutoCompartment ac(cx, glob);
JSAutoEnterCompartment ac;
ac.enter(cx, glob);
if (!JS_InitStandardClasses(cx, glob))
return NULL;
if (!JS_InitReflect(cx, glob))
return NULL;
if (!JS_DefineDebuggerObject(cx, glob))
JSBool ok = JS_TRUE;
ok = JS_InitStandardClasses(cx, glob);
if (ok)
JS_InitReflect(cx, glob);
if (ok)
ok = JS_DefineDebuggerObject(cx, glob);
ac.leave();
if (!ok)
return NULL;
return glob;