mirror of https://github.com/axmolengine/axmol.git
Changed byte code file ext to ".jsc"
Modified loading logic to load js file first
This commit is contained in:
parent
077214c419
commit
de27f1137a
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
#include "js_bindings_config.h"
|
#include "js_bindings_config.h"
|
||||||
|
|
||||||
#define BYTE_CODE_SUFFIX ".bc"
|
#define BYTE_CODE_FILE_EXT ".jsc"
|
||||||
|
|
||||||
pthread_t debugThread;
|
pthread_t debugThread;
|
||||||
string inData;
|
string inData;
|
||||||
|
@ -446,12 +446,22 @@ void ScriptingCore::createGlobalContext() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TransScriptPath(const std::string& path) {
|
std::string TransFilePath(const std::string& filePath) {
|
||||||
if (path.c_str()[0] == '/') {
|
if (filePath.c_str()[0] == '/') {
|
||||||
return path;
|
return filePath;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str());
|
return cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(filePath.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RemoveFileExt(const std::string& filePath) {
|
||||||
|
size_t pos = filePath.rfind('.');
|
||||||
|
if (0 < pos) {
|
||||||
|
return filePath.substr(0, pos);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return filePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,8 +471,7 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cocos2d::CCFileUtils *futil = cocos2d::CCFileUtils::sharedFileUtils();
|
cocos2d::CCFileUtils *futil = cocos2d::CCFileUtils::sharedFileUtils();
|
||||||
std::string rpath = TransScriptPath(path);
|
std::string rpath = TransFilePath(path);
|
||||||
std::string bcPath = TransScriptPath(std::string(path) + BYTE_CODE_SUFFIX);
|
|
||||||
if (global == NULL) {
|
if (global == NULL) {
|
||||||
global = global_;
|
global = global_;
|
||||||
}
|
}
|
||||||
|
@ -474,19 +483,7 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
|
||||||
JS::CompileOptions options(cx);
|
JS::CompileOptions options(cx);
|
||||||
options.setUTF8(true).setFileAndLine(rpath.c_str(), 1);
|
options.setUTF8(true).setFileAndLine(rpath.c_str(), 1);
|
||||||
|
|
||||||
// this will always compile the script, we can actually check if the script
|
// a) check js file first
|
||||||
// was compiled before, because it can be in the global map
|
|
||||||
unsigned long length = 0;
|
|
||||||
// Removed in SpiderMonkey 19.0
|
|
||||||
//JSScript* script = JS_CompileUTF8File(cx, global, rpath.c_str());
|
|
||||||
bool notify = futil->isPopupNotify();
|
|
||||||
futil->setPopupNotify(false);
|
|
||||||
void *data = futil->getFileData(bcPath.c_str(), "rb", &length);
|
|
||||||
futil->setPopupNotify(notify);
|
|
||||||
if (data) {
|
|
||||||
script = JS_DecodeScript(cx, data, length, NULL, NULL);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||||
unsigned char *content = (unsigned char*)CCString::createWithContentsOfFile(rpath.c_str())->getCString();
|
unsigned char *content = (unsigned char*)CCString::createWithContentsOfFile(rpath.c_str())->getCString();
|
||||||
if (content) {
|
if (content) {
|
||||||
|
@ -497,6 +494,16 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
|
||||||
#else
|
#else
|
||||||
script = JS::Compile(cx, obj, options, rpath.c_str());
|
script = JS::Compile(cx, obj, options, rpath.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
// b) no js file, check jsc file
|
||||||
|
if (!script) {
|
||||||
|
std::string byteCodeFilePath = TransFilePath(RemoveFileExt(std::string(path)) + BYTE_CODE_FILE_EXT);
|
||||||
|
unsigned long length = 0;
|
||||||
|
// Removed in SpiderMonkey 19.0
|
||||||
|
//JSScript* script = JS_CompileUTF8File(cx, global, rpath.c_str());
|
||||||
|
void *data = futil->getFileData(byteCodeFilePath.c_str(), "rb", &length);
|
||||||
|
if (data) {
|
||||||
|
script = JS_DecodeScript(cx, data, length, NULL, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
JSBool evaluatedOK = false;
|
JSBool evaluatedOK = false;
|
||||||
if (script) {
|
if (script) {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
const char *USAGE = "Usage: jsbcc input_js_file [byte_code_file]\n"\
|
const char *USAGE = "Usage: jsbcc input_js_file [byte_code_file]\n"\
|
||||||
" Pipe supported";
|
" Pipe supported";
|
||||||
const char *BYTE_CODE_FILE_SUFFIX = ".bc";
|
const char *BYTE_CODE_FILE_EXT = ".jsc";
|
||||||
|
|
||||||
enum ErrorCode {
|
enum ErrorCode {
|
||||||
EC_OK = 0,
|
EC_OK = 0,
|
||||||
|
@ -49,6 +49,17 @@ bool WriteFile(const std::string &filePath, void *data, uint32_t length) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string RemoveFileExt(const std::string &filePath) {
|
||||||
|
size_t pos = filePath.rfind('.');
|
||||||
|
if (0 < pos) {
|
||||||
|
return filePath.substr(0, pos);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CompileFile(const std::string &inputFilePath, const std::string &outputFilePath) {
|
bool CompileFile(const std::string &inputFilePath, const std::string &outputFilePath) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
std::string ofp;
|
std::string ofp;
|
||||||
|
@ -56,7 +67,7 @@ bool CompileFile(const std::string &inputFilePath, const std::string &outputFile
|
||||||
ofp = outputFilePath;
|
ofp = outputFilePath;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ofp = inputFilePath + BYTE_CODE_FILE_SUFFIX;
|
ofp = RemoveFileExt(inputFilePath) + BYTE_CODE_FILE_EXT;
|
||||||
}
|
}
|
||||||
std::cout << "Input file: " << inputFilePath << std::endl;
|
std::cout << "Input file: " << inputFilePath << std::endl;
|
||||||
JSRuntime * runtime = JS_NewRuntime(10 * 1024 * 1024, JS_NO_HELPER_THREADS);
|
JSRuntime * runtime = JS_NewRuntime(10 * 1024 * 1024, JS_NO_HELPER_THREADS);
|
||||||
|
|
Loading…
Reference in New Issue