Dali 3D User Interface Engine
javascript-wrapping-guide

JavaScript wrapping guide

This guide outlines what files to modify when the DALi C++ public API changes.

Background

We use Google's V8 to run JavaScript code. https://developers.google.com/v8/get_started

Folder structure

There is a folder for each type of wrapped object.

The filename for a wrapped type are always object-wrapper.xxx The filename for the static functions that forward calls to DALi are always object-api.xxx

The current file / folder structure is as follows:

folder-view.png

What to do when the DALi public API changes:

New property has been added

New property type has been added

New function added to an object

adding-function.png

New object added

This is an example of wrapping a new DALi C++ object called Light.

constructors.png

Objects registered in this table can be created in JavaScript as follows:

var light = new dali.Light();
base-wrapped-types.png

If Light inherits from Handle then use path-wrapper and path-api as a template to create light-wrapper and light-api ( inherits from HandleWrapper)

Otherwise use animation-wrapper and animation-api as a template ( inherts from BaseWrappedObject)

Design

high-level-design.png
plugin-creation.png
plugin-execution.png

Internals

In order to wrap DALi C++ objects in JavaScript, we use hidden fields inside the JavaScript object.

JavaScript Object _ C++ WrappedObject (e.g. ImageWrapper)
Hidden internal fields
*Pointer to a WrappedObject -—> Handle to a Dali::Image object
Type of wrapped object (e.g. Image)

So if you call

var name = myActor.getId();

v8 will detect myActor is a wrapped object, and call getId() on that wrapped object. The wrapped object, then forwards the command to the real DALi object.

Whenever we want to access functions / properties of that wrapped object, we unwrap it to get access to the DALi object.

Each wrapped object registers with DALi garbage collector so they can be deleted when DALi shuts down

Dali Docs Home
Read more about Dali