All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSFunction

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

Overview

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]

Create an empty Function.

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

◆ JSFunction() [2/3]

JSFunction ( const JSFunction & other)

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

◆ ~JSFunction()

~JSFunction ( )

◆ JSFunction() [3/3]

JSFunction ( JSContextRef ctx,
JSValueRef val )
protected

Member Function Documentation

◆ context()

JSContextRef context ( ) const
inline

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

◆ IsValid()

bool IsValid ( ) const

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

◆ operator JSObjectRef()

operator JSObjectRef ( ) const
inline

Get the underlying JSObjectRef (JavaScriptCore C API)

◆ operator()() [1/2]

JSValue operator() ( const JSArgs & args)

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

◆ operator()() [2/2]

JSValue operator() ( const JSObject & thisObject,
const JSArgs & args )

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

◆ operator=()

JSFunction & operator= ( const JSFunction & other)

Assignment (shallow assignment, will point to same instance)

◆ set_context()

void 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 ctx_
protected

◆ instance_

JSObjectRef instance_
protected

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