Calling JavaScript Functions
QuickJS provides functions to call JavaScript functions and methods from C code.JS_Call
Call a JavaScript function.Parameters
ctx- The JavaScript contextfunc_obj- The function object to callthis_obj- Thethisvalue for the function callargc- Number of argumentsargv- Array of argument values
Returns
Returns the result of the function call, orJS_EXCEPTION on error.
Example
JS_Invoke
Invoke a method on an object by property name.Parameters
ctx- The JavaScript contextthis_val- The object to invoke the method onatom- The atom representing the method nameargc- Number of argumentsargv- Array of argument values
Returns
Returns the result of the method call, orJS_EXCEPTION on error.
Example
Notes
- Both functions transfer ownership of argument values to the callee
- The returned value must be freed with
JS_FreeValue() - Always check for
JS_EXCEPTIONbefore using the result JS_Invoke()is a convenience function that combines property lookup and function call