Merge pull request #3250 from dumganhar/develop

closed 2431: Potential crash when loading js files.
This commit is contained in:
James Chen 2013-07-25 02:59:42 -07:00
commit f40c5aa280
1 changed files with 14 additions and 1 deletions

View File

@ -80,6 +80,16 @@ static std::map<int,int> ports_sockets;
// name ~> globals
static std::map<std::string, js::RootedObject*> 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) {