callAsFunction method

JSValue callAsFunction({
  1. JSObject? thisObject,
  2. List<JSValue>? arguments,
  3. bool autoDispose = true,
})

Calls an object as a function. thisObject (JSObjectRef) The object to use as "this," or NULL to use the global object as "this." arguments (JSValueRef[]) A JSValue array of arguments to pass to the function. Pass NULL if argumentCount is 0. exception (JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result (JSValue) The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.

Implementation

JSValue callAsFunction({
  JSObject? thisObject,
  List<JSValue>? arguments,
  bool autoDispose = true,
}) {
  final JSException exception = JSException.create(context);
  final JSValueRef valueRef = JSObjectCallAsFunction(
    context.ref,
    _ref,
    thisObject?.ref ?? nullptr,
    arguments?.length ?? 0,
    arguments?.ref ?? nullptr,
    exception.ref,
  );
  if (exception.shouldThrow) throw exception.error;
  return JSValue(context, valueRef, autoDispose: autoDispose);
}