4 # JavaScript wrapping guide {#javascriptwrapping}
6 This guide outlines what files to modify when the DALi C++ public API changes.
10 We use Google's V8 to run JavaScript code.
11 https://developers.google.com/v8/get_started
15 There is a folder for each type of wrapped object.
18 The filename for a wrapped type are always object-wrapper.xxx
19 The filename for the static functions that forward calls to DALi are always object-api.xxx
21 The current file / folder structure is as follows:
23 
27 ## What to do when the DALi public API changes:
29 ### New property has been added
30 - No code change required.
31 - It will be automatically avalable using the dot notation. E.g. actor.my_new_property = true;
33 ### New property type has been added
34 - modify property-value-wrapper.h / .cpp to support the new type
36 ### New function added to an object
37 - Add the function name to function table in my-object-wrapper.cpp
38 - Add the forwarding function to my-object-api.cpp/.h
39 - Ensure you have created YUIDOC documention above the function
41 
42 
46 This is an example of wrapping a new DALi C++ object called Light.
48 - in dali-wrapper.cpp in ConstructorFunctionTable insert the constructor in the table.
50 
51 
54 Objects registered in this table can be created in JavaScript as follows:
57 var light = new dali.Light();
60 - Add the Light to the Type enum in BaseWrappedObject class.
62 
63 
66 - Create the light-wrapper / light-api files
68 If Light inherits from Handle then use path-wrapper and path-api as a template to create light-wrapper and light-api
69 ( inherits from HandleWrapper)
71 Otherwise use animation-wrapper and animation-api as a template ( inherts from BaseWrappedObject)
76 
77 
80 
81 
84 
85 
88 In order to wrap DALi C++ objects in JavaScript, we use
89 hidden fields inside the JavaScript object.
93 | JavaScript Object | _ | C++ WrappedObject (e.g. ImageWrapper)|
94 |---------------------------------------|-------|----------------------------------------|
95 | Hidden internal fields | | |
96 | *Pointer to a WrappedObject | ----> | Handle to a Dali::Image object |
97 | Type of wrapped object (e.g. Image) | | |
102 var name = myActor.getId();
104 v8 will detect myActor is a wrapped object, and call getId() on that wrapped object.
105 The wrapped object, then forwards the command to the real DALi object.
107 Whenever we want to access functions / properties of that wrapped object, we unwrap it
108 to get access to the DALi object.
110 Each wrapped object registers with DALi garbage collector so they can be deleted
113 @class _Guide_JavaScript_Wrapping