2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_JSUTILS_H_
17 #define WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_JSUTILS_H_
20 #include <dpl/log/log.h>
21 #include <JavaScriptCore/JavaScript.h>
22 #include <Commons/Exception.h>
23 #include <CommonsJavaScript/PrivateObject.h>
25 namespace WrtDeviceApis {
26 namespace CommonsJavaScript {
30 static bool hasProperty(JSStaticValue* properties,
34 * Gets a property from JSObject if exists
35 * @return JSValueRef if property exists, NULL if not
37 static JSValueRef getJSProperty(JSContextRef context,
39 const std::string &name,
40 JSValueRef* exception = NULL);
42 static JSValueRef getJSProperty(JSContextRef context,
44 const std::string& name);
46 static JSValueRef getJSPropertyOrUndefined(JSContextRef context,
48 const std::string& name);
51 static JSObjectRef makeObject(JSContextRef context,
55 typedef typename PrivateObjectT<C>::Type Private;
57 Private* priv = new Private(context, data);
58 JSObjectRef object = JSObjectMake(context, classRef, priv);
60 ThrowMsg(Commons::NullPointerException,
61 "Could not create JS object.");
67 static JSObjectRef makeObject(JSContextRef context,
70 typedef PrivateObjectT<void>::Type Private;
72 Private* priv = new Private(context);
73 JSObjectRef object = JSObjectMake(context, classRef, priv);
75 ThrowMsg(Commons::NullPointerException,
76 "Could not create JS object.");
82 } // CommonsJavaScript
85 #endif /* WRTPLUGINS_COMMONS_JSUTILS_H_ */