Ultralight C++ API 1.3.0
Loading...
Searching...
No Matches
ultralight::JSFunction Class Reference

#include <AppCore/JSHelpers.h>

Details

JSFunction wrapper that automatically manages lifetime and provides convenient function invocation operators.

Public Member Functions

 JSFunction ()
 Create an empty Function.
 
 JSFunction (const JSFunction &other)
 Copy constructor (shallow copy, will point to same instance)
 
 ~JSFunction ()
 
JSFunctionoperator= (const JSFunction &other)
 Assignment (shallow assignment, will point to same instance)
 
bool IsValid () const
 Whether or not this is a valid, callable Function object.
 
JSValue operator() (const JSArgs &args)
 Call function (using Global Object for 'this') and return the result.
 
JSValue operator() (const JSObject &thisObject, const JSArgs &args)
 Call function (with explicit object for 'this') and return the result.
 
 operator JSObjectRef () const
 Get the underlying JSObjectRef (JavaScriptCore C API)
 
JSContextRef context () const
 Get the bound context for this JSFunction (it is cached at creation).
 
void set_context (JSContextRef context)
 Set the JSContext for this JSFunction.
 

Protected Member Functions

 JSFunction (JSContextRef ctx, JSValueRef val)
 

Protected Attributes

JSContextRef ctx_
 
JSObjectRef instance_
 

Friends

class JSValue
 

Constructor & Destructor Documentation

◆ JSFunction() [1/3]

ultralight::JSFunction::JSFunction ( )

Create an empty Function.

NOTE: It is OKAY to create this without calling SetJSContext() first.

◆ JSFunction() [2/3]

ultralight::JSFunction::JSFunction ( const JSFunction other)

Copy constructor (shallow copy, will point to same instance)

◆ ~JSFunction()

ultralight::JSFunction::~JSFunction ( )

◆ JSFunction() [3/3]

ultralight::JSFunction::JSFunction ( JSContextRef  ctx,
JSValueRef  val 
)
protected

Member Function Documentation

◆ context()

JSContextRef ultralight::JSFunction::context ( ) const
inline

Get the bound context for this JSFunction (it is cached at creation).

◆ IsValid()

bool ultralight::JSFunction::IsValid ( ) const

Whether or not this is a valid, callable Function object.

◆ operator JSObjectRef()

ultralight::JSFunction::operator JSObjectRef ( ) const
inline

Get the underlying JSObjectRef (JavaScriptCore C API)

◆ operator()() [1/2]

JSValue ultralight::JSFunction::operator() ( const JSArgs args)

Call function (using Global Object for 'this') and return the result.

◆ operator()() [2/2]

JSValue ultralight::JSFunction::operator() ( const JSObject thisObject,
const JSArgs args 
)

Call function (with explicit object for 'this') and return the result.

◆ operator=()

JSFunction & ultralight::JSFunction::operator= ( const JSFunction other)

Assignment (shallow assignment, will point to same instance)

◆ set_context()

void ultralight::JSFunction::set_context ( JSContextRef  context)
inline

Set the JSContext for this JSFunction.

Note: JSFunctions created from within a JSCallback have a temporary JSContext that is destroyed when the callback returns. You will need to "move" any JSFunctions created within these callbacks to the View's main context (call set_context() with the main context) before using them outside the callback.

Friends And Related Symbol Documentation

◆ JSValue

friend class JSValue
friend

Member Data Documentation

◆ ctx_

JSContextRef ultralight::JSFunction::ctx_
protected

◆ instance_

JSObjectRef ultralight::JSFunction::instance_
protected

The documentation for this class was generated from the following file: