mirror of https://github.com/axmolengine/axmol.git
fixed #1811: Adding a method to get file data for JSB. Updating the way of encoding cpp string to jsval or jsval to cpp string.
This commit is contained in:
parent
4d8a735463
commit
f7e60e290f
|
@ -459,7 +459,9 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
|
|||
|
||||
js::RootedObject obj(cx, global);
|
||||
JS::CompileOptions options(cx);
|
||||
options.setUTF8(true).setFileAndLine(rpath.c_str(), 1);
|
||||
options.setFileAndLine(rpath.c_str(), 1);
|
||||
// Don't setUTF8 since it will cause messy string output by cc.log .
|
||||
// options.setUTF8(true).setFileAndLine(rpath.c_str(), 1);
|
||||
|
||||
// this will always compile the script, we can actually check if the script
|
||||
// was compiled before, because it can be in the global map
|
||||
|
@ -1622,13 +1624,7 @@ JSBool JSBDebug_BufferWrite(JSContext* cx, unsigned argc, jsval* vp)
|
|||
{
|
||||
if (argc == 1) {
|
||||
jsval* argv = JS_ARGV(cx, vp);
|
||||
const char* str;
|
||||
|
||||
JSString* jsstr = JS_ValueToString(cx, argv[0]);
|
||||
// Not supported in SpiderMonkey v19
|
||||
//str = JS_EncodeString(cx, jsstr);
|
||||
JSStringWrapper strWrapper(jsstr);
|
||||
|
||||
JSStringWrapper strWrapper(argv[0]);
|
||||
// this is safe because we're already inside a lock (from clearBuffers)
|
||||
outData.append(strWrapper.get());
|
||||
}
|
||||
|
|
|
@ -267,8 +267,7 @@ public:
|
|||
}
|
||||
~JSStringWrapper() {
|
||||
if (buffer) {
|
||||
// JS_free(ScriptingCore::getInstance()->getGlobalContext(), (void*)buffer);
|
||||
CC_SAFE_DELETE_ARRAY(buffer);
|
||||
JS_free(ScriptingCore::getInstance()->getGlobalContext(), (void*)buffer);
|
||||
}
|
||||
}
|
||||
void set(jsval val, JSContext* cx) {
|
||||
|
@ -283,14 +282,7 @@ public:
|
|||
if (!cx) {
|
||||
cx = ScriptingCore::getInstance()->getGlobalContext();
|
||||
}
|
||||
// Not suppored in SpiderMonkey v19
|
||||
//buffer = JS_EncodeString(cx, string);
|
||||
|
||||
const jschar *chars = JS_GetStringCharsZ(cx, string);
|
||||
size_t l = JS_GetStringLength(string);
|
||||
char* pUTF8Str = cc_utf16_to_utf8((const unsigned short*)chars, l, NULL, NULL);
|
||||
buffer = pUTF8Str;
|
||||
|
||||
buffer = JS_EncodeString(cx, string);
|
||||
}
|
||||
std::string get() {
|
||||
return buffer;
|
||||
|
|
|
@ -1 +1 @@
|
|||
e4b7d86461a17a555283bbc28cba2ab48cab21cd
|
||||
c12cdcc2ffa853b5b702ed1347279ff7fa076974
|
|
@ -80,12 +80,8 @@ JSBool JSBCore_log(JSContext *cx, uint32_t argc, jsval *vp)
|
|||
JSString *string = NULL;
|
||||
JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &string);
|
||||
if (string) {
|
||||
// Not supported in SpiderMonkey v19
|
||||
//char *cstr = JS_EncodeString(cx, string);
|
||||
const jschar *chars = JS_GetStringCharsZ(cx, string);
|
||||
size_t l = JS_GetStringLength(string);
|
||||
char* pUTF8Str = cc_utf16_to_utf8((const unsigned short*)chars, l, NULL, NULL);
|
||||
CCLOG(pUTF8Str);
|
||||
JSAutoByteString log_str(cx, string);
|
||||
CCLOG(log_str.ptr());
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
|
|
|
@ -199,8 +199,6 @@ JSBool jsval_to_charptr( JSContext *cx, jsval vp, const char **ret )
|
|||
// root it
|
||||
vp = STRING_TO_JSVAL(jsstr);
|
||||
|
||||
// Not supported in SpiderMonkey v19
|
||||
//char *ptr = JS_EncodeString(cx, jsstr);
|
||||
JSStringWrapper strWrapper(jsstr);
|
||||
|
||||
// XXX: It is converted to CCString and then back to char* to autorelease the created object.
|
||||
|
|
Loading…
Reference in New Issue