mirror of https://github.com/axmolengine/axmol.git
Merge pull request #14670 from pandamicro/v3
Fix evalString doesn't return result issue
This commit is contained in:
commit
0e7a02d025
|
@ -500,16 +500,21 @@ void ScriptingCore::string_report(JS::HandleValue val) {
|
|||
}
|
||||
}
|
||||
|
||||
bool ScriptingCore::evalString(const char *string, jsval *outVal, const char *filename, JSContext* cx, JSObject* global)
|
||||
bool ScriptingCore::evalString(const char *string, JS::MutableHandleValue outVal, const char *filename, JSContext* cx, JS::HandleObject global)
|
||||
{
|
||||
if (cx == NULL)
|
||||
cx = _cx;
|
||||
if (global == NULL)
|
||||
global = _global.ref().get();
|
||||
|
||||
JSAutoCompartment ac(cx, global);
|
||||
JS::RootedObject jsglobal(cx, global);
|
||||
return JS_EvaluateScript(cx, jsglobal, string, (unsigned)strlen(string), "ScriptingCore::evalString", 1);
|
||||
return JS_EvaluateScript(cx, global, string, (unsigned)strlen(string), "ScriptingCore::evalString", 1, outVal);
|
||||
}
|
||||
|
||||
bool ScriptingCore::evalString(const char *string, JS::MutableHandleValue outVal)
|
||||
{
|
||||
return evalString(string, outVal, nullptr, _cx, _global.ref());
|
||||
}
|
||||
|
||||
bool ScriptingCore::evalString(const char *string)
|
||||
{
|
||||
JS::RootedValue retVal(_cx);
|
||||
return evalString(string, &retVal);
|
||||
}
|
||||
|
||||
void ScriptingCore::start()
|
||||
|
|
|
@ -234,7 +234,22 @@ public:
|
|||
* @param global @~english The js global object
|
||||
* @return @~english Return true if successfully invoked, otherwise return false.
|
||||
*/
|
||||
bool evalString(const char *string, jsval *outVal, const char *filename = NULL, JSContext* cx = NULL, JSObject* global = NULL);
|
||||
bool evalString(const char *string, JS::MutableHandleValue outVal, const char *filename, JSContext* cx, JS::HandleObject global);
|
||||
|
||||
/**@~english
|
||||
* Evaluate the specified js code string
|
||||
* @param string @~english The string with the javascript code to be evaluated
|
||||
* @param outVal @~english The jsval that will hold the return value of the evaluation.
|
||||
* @return @~english Return true if successfully invoked, otherwise return false.
|
||||
*/
|
||||
bool evalString(const char *string, JS::MutableHandleValue outVal);
|
||||
|
||||
/**@~english
|
||||
* Evaluate the specified js code string
|
||||
* @param string @~english The string with the javascript code to be evaluated
|
||||
* @return @~english Return true if successfully invoked, otherwise return false.
|
||||
*/
|
||||
bool evalString(const char *string);
|
||||
|
||||
/**
|
||||
@brief @~english Get script object for the given path
|
||||
|
|
|
@ -46,7 +46,7 @@ JNIEXPORT jint JNICALL Java_org_cocos2dx_lib_Cocos2dxJavascriptJavaBridge_evalSt
|
|||
CCLOG("Cocos2dxJavascriptJavaBridge_evalString error, invalid string code");
|
||||
return 0;
|
||||
}
|
||||
ScriptingCore::getInstance()->evalString(strValue.c_str(), nullptr);
|
||||
ScriptingCore::getInstance()->evalString(strValue.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue