Skip to main content

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 context
  • func_obj - The function object to call
  • this_obj - The this value for the function call
  • argc - Number of arguments
  • argv - Array of argument values

Returns

Returns the result of the function call, or JS_EXCEPTION on error.

Example

JS_Invoke

Invoke a method on an object by property name.

Parameters

  • ctx - The JavaScript context
  • this_val - The object to invoke the method on
  • atom - The atom representing the method name
  • argc - Number of arguments
  • argv - Array of argument values

Returns

Returns the result of the method call, or JS_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_EXCEPTION before using the result
  • JS_Invoke() is a convenience function that combines property lookup and function call