Commit c30315cf authored by Michael Droettboom's avatar Michael Droettboom

Avoid using UTF8ToString

The only places we were using it was for strings that are ASCII anyway,
so this is both more efficient and avoids this Chrome bug:

https://bugs.chromium.org/p/chromium/issues/detail?id=868404
parent 79c97f8d
...@@ -67,6 +67,15 @@ EM_JS(int, hiwire_string_utf8, (int ptr), { ...@@ -67,6 +67,15 @@ EM_JS(int, hiwire_string_utf8, (int ptr), {
return Module.hiwire_new_value(UTF8ToString(ptr)); return Module.hiwire_new_value(UTF8ToString(ptr));
}); });
EM_JS(int, hiwire_string_ascii, (int ptr), {
var jsstr = "";
var idx = ptr;
for (var idx = ptr; Module.HEAPU8[idx] != 0; ++idx) {
jsstr += String.fromCharCode(Module.HEAPU8[idx]);
}
return Module.hiwire_new_value(jsstr);
});
EM_JS(int, hiwire_bytes, (int ptr, int len), { EM_JS(int, hiwire_bytes, (int ptr, int len), {
var bytes = new Uint8ClampedArray(Module.HEAPU8.buffer, ptr, len); var bytes = new Uint8ClampedArray(Module.HEAPU8.buffer, ptr, len);
return Module.hiwire_new_value(bytes); return Module.hiwire_new_value(bytes);
......
...@@ -86,6 +86,16 @@ hiwire_string_ucs1(int ptr, int len); ...@@ -86,6 +86,16 @@ hiwire_string_ucs1(int ptr, int len);
int int
hiwire_string_utf8(int ptr); hiwire_string_utf8(int ptr);
/**
* Create a new Javascript string, given a pointer to a null-terminated buffer
* containing ascii (well, technically latin-1). The string data itself is
* copied.
*
* Returns: New reference
*/
int
hiwire_string_ascii(int ptr);
/** /**
* Create a new Javascript Uint8ClampedArray, given a pointer to a buffer and a * Create a new Javascript Uint8ClampedArray, given a pointer to a buffer and a
* length, in bytes. * length, in bytes.
......
...@@ -21,7 +21,7 @@ pythonexc2js() ...@@ -21,7 +21,7 @@ pythonexc2js()
int exc; int exc;
if (type == NULL || type == Py_None || value == NULL || value == Py_None) { if (type == NULL || type == Py_None || value == NULL || value == Py_None) {
excval = hiwire_string_utf8((int)"No exception type or value"); excval = hiwire_string_ascii((int)"No exception type or value");
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
goto exit; goto exit;
...@@ -31,7 +31,7 @@ pythonexc2js() ...@@ -31,7 +31,7 @@ pythonexc2js()
if (tbmod == NULL) { if (tbmod == NULL) {
PyObject* repr = PyObject_Repr(value); PyObject* repr = PyObject_Repr(value);
if (repr == NULL) { if (repr == NULL) {
excval = hiwire_string_utf8((int)"Could not get repr for exception"); excval = hiwire_string_ascii((int)"Could not get repr for exception");
} else { } else {
excval = python2js(repr); excval = python2js(repr);
Py_DECREF(repr); Py_DECREF(repr);
...@@ -46,7 +46,7 @@ pythonexc2js() ...@@ -46,7 +46,7 @@ pythonexc2js()
} }
if (format_exception == NULL) { if (format_exception == NULL) {
excval = excval =
hiwire_string_utf8((int)"Could not get format_exception function"); hiwire_string_ascii((int)"Could not get format_exception function");
} else { } else {
PyObject* pylines; PyObject* pylines;
if (no_traceback) { if (no_traceback) {
...@@ -58,7 +58,7 @@ pythonexc2js() ...@@ -58,7 +58,7 @@ pythonexc2js()
} }
if (pylines == NULL) { if (pylines == NULL) {
excval = excval =
hiwire_string_utf8((int)"Error calling traceback.format_exception"); hiwire_string_ascii((int)"Error calling traceback.format_exception");
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
goto exit; goto exit;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment