tizen 2.3.1 release
[framework/web/mobile/wrt-plugins-tizen.git] / src / RefImpl / JSRefImplManager.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <SecurityExceptions.h>
17 #include <CommonsJavaScript/Converter.h>
18 #include <GlobalContextManager.h>
19 #include <ArgumentValidator.h>
20 #include <PlatformException.h>
21 #include <JSWebAPIErrorFactory.h>
22 #include <JSUtil.h>
23 #include <Logger.h>
24 #include <MultiCallbackUserData.h>
25 #include <boost/shared_ptr.hpp>
26 #include <string>
27 #include <vector>
28 #include <JSArray.h>
29
30 #include "TimeTracer.h"
31 #include "JSRefImplManager.h"
32 #include "RefImplManager.h"
33 #include "JSSub.h"
34 #include "JSSuper.h"
35 #include "Sub.h"
36 #include "NestedValue.h"
37 #include "JSNestedValue.h"
38
39 using namespace std;
40 using namespace WrtDeviceApis::CommonsJavaScript;
41 using namespace WrtDeviceApis::Commons;
42 using namespace DeviceAPI::Common;
43
44
45 namespace DeviceAPI {
46 namespace Reference {
47
48 JSClassRef JSRefImplManager::m_jsClassRef = NULL;
49
50 JSClassDefinition JSRefImplManager::m_jsClassInfo = {
51     0,                                       // current (and only) version is 0
52     kJSClassAttributeNone,        //attributes
53     "RefImplManager",                        //class name
54     NULL,                                 // parent class
55     JSRefImplManager::m_property,                                 //static values
56     JSRefImplManager::m_function,     // static functions
57     JSRefImplManager::initialize,         // initialize
58     JSRefImplManager::finalize,          //finalize
59     NULL,                                //hasProperty
60     JSRefImplManager::getNormalProperty,   //getProperty
61     JSRefImplManager::setNormalProperty,  //setProperty
62     NULL,                                //deleteProperty
63     NULL,                                //getPropertyNames
64     NULL,                               // callAsConstructor
65     NULL,                               // constructor
66     NULL,
67     NULL // convertToType
68 };
69
70 JSStaticValue JSRefImplManager::m_property[] = {
71         { "Number", getReadOnlyNumber, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
72         { "Sub", getReadOnlySub, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
73         { 0, 0, 0, 0 }
74 };
75
76
77
78 JSStaticFunction JSRefImplManager::m_function[] = {
79     { "syncToSync", JSRefImplManager::syncToSync, kJSPropertyAttributeNone },
80     { "syncToAsync", JSRefImplManager::syncToAsync, kJSPropertyAttributeNone },
81     { "asyncToAsync", JSRefImplManager::asyncToAsync, kJSPropertyAttributeNone },
82     { "addListener", JSRefImplManager::addListener, kJSPropertyAttributeNone },
83     { "removeListener", JSRefImplManager::removeListener, kJSPropertyAttributeNone },
84     { "fire", JSRefImplManager::fire, kJSPropertyAttributeNone },
85     { "argtest", JSRefImplManager::argtest, kJSPropertyAttributeNone },
86     { "arraytest", JSRefImplManager::arraytest, kJSPropertyAttributeNone },
87     { "isSuper", JSRefImplManager::isSuper, kJSPropertyAttributeNone },
88     { "isSub", JSRefImplManager::isSub, kJSPropertyAttributeNone },
89     { "setCallback", JSRefImplManager::setCallback, kJSPropertyAttributeNone },
90     { "unsetCallback", JSRefImplManager::unsetCallback, kJSPropertyAttributeNone },
91     { "fireCallback", JSRefImplManager::fireCallback, kJSPropertyAttributeNone },
92     { "callbackObjectTest", JSRefImplManager::callbackObjectTest, kJSPropertyAttributeNone },
93     { "updateNumber", JSRefImplManager::updateNumber, kJSPropertyAttributeNone },
94     { "updateSub", JSRefImplManager::updateSub, kJSPropertyAttributeNone },
95     { 0, 0, 0 }
96 };
97
98 const JSClassRef JSRefImplManager::getClassRef()
99 {
100     if (!m_jsClassRef) {
101         m_jsClassRef = JSClassCreate(&m_jsClassInfo);
102     }
103     return m_jsClassRef;
104 }
105
106 const JSClassDefinition* JSRefImplManager::getClassInfo()
107 {
108     return &m_jsClassInfo;
109 }
110
111 void JSRefImplManager::initialize(JSContextRef ctx, JSObjectRef object)
112 {
113         TIME_TRACER_INIT();
114 }
115
116 void JSRefImplManager::finalize(JSObjectRef object)
117 {
118         TIME_TRACER_EXPORT_REPORT_TO(TIME_TRACER_EXPORT_FILE,"RefImpl");
119         TIME_TRACER_RELEASE();
120 }
121
122
123 JSValueRef JSRefImplManager::getReadOnlyNumber(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception){
124     return RefImplManager::getInstance()->mLocalProperty.getProperty(context,propertyName);
125 }
126
127 JSValueRef JSRefImplManager::getReadOnlySub(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception){
128     return RefImplManager::getInstance()->mLocalProperty.getProperty(context,propertyName);
129 }
130
131 JSValueRef JSRefImplManager::getNormalProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception){
132     string name = JSUtil::JSStringToString(context, propertyName);
133     if( name == "Number" )
134         return NULL;
135     if( name == "Sub")
136         return NULL;
137     return RefImplManager::getInstance()->mLocalProperty.getProperty(context,propertyName);
138 }
139
140 bool JSRefImplManager::setNormalProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception){
141     string name = JSUtil::JSStringToString(context, propertyName);
142     if( name == "Number" )
143         return false;
144     if( name == "Sub")
145         return false;
146     return RefImplManager::getInstance()->mLocalProperty.setProperty(context,propertyName, value);
147 }
148
149 JSValueRef JSRefImplManager::syncToSync(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
150         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);
151     try{
152         Converter convert(ctx);
153         ArgumentValidator validator(ctx, argumentCount, arguments);
154
155         int a = validator.toLong(0);
156         int b = validator.toLong(1);
157         int result = RefImplManager::getInstance()->syncToSync(a,b);
158         TIME_TRACER_ITEM_END(__FUNCTION__, 1);
159         return convert.toJSValueRef(result);
160     }catch( const TypeMismatchException& err ){
161         return JSWebAPIErrorFactory::postException(ctx, exception, err);
162     }catch( const BasePlatformException& err){
163         return JSWebAPIErrorFactory::postException(ctx, exception, err);
164     }catch( const ConversionException& err){
165         return JSWebAPIErrorFactory::postException(ctx, exception,  "TypeMismatchError" , "can't convert to int");    
166     }
167     return JSValueMakeUndefined(ctx);
168 }
169
170 JSValueRef JSRefImplManager::syncToAsync(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
171         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);
172     try{
173         ArgumentValidator validator(ctx, argumentCount, arguments);
174
175         int a = validator.toLong(0);
176         int b = validator.toLong(1);
177         RefCallbackUserData *callback = new RefCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(ctx),a,b);
178         callback->setSuccessCallback(validator.toFunction(2));
179         callback->setErrorCallback(validator.toFunction(3, true));
180
181         RefImplManager::getInstance()->syncToAsync(callback);
182         
183     }catch( const TypeMismatchException& err ){
184         return JSWebAPIErrorFactory::postException(ctx, exception, err);
185     }catch( const BasePlatformException& err){
186         return JSWebAPIErrorFactory::postException(ctx, exception, err);
187     }
188         TIME_TRACER_ITEM_END(__FUNCTION__, 1);
189         TIME_TRACER_EXPORT_REPORT();
190         TIME_TRACER_EXPORT_REPORT_TO(TIME_TRACER_EXPORT_FILE,"RefImpl");
191     return JSValueMakeUndefined(ctx);
192
193 }
194
195 JSValueRef JSRefImplManager::asyncToAsync(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
196     try{
197         ArgumentValidator validator(ctx, argumentCount, arguments);
198         int a = validator.toLong(0);
199         int b = validator.toLong(1);
200         RefCallbackUserData *callback = new RefCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(ctx),a,b);
201         callback->setSuccessCallback(validator.toFunction(2));
202         callback->setErrorCallback(validator.toFunction(3, true));
203
204         RefImplManager::getInstance()->asyncToAsync(callback);
205
206     }catch( const TypeMismatchException& err ){
207         return JSWebAPIErrorFactory::postException(ctx, exception, err);
208     }catch( const BasePlatformException& err){
209         return JSWebAPIErrorFactory::postException(ctx, exception, err);
210     }
211
212     return JSValueMakeUndefined(ctx);
213
214 }
215
216 JSValueRef JSRefImplManager::argtest(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
217     try{
218         ArgumentValidator validator(ctx, argumentCount, arguments);
219         string tocheck = validator.toString(0);
220
221         if( validator.isOmitted(0) || validator.isNull(0)){
222             printf("argument is omitted\n");
223         }
224
225         if( tocheck == "Boolean"){
226             bool value = validator.toBool(1);
227             printf("arg[1] = %d\n", value);
228             return JSUtil::toJSValueRef(ctx, value);
229         }
230         else if( tocheck == "Long"){
231             long value = validator.toLong(1);
232             printf("arg[1] = %ld\n", value);
233             return JSUtil::toJSValueRef(ctx, value);
234         }
235         else if( tocheck == "ULong"){
236             unsigned long value = validator.toULong(1);
237             printf("arg[1] = %lu\n", value);
238             return JSUtil::toJSValueRef(ctx, value);
239         }
240         else if( tocheck == "ULongLong"){
241             unsigned long long value = validator.toULongLong(1);
242             printf("arg[1] = %llu\n", value);
243             return JSUtil::toJSValueRef(ctx, value);
244         }
245         else if( tocheck == "Byte"){
246             signed char value = (int)validator.toByte(1);
247             printf("arg[1] = %d\n", value);
248             return JSUtil::toJSValueRef(ctx, value);
249         }
250         else if( tocheck == "Octet"){
251             unsigned char value = (int)validator.toOctet(1);
252             printf("arg[1] = %d\n", value);
253             return JSUtil::toJSValueRef(ctx, value);
254         }
255         else if( tocheck == "String"){
256             string value = validator.toString(1);
257             printf("arg[1] = %s\n", value.c_str());
258             return JSUtil::toJSValueRef(ctx, value);
259         }else if( tocheck == "Object"){
260             JSObjectRef value = validator.toObject(1);
261             printf("arg[1] = %p\n", value);
262             return value;
263         }else if( tocheck == "Date"){
264             time_t value = validator.toTimeT(1);
265             printf("arg[1] = %ld\n", value);
266             return JSUtil::makeDateObject(ctx, value);
267         }else if( tocheck == "Double" ){
268             double value = validator.toDouble(1);
269             printf("arg[1] = %f\n", value);
270             return JSUtil::toJSValueRef(ctx, value);
271         }else if( tocheck == "Function"){
272             JSObjectRef value = validator.toFunction(1);
273             printf("arg[1] = %p\n", value);
274             return value;
275         }else if( tocheck == "Array"){
276             JSObjectRef value = validator.toArrayObject(1);
277             printf("arg[1] = %p\n", value);
278             return value;
279         }else{
280             printf("usage: argtest([Long|String|Object|Date|Double|Function], ...)\n");
281             return JSUtil::toJSValueRef(ctx, "usage: argtest([Long|String|Object|Date|Double|Function], ...)");
282         }
283     }catch( const TypeMismatchException& err ){
284         printf("TypeMismatch exception %s : %s\n", err.getName().c_str(), err.getMessage().c_str());
285         return JSWebAPIErrorFactory::postException(ctx, exception, err);
286     }
287     return JSValueMakeUndefined(ctx);
288 }
289
290 JSValueRef makeJSBool(JSContextRef ctx, bool v){
291     return JSUtil::toJSValueRef(ctx, v);
292 }
293
294 JSValueRef makeNestedValue(JSContextRef ctx,  boost::shared_ptr < NestedValue > native){
295     return JSNestedValue::makeJSObject(ctx, native);
296 }
297
298 JSValueRef JSRefImplManager::arraytest(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
299     try{
300         ArgumentValidator validator(ctx, argumentCount, arguments);
301         string type = validator.toString(0);
302         JSObjectRef jsArray = validator.toArrayObject(1, true);
303         if( type == "String" && jsArray != NULL){
304             JSStringArray receivedArray(ctx, jsArray);
305
306             // basic getting test
307             for( unsigned int i = 0 ; i < receivedArray.size() ; i++){
308                 string element = receivedArray[i];
309                 printf("received array[%d] = %s\n", i, element.c_str());
310             }
311
312             // JSArray to JSArray Copy test
313             JSStringArray copyTest(ctx);
314             copyTest = receivedArray;
315
316             for( unsigned int i = 0 ; i < copyTest.size() ; i++){
317                 string element = copyTest[i];
318                 printf("copyTest array[%d] = %s\n", i, element.c_str());
319             }
320
321             // to Native Vector converting test
322             vector<string> tmp = receivedArray;
323             for( unsigned int i = 0 ; i < tmp.size() ; i++){
324                 printf("to Native Vector [%d] = %s\n", i, tmp[i].c_str());
325             }
326
327             //Copy from vector
328             vector<string> aa;
329             aa.push_back("one");
330             aa.push_back("two");
331             aa.push_back("three");
332             JSStringArray newArray(ctx);
333             newArray = aa;
334             for( unsigned int i = 0 ; i < newArray.size() ; i++){
335                 string element = newArray[i];
336                 printf("Copy from Vector[%d] = %s\n", i, element.c_str());
337             }
338
339             // Modification test
340             newArray[newArray.size()] = "last";
341             newArray[0] = "zero";
342             printf("Modification test\n");
343             printf("except:zero,two,three,last\n");
344
345             return newArray;
346         }
347         else if( type == "Long" && jsArray != NULL ){
348             JSLongArray receivedArray(ctx, jsArray);
349
350             //Basic getting test
351             for( unsigned int i = 0 ; i < receivedArray.size() ; i++){
352                 long v = receivedArray[i];
353                 printf("received array[%d] = %d\n", i, v );
354             }
355
356             // JSArray to JSArray Copy test
357             JSLongArray copyTest(ctx);
358             copyTest = receivedArray;
359
360             for( unsigned int i = 0 ; i < copyTest.size() ; i++){
361                 long v = copyTest[i];
362                 printf("copyTest array[%d] = %d\n", i, v);
363             }
364
365             // to Native Vector converting test
366             vector<long> tmp = receivedArray;
367             for( unsigned int i = 0 ; i < tmp.size() ; i++){
368                 printf("to Native Vector [%d] = %d\n", i, tmp[i]);
369             }
370
371             //Copy from vector
372             vector<long> aa;
373             aa.push_back(1);
374             aa.push_back(2);
375             aa.push_back(3);
376             JSLongArray newArray(ctx);
377             newArray = aa;
378             for( unsigned int i = 0 ; i < newArray.size() ; i++){
379                 long v = newArray[i];
380                 printf("Copy from Vector[%d] = %d\n", i, v);
381             }
382
383             // Modification test
384             newArray[newArray.size()] = 99;
385             newArray[0] = 0;
386             printf("Modification test\n");
387             printf("except:0,2,3,99\n");
388
389             return newArray;
390         }
391         else if( type == "Boolean" && jsArray != NULL ){
392             JSArray<bool> receivedArray(ctx, jsArray, JSUtil::JSValueToBoolean, makeJSBool);
393
394             //Basic getting test
395             for( unsigned int i = 0 ; i < receivedArray.size() ; i++){
396                 printf("received array[%d] = %s\n", i, receivedArray[i] ? "true" : "false" );
397             }
398
399             // JSArray to JSArray Copy test
400             JSArray<bool> copyTest(ctx,  JSUtil::JSValueToBoolean, makeJSBool);
401             copyTest = receivedArray;
402
403             for( unsigned int i = 0 ; i < copyTest.size() ; i++){
404                 printf("copyTest array[%d] = %s\n", i, copyTest[i] ? "true" : "false" );
405             }
406
407             // to Native Vector converting test
408             vector<bool> tmp = receivedArray;
409             for( unsigned int i = 0 ; i < tmp.size() ; i++){
410                 printf("to Native Vector[%d] = %s\n", i, tmp[i] ? "true" : "false" );
411             }
412
413             //Copy from vector
414             vector<bool> aa;
415             aa.push_back(true);
416             aa.push_back(false);
417             aa.push_back(true);
418             JSArray<bool> newArray(ctx,  JSUtil::JSValueToBoolean, makeJSBool);
419             newArray = aa;
420             for( unsigned int i = 0 ; i < newArray.size() ; i++){
421                 printf("Copy from Vector[%d] = %s\n", i, newArray[i] ? "true" : "false" );
422             }
423
424             // Modification test
425             newArray[newArray.size()] = true;
426             newArray[0] = false;
427             printf("Modification test\n");
428             printf("except:false,false,true,false\n");
429             return newArray;
430
431         }
432         else if( type == "NestedValue" && jsArray != NULL ){
433             JSArray<boost::shared_ptr<NestedValue>> receivedArray(ctx, jsArray, JSNestedValue::getNative, makeNestedValue);
434             for( unsigned int i = 0 ; i< receivedArray.size() ; i++){
435                 boost::shared_ptr<NestedValue> ptr = receivedArray[i];
436                 ptr->print();
437             }
438             JSArray<boost::shared_ptr<NestedValue>> newArray(ctx, JSNestedValue::getNative, makeNestedValue);
439             newArray = receivedArray;
440             newArray[0] = boost::shared_ptr<NestedValue>(new NestedValue(0, "newAdded!"));
441             for( unsigned int i = 0 ; i< newArray.size() ; i++){
442                 boost::shared_ptr<NestedValue> ptr = newArray[i];
443                 ptr->print();
444             }
445             return newArray;
446         }
447         else{
448             printf("usage: arraytest([Long|String|Boolean], array)\n");
449             return JSUtil::toJSValueRef(ctx, "usage: arraytest([Long|String|Boolean], array)");
450         }
451         return JSValueMakeUndefined(ctx);
452     }catch( const TypeMismatchException& err ){
453         printf("TypeMismatch exception %s : %s\n", err.getName().c_str(), err.getMessage().c_str());
454         return JSWebAPIErrorFactory::postException(ctx, exception, err);
455     }catch( const BasePlatformException& err){
456         printf("exception %s : %s\n", err.getName().c_str(), err.getMessage().c_str());
457         return JSWebAPIErrorFactory::postException(ctx, exception, err);
458     }
459     return JSValueMakeUndefined(ctx);
460
461 }
462
463 JSValueRef JSRefImplManager::addListener(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
464     try{
465         ArgumentValidator validator(ctx, argumentCount, arguments);
466         JSObjectRef fun = validator.toFunction(0);
467         boost::shared_ptr<CallbackUserData> callback(new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(ctx)));
468         callback->setSuccessCallback(fun);
469         long id = RefImplManager::getInstance()->addListener(callback);
470         return JSUtil::toJSValueRef(ctx, id);
471     }catch( const BasePlatformException& err){
472         return JSWebAPIErrorFactory::postException(ctx, exception, err);
473     }
474     return JSValueMakeUndefined(ctx);
475 }
476
477 JSValueRef JSRefImplManager::removeListener(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
478     try{
479         ArgumentValidator validator(ctx, argumentCount, arguments);
480         int id = validator.toLong(0);
481         RefImplManager::getInstance()->removeListener(id);
482     }catch( const BasePlatformException& err){
483         return JSWebAPIErrorFactory::postException(ctx, exception, err);
484     }
485     return JSValueMakeUndefined(ctx);
486 }
487
488 JSValueRef JSRefImplManager::fire(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
489     RefImplManager::getInstance()->fireListener();
490     return JSValueMakeUndefined(ctx);
491 }
492
493
494
495 JSValueRef JSRefImplManager::isSuper(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
496     try{
497         ArgumentValidator validator(ctx, argumentCount, arguments);
498         JSObjectRef test = validator.toObject(0);
499         if( JSValueIsObjectOfClass(ctx, test, JSSuper::getClassRef()) )
500             return JSUtil::toJSValueRef(ctx, true);
501         else
502             return JSUtil::toJSValueRef(ctx, false);
503     }catch( const BasePlatformException& err){
504         printf("exception %s %s\n", err.getName().c_str(), err.getMessage().c_str());
505         return JSWebAPIErrorFactory::postException(ctx, exception, err);
506     }
507     return JSValueMakeUndefined(ctx);
508 }
509
510 JSValueRef JSRefImplManager::isSub(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
511     try{
512         ArgumentValidator validator(ctx, argumentCount, arguments);
513         JSObjectRef test = validator.toObject(0);
514         if( JSValueIsObjectOfClass(ctx, test, JSSub::getClassRef()) )
515             return JSUtil::toJSValueRef(ctx, true);
516         else
517             return JSUtil::toJSValueRef(ctx, false);
518     }catch( const BasePlatformException& err){
519         printf("exception %s %s\n", err.getName().c_str(), err.getMessage().c_str());
520         return JSWebAPIErrorFactory::postException(ctx, exception, err);
521     }
522     return JSValueMakeUndefined(ctx);
523 }
524
525 JSValueRef JSRefImplManager::setCallback(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
526     try{
527         ArgumentValidator validator(ctx, argumentCount, arguments);
528         JSObjectRef jsCallbackObj = validator.toObject(0);
529         boost::shared_ptr<MultiCallbackUserData> callback(new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(ctx), jsCallbackObj));
530         RefImplManager::getInstance()->setCallbackObject(GlobalContextManager::getInstance()->getGlobalContext(ctx), callback);
531     }catch( const BasePlatformException& err){
532         return JSWebAPIErrorFactory::postException(ctx, exception, err);
533     }
534     return JSValueMakeUndefined(ctx);
535 }
536 JSValueRef JSRefImplManager::unsetCallback(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
537     RefImplManager::getInstance()->unsetCallbackObject(GlobalContextManager::getInstance()->getGlobalContext(ctx));
538     return JSValueMakeUndefined(ctx);
539 }
540 JSValueRef JSRefImplManager::fireCallback(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
541     try{
542         ArgumentValidator validator(ctx, argumentCount, arguments);
543         string functionName= validator.toString(0);
544         RefImplManager::getInstance()->namedCallbackFire(GlobalContextManager::getInstance()->getGlobalContext(ctx), functionName.c_str());
545     }catch( const BasePlatformException& err){
546         return JSWebAPIErrorFactory::postException(ctx, exception, err);
547     }
548     return JSValueMakeUndefined(ctx);
549 }
550
551 JSValueRef JSRefImplManager::callbackObjectTest(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
552     try{
553         printf("validator.toCallbackObject(0, true, \"fun1\", \"fun2\", \"fun3\", NULL);\n");
554         ArgumentValidator validator(ctx, argumentCount, arguments);
555         JSObjectRef obj = validator.toCallbackObject(0, true, "fun1", "fun2", "fun3", NULL);
556         printf("returnd obj = %p\n", obj);
557     }catch( const BasePlatformException& err){
558         printf("exception %s %s\n", err.getName().c_str(), err.getMessage().c_str());
559     }
560     try{
561         printf("validator.toCallbackObject(0, false, \"fun1\", \"fun2\", \"fun3\", NULL);\n");
562         ArgumentValidator validator(ctx, argumentCount, arguments);
563         JSObjectRef obj = validator.toCallbackObject(0, false, "fun1", "fun2", "fun3", NULL);
564         printf("returnd obj = %p\n", obj);
565     }catch( const BasePlatformException& err){
566         printf("exception %s %s\n", err.getName().c_str(), err.getMessage().c_str());
567     }
568
569     return JSValueMakeUndefined(ctx);
570 }
571
572 JSValueRef JSRefImplManager::updateNumber(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
573     try{
574         ArgumentValidator validator(ctx, argumentCount, arguments);
575         int readonlyValue= validator.toLong(0);
576         RefImplManager::getInstance()->mLocalProperty.setProperty(ctx, "Number", (double)readonlyValue);
577     }catch( const BasePlatformException& err){
578         return JSWebAPIErrorFactory::postException(ctx, exception, err);
579     }
580     return JSValueMakeUndefined(ctx);
581 }
582
583 JSValueRef JSRefImplManager::updateSub(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){
584     try{
585         ArgumentValidator validator(ctx, argumentCount, arguments);
586         JSObjectRef o = validator.toObject(0, JSSub::getClassRef());
587         RefImplManager::getInstance()->mLocalProperty.setProperty(ctx, "Sub", o);
588     }catch( const BasePlatformException& err){
589         return JSWebAPIErrorFactory::postException(ctx, exception, err);
590     }
591     return JSValueMakeUndefined(ctx);
592 }
593
594 } // Reference
595 } // TizenApis
596