Skip to content

Commit de44cf7

Browse files
committed
refactor(PyProxyHandler): idToKey handle property key string by copying
1 parent 526a8b7 commit de44cf7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/PyProxyHandler.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@
2424

2525
PyObject *idToKey(JSContext *cx, JS::HandleId id) {
2626
JS::RootedValue idv(cx, js::IdToValue(id));
27-
JSString *idStr;
27+
JS::RootedString idStr(cx);
2828
if (!id.isSymbol()) { // `JS::ToString` returns `nullptr` for JS symbols
2929
idStr = JS::ToString(cx, idv);
3030
} else {
3131
// TODO (Tom Tang): Revisit this once we have Symbol coercion support
3232
// FIXME (Tom Tang): key collision for symbols without a description string, or pure strings look like "Symbol(xxx)"
3333
idStr = JS_ValueToSource(cx, idv);
3434
}
35+
3536
// We convert all types of property keys to string
36-
return StrType(cx, idStr).getPyObject();
37+
auto chars = JS_EncodeStringToUTF8(cx, idStr);
38+
return PyUnicode_FromString(chars.get());
3739
}
3840

3941
bool idToIndex(JSContext *cx, JS::HandleId id, Py_ssize_t *index) {

0 commit comments

Comments
 (0)