Skip to content

Commit 8e365a7

Browse files
committed
refactor: replace the use of our own roundtrip StrType::getValue method with the simpler JS_EncodeStringToUTF8 SpiderMonkey API
1 parent 5a13901 commit 8e365a7

File tree

4 files changed

+4
-13
lines changed

4 files changed

+4
-13
lines changed

include/StrType.hh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public:
3636
*/
3737
static PyObject *getPyObject(JSContext *cx, JS::HandleValue str);
3838

39-
static const char *getValue(JSContext *cx, JS::HandleValue str);
40-
4139
static PyObject *proxifyString(JSContext *cx, JS::HandleValue str);
4240
};
4341

src/ExceptionType.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ JSObject *ExceptionType::toJsError(JSContext *cx, PyObject *exceptionValue, PyOb
107107
if (stackObj.get()) {
108108
JS::RootedString stackStr(cx);
109109
JS::BuildStackString(cx, nullptr, stackObj, &stackStr, 2, js::StackFormat::SpiderMonkey);
110-
JS::RootedValue stackStrVal(cx, JS::StringValue(stackStr));
111-
stackStream << "\nJS Stack Trace:\n" << StrType::getValue(cx, stackStrVal);
110+
JS::UniqueChars stackStrUtf8 = JS_EncodeStringToUTF8(cx, stackStr);
111+
stackStream << "\nJS Stack Trace:\n" << stackStrUtf8.get();
112112
}
113113

114114

src/StrType.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,3 @@ PyObject *StrType::getPyObject(JSContext *cx, JS::HandleValue str) {
212212

213213
return proxifyString(cx, str);
214214
}
215-
216-
const char *StrType::getValue(JSContext *cx, JS::HandleValue str) {
217-
PyObject *pyString = proxifyString(cx, str);
218-
const char *value = PyUnicode_AsUTF8(PyUnicode_FromObject(pyString));
219-
Py_DECREF(pyString);
220-
return value;
221-
}

src/setSpiderMonkeyException.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ PyObject *getExceptionString(JSContext *cx, const JS::ExceptionStack &exceptionS
6666
if (stackObj.get()) {
6767
JS::RootedString stackStr(cx);
6868
BuildStackString(cx, nullptr, stackObj, &stackStr, 2, js::StackFormat::SpiderMonkey);
69-
JS::RootedValue stackStrVal(cx, JS::StringValue(stackStr));
70-
outStrStream << "Stack Trace:\n" << StrType::getValue(cx, stackStrVal);
69+
JS::UniqueChars stackStrUtf8 = JS_EncodeStringToUTF8(cx, stackStr);
70+
outStrStream << "Stack Trace:\n" << stackStrUtf8.get();
7171
}
7272
}
7373

0 commit comments

Comments
 (0)