diff --git a/scripting/javascript/bindings/ScriptingCore.cpp b/scripting/javascript/bindings/ScriptingCore.cpp index fd6b1fa55e..02c27faf13 100644 --- a/scripting/javascript/bindings/ScriptingCore.cpp +++ b/scripting/javascript/bindings/ScriptingCore.cpp @@ -80,6 +80,16 @@ static std::map ports_sockets; // name ~> globals static std::map globals; + +static void ReportException(JSContext *cx) +{ + if (JS_IsExceptionPending(cx)) { + if (!JS_ReportPendingException(cx)) { + JS_ClearPendingException(cx); + } + } +} + static void executeJSFunctionFromReservedSpot(JSContext *cx, JSObject *obj, jsval &dataVal, jsval &retval) { @@ -487,7 +497,7 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c JS::CompileOptions options(cx); options.setUTF8(true).setFileAndLine(fullPath.c_str(), 1); - // a) check js file first + // a) check jsc file first std::string byteCodePath = RemoveFileExt(std::string(path)) + BYTE_CODE_FILE_EXT; unsigned long length = 0; void *data = futil->getFileData(byteCodePath.c_str(), @@ -499,6 +509,9 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c // b) no jsc file, check js file if (!script) { + /* Clear any pending exception from previous failed decoding. */ + ReportException(cx); + #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) String* content = String::createWithContentsOfFile(path); if (content) {