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

Method JSFunctionProxy_call

src/JSFunctionProxy.cc:35–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35PyObject *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}

Callers

nothing calls this directly

Calls 4

jsTypeFactoryFunction · 0.85
setSpiderMonkeyExceptionFunction · 0.85
pyTypeFactoryFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected