| 33 | } |
| 34 | |
| 35 | PyObject *JSFunctionProxyMethodDefinitions::JSFunctionProxy_call(PyObject *self, PyObject *args, PyObject *kwargs) { |
| 36 | JSContext *cx = GLOBAL_CX; |
| 37 | JS::RootedValue jsFunc(GLOBAL_CX, JS::ObjectValue(**((JSFunctionProxy *)self)->jsFunc)); |
| 38 | JSObject *jsFuncObj = jsFunc.toObjectOrNull(); |
| 39 | JS::RootedObject thisObj(GLOBAL_CX, JS::CurrentGlobalOrNull(GLOBAL_CX)); // if jsFunc is not bound, assume `this` is `globalThis` |
| 40 | |
| 41 | JS::RootedVector<JS::Value> jsArgsVector(cx); |
| 42 | Py_ssize_t nargs = PyTuple_Size(args); |
| 43 | for (size_t i = 0; i < nargs; i++) { |
| 44 | JS::Value jsValue = jsTypeFactory(cx, PyTuple_GetItem(args, i)); |
| 45 | if (PyErr_Occurred()) { // Check if an exception has already been set in the flow of control |
| 46 | return NULL; // Fail-fast |
| 47 | } |
| 48 | if (!jsArgsVector.append(jsValue)) { |
| 49 | // out of memory |
| 50 | setSpiderMonkeyException(cx); |
| 51 | return NULL; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | JS::HandleValueArray jsArgs(jsArgsVector); |
| 56 | JS::RootedValue jsReturnVal(cx); |
| 57 | if (!JS_CallFunctionValue(cx, thisObj, jsFunc, jsArgs, &jsReturnVal)) { |
| 58 | setSpiderMonkeyException(cx); |
| 59 | return NULL; |
| 60 | } |
| 61 | |
| 62 | if (PyErr_Occurred()) { |
| 63 | return NULL; |
| 64 | } |
| 65 | |
| 66 | return pyTypeFactory(cx, jsReturnVal); |
| 67 | } |
nothing calls this directly
no test coverage detected