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

Function keyToId

src/JSObjectProxy.cc:36–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34JSContext *GLOBAL_CX; /**< pointer to PythonMonkey's JSContext */
35
36bool keyToId(PyObject *key, JS::MutableHandleId idp) {
37 if (PyUnicode_Check(key)) { // key is str type
38 JS::RootedString idString(GLOBAL_CX);
39 Py_ssize_t length;
40 const char *keyStr = PyUnicode_AsUTF8AndSize(key, &length);
41 JS::UTF8Chars utf8Chars(keyStr, length);
42 idString.set(JS_NewStringCopyUTF8N(GLOBAL_CX, utf8Chars));
43 return JS_StringToId(GLOBAL_CX, idString, idp);
44 } else if (PyLong_Check(key)) { // key is int type
45 uint32_t keyAsInt = PyLong_AsUnsignedLong(key); // TODO raise OverflowError if the value of pylong is out of range for a unsigned long
46 return JS_IndexToId(GLOBAL_CX, keyAsInt, idp);
47 } else {
48 return false; // fail
49 }
50}
51
52void JSObjectProxyMethodDefinitions::JSObjectProxy_dealloc(JSObjectProxy *self)
53{

Callers 9

JSObjectProxy_getMethod · 0.85
JSObjectProxy_assignMethod · 0.85
JSArrayProxy_getMethod · 0.85
handleOwnPropertyKeysMethod · 0.85

Calls 1

setMethod · 0.65

Tested by

no test coverage detected