Skip to content

Struct jac::ProtoBuilder::Opaque

template <typename T>

ClassList > jac > ProtoBuilder > Opaque

A base class for javascript classes with opaque data. More...

  • #include <class.h>

Public Types

Type Name
typedef T OpaqueType

Public Static Attributes

Type Name
JSClassID classId

Public Static Functions

Type Name
void addMethodMember (ContextRef ctx, Object proto, std::string name, PropFlags flags=PropFlags::Default)
Add a property to the object prototype from a member function of the wrapped class.
void addPropMember (ContextRef ctx, Object proto, std::string name, PropFlags flags=PropFlags::Default)
Add a property to the object prototype from a member variable of the wrapped class.
Value callMember (ContextRef ctx, ValueWeak funcObj, ValueWeak thisVal, std::vector< ValueWeak > argv)
Process a call to a member function of the wrapped class.
T * constructOpaque (ContextRef, std::vector< ValueWeak >)
Construct a new Opaque object from javascript arguments.
void destroyOpaque (JSRuntime *, T * ptr) noexcept
Destroy the Opaque object.
T * getOpaque (ContextRef, ValueWeak thisVal)
Get the Opaque object from an instance of the class.

Detailed Description

The functions constructOpaque and destroyOpaque can be overriden to provide custom construction and destruction of the opaque data.

Template parameters:

  • T The type of the opaque data

Public Types Documentation

typedef OpaqueType

using jac::ProtoBuilder::Opaque< T >::OpaqueType =  T;

Public Static Attributes Documentation

variable classId

JSClassID jac::ProtoBuilder::Opaque< T >::classId;

Public Static Functions Documentation

function addMethodMember

Add a property to the object prototype from a member function of the wrapped class.

template<typename Sgn, Sgn member>
static inline void jac::ProtoBuilder::Opaque::addMethodMember (
    ContextRef ctx,
    Object proto,
    std::string name,
    PropFlags flags=PropFlags::Default
) 

Template parameters:

  • Sgn signature of the member function
  • member pointer to the member function

Parameters:

  • ctx context to work in
  • proto the prototype of the class
  • name name of the property
  • flags flags of the property

function addPropMember

Add a property to the object prototype from a member variable of the wrapped class.

template<typename U, UT::* member>
static inline void jac::ProtoBuilder::Opaque::addPropMember (
    ContextRef ctx,
    Object proto,
    std::string name,
    PropFlags flags=PropFlags::Default
) 

Template parameters:

  • U the type of the member variable
  • U(T::*member) pointer to the member variable

Parameters:

  • ctx context to work in
  • proto the prototype of the class
  • name name of the property
  • flags flags of the property

function callMember

Process a call to a member function of the wrapped class.

template<typename Sgn, Sgn member>
static inline Value jac::ProtoBuilder::Opaque::callMember (
    ContextRef ctx,
    ValueWeak funcObj,
    ValueWeak thisVal,
    std::vector< ValueWeak > argv
) 

Note:

The arguments and return value are automatically converted to and from javascript values

Template parameters:

  • Sgn the signature of the member function
  • member pointer to the member function

Parameters:

  • ctx context to work in
  • funcObj instance of the class
  • thisVal value of this in the function
  • argv arguments passed to the function

Returns:

Result of the call


function constructOpaque

Construct a new Opaque object from javascript arguments.

static inline T * jac::ProtoBuilder::Opaque::constructOpaque (
    ContextRef,
    std::vector< ValueWeak >
) 

Note:

This function is only called upon javascript class instantiation

Parameters:

  • ctx context to work in
  • args arguments passed to the constructor

Returns:

A pointer to the opaque data


function destroyOpaque

Destroy the Opaque object.

static inline void jac::ProtoBuilder::Opaque::destroyOpaque (
    JSRuntime *,
    T * ptr
) noexcept

Note:

This function is only called when the javascript object is garbage collected

Parameters:

  • rt runtime to work in
  • ptr pointer to the opaque data

function getOpaque

Get the Opaque object from an instance of the class.

static inline T * jac::ProtoBuilder::Opaque::getOpaque (
    ContextRef,
    ValueWeak thisVal
) 

Parameters:

  • ctx context to work in
  • thisVal the instance of the class

Returns:

A pointer to the opaque data



The documentation for this class was generated from the following file src/jac/machine/class.h