JSObject.makeFunction constructor

JSObject.makeFunction(
  1. JSContext context,
  2. String name,
  3. JSStringPointer parameterNames,
  4. String body,
  5. String sourceURL, {
  6. JSValuePointer? exception,
  7. int startingLineNumber = 0,
})

Creates a function with a given script as its body. Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution. name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function. parameterNames (JSStringRef[]) A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0. body A JSString containing the script to use as the function's body. sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. startingLineNumber (int) An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1. exception (JSValueRef*) A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.

Implementation

JSObject.makeFunction(
  this.context,
  String name,
  JSStringPointer parameterNames,
  String body,
  String sourceURL, {
  JSValuePointer? exception,
  int startingLineNumber = 0,
}) : this.pointer = JSObjectRef.jSObjectMakeFunction(
          context.pointer,
          JSString.fromString(name).pointer,
          parameterNames.count,
          parameterNames.pointer,
          JSString.fromString(body).pointer,
          JSString.fromString(sourceURL).pointer,
          startingLineNumber,
          (exception ?? JSValuePointer(nullptr)).pointer);