MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / idToKey

Function idToKey

src/PyBaseProxyHandler.cc:19–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18
19PyObject *idToKey(JSContext *cx, JS::HandleId id) {
20 JS::RootedValue idv(cx, js::IdToValue(id));
21 JS::RootedString idStr(cx);
22 if (!id.isSymbol()) { // `JS::ToString` returns `nullptr` for JS symbols
23 idStr = JS::ToString(cx, idv);
24 } else {
25 // TODO (Tom Tang): Revisit this once we have Symbol coercion support
26 // FIXME (Tom Tang): key collision for symbols without a description string, or pure strings look like "Symbol(xxx)"
27 idStr = JS_ValueToSource(cx, idv);
28 }
29
30 // We convert all types of property keys to string
31 auto chars = JS_EncodeStringToUTF8(cx, idStr);
32 return PyUnicode_FromString(chars.get());
33}
34
35bool idToIndex(JSContext *cx, JS::HandleId id, Py_ssize_t *index) {
36 if (id.isInt()) { // int-like strings have already been automatically converted to ints

Callers 12

JSObjectProxy_reprMethod · 0.85
delete_Method · 0.85
setMethod · 0.85
hasOwnMethod · 0.85
delete_Method · 0.85
setMethod · 0.85
hasOwnMethod · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected