| 34 | JSContext *GLOBAL_CX; /**< pointer to PythonMonkey's JSContext */ |
| 35 | |
| 36 | bool 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 | |
| 52 | void JSObjectProxyMethodDefinitions::JSObjectProxy_dealloc(JSObjectProxy *self) |
| 53 | { |
no test coverage detected