Merge branch 'gles20' of https://github.com/funkaster/cocos2d-x into js-surith-gnu

This commit is contained in:
James Chen 2012-10-31 10:04:35 +08:00
commit bdbb70bea5
1 changed files with 8 additions and 12 deletions

View File

@ -55,18 +55,17 @@ std::map<std::string, js::RootedObject*> globals;
static void executeJSFunctionFromReservedSpot(JSContext *cx, JSObject *obj, static void executeJSFunctionFromReservedSpot(JSContext *cx, JSObject *obj,
jsval &dataVal, jsval &retval) { jsval &dataVal, jsval &retval) {
// if(p->jsclass->JSCLASS_HAS_RESERVED_SLOTS(1)) {
jsval func = JS_GetReservedSlot(obj, 0); jsval func = JS_GetReservedSlot(obj, 0);
if(func == JSVAL_VOID) { return; } if(func == JSVAL_VOID) { return; }
jsval thisObj = JS_GetReservedSlot(obj, 1); jsval thisObj = JS_GetReservedSlot(obj, 1);
JSAutoCompartment ac(cx, obj);
if(thisObj == JSVAL_VOID) { if(thisObj == JSVAL_VOID) {
JS_CallFunctionValue(cx, obj, func, 1, &dataVal, &retval); JS_CallFunctionValue(cx, obj, func, 1, &dataVal, &retval);
} else { } else {
assert(!JSVAL_IS_PRIMITIVE(thisObj)); assert(!JSVAL_IS_PRIMITIVE(thisObj));
JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(thisObj), func, 1, &dataVal, &retval); JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(thisObj), func, 1, &dataVal, &retval);
} }
// }
} }
static void getTouchesFuncName(int eventType, std::string &funcName) { static void getTouchesFuncName(int eventType, std::string &funcName) {
@ -163,6 +162,7 @@ static void executeJSFunctionWithName(JSContext *cx, JSObject *obj,
if(temp_retval == JSVAL_VOID) { if(temp_retval == JSVAL_VOID) {
return; return;
} }
JSAutoCompartment ac(cx, obj);
JS_CallFunctionName(cx, obj, funcName, JS_CallFunctionName(cx, obj, funcName,
1, &dataVal, &retval); 1, &dataVal, &retval);
} }
@ -361,13 +361,11 @@ JSBool ScriptingCore::evalString(const char *string, jsval *outVal, const char *
JSScript* script = JS_CompileScript(cx, global, string, strlen(string), filename, 1); JSScript* script = JS_CompileScript(cx, global, string, strlen(string), filename, 1);
if (script) { if (script) {
// JSAutoCompartment ac(cx, global); // JSAutoCompartment ac(cx, global);
JSAutoEnterCompartment ac; JSAutoCompartment ac(cx, global);
ac.enter(cx, global); JSBool evaluatedOK = JS_ExecuteScript(cx, global, script, &rval);
JSBool evaluatedOK = JS_ExecuteScript(cx_, global_, script, &rval);
if (JS_FALSE == evaluatedOK) { if (JS_FALSE == evaluatedOK) {
fprintf(stderr, "(evaluatedOK == JS_FALSE)\n"); fprintf(stderr, "(evaluatedOK == JS_FALSE)\n");
} }
ac.leave();
return evaluatedOK; return evaluatedOK;
} }
return false; return false;
@ -406,6 +404,7 @@ void ScriptingCore::createGlobalContext() {
this->cx_ = NULL; this->cx_ = NULL;
this->rt_ = NULL; this->rt_ = NULL;
} }
JS_SetCStringsAreUTF8();
this->rt_ = JS_NewRuntime(10 * 1024 * 1024); this->rt_ = JS_NewRuntime(10 * 1024 * 1024);
this->cx_ = JS_NewContext(rt_, 10240); this->cx_ = JS_NewContext(rt_, 10240);
JS_SetOptions(this->cx_, JSOPTION_TYPE_INFERENCE); JS_SetOptions(this->cx_, JSOPTION_TYPE_INFERENCE);
@ -455,13 +454,11 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
if (script) { if (script) {
jsval rval; jsval rval;
filename_script[path] = script; filename_script[path] = script;
JSAutoEnterCompartment ac; JSAutoCompartment ac(cx, global);
ac.enter(cx, global);
evaluatedOK = JS_ExecuteScript(cx, global, script, &rval); evaluatedOK = JS_ExecuteScript(cx, global, script, &rval);
if (JS_FALSE == evaluatedOK) { if (JS_FALSE == evaluatedOK) {
fprintf(stderr, "(evaluatedOK == JS_FALSE)\n"); fprintf(stderr, "(evaluatedOK == JS_FALSE)\n");
} }
ac.leave();
} }
return evaluatedOK; return evaluatedOK;
} }
@ -1145,15 +1142,13 @@ JSObject* NewGlobalObject(JSContext* cx)
if (!glob) { if (!glob) {
return NULL; return NULL;
} }
JSAutoEnterCompartment ac; JSAutoCompartment ac(cx, glob);
ac.enter(cx, glob);
JSBool ok = JS_TRUE; JSBool ok = JS_TRUE;
ok = JS_InitStandardClasses(cx, glob); ok = JS_InitStandardClasses(cx, glob);
if (ok) if (ok)
JS_InitReflect(cx, glob); JS_InitReflect(cx, glob);
if (ok) if (ok)
ok = JS_DefineDebuggerObject(cx, glob); ok = JS_DefineDebuggerObject(cx, glob);
ac.leave();
if (!ok) if (!ok)
return NULL; return NULL;
@ -1173,6 +1168,7 @@ JSBool jsNewGlobal(JSContext* cx, unsigned argc, jsval* vp)
JS_WrapObject(cx, global->address()); JS_WrapObject(cx, global->address());
globals[key] = global; globals[key] = global;
// register everything on the list on this new global object // register everything on the list on this new global object
JSAutoCompartment ac(cx, g);
for (std::vector<sc_register_sth>::iterator it = registrationList.begin(); it != registrationList.end(); it++) { for (std::vector<sc_register_sth>::iterator it = registrationList.begin(); it != registrationList.end(); it++) {
sc_register_sth callback = *it; sc_register_sth callback = *it;
callback(cx, g); callback(cx, g);