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 #include "Converter.h"
17 #include "ScopedJSStringRef.h"
20 namespace WrtDeviceApis {
21 namespace CommonsJavaScript {
23 using namespace WrtDeviceApis::Commons;
26 bool JSUtils::hasProperty(JSStaticValue* properties,
29 JSStaticValue* property = properties;
30 while (property->name) {
31 if (JSStringIsEqualToUTF8CString(name, property->name)) {
39 JSValueRef JSUtils::getJSProperty(JSContextRef context,
41 const std::string &name,
42 JSValueRef *exception)
44 ScopedJSStringRef jsPropName(JSStringCreateWithUTF8CString(name.c_str()));
45 Converter converter(context);
46 JSObjectRef jsObject = converter.toJSObjectRef(jsValue);
47 if (JSObjectHasProperty(context, jsObject, jsPropName.get())) {
48 return JSObjectGetProperty(context, jsObject,
49 jsPropName.get(), exception);
54 JSValueRef JSUtils::getJSProperty(JSContextRef context,
56 const std::string& name)
58 Converter converter(context);
60 ScopedJSStringRef propName(converter.toJSStringRef(name));
61 if (JSObjectHasProperty(context, object, propName.get())) {
62 JSValueRef result = JSObjectGetProperty(context,
66 if (!JSValueIsUndefined(context, result)) {
71 Catch(ConversionException) {
76 JSValueRef JSUtils::getJSPropertyOrUndefined(JSContextRef context,
78 const std::string& name)
80 Converter converter(context);
82 ScopedJSStringRef propName(converter.toJSStringRef(name));
83 if (JSObjectHasProperty(context, object, propName.get())) {
84 return JSObjectGetProperty(context, object, propName.get(), NULL);
87 Catch(ConversionException) {
89 return JSValueMakeUndefined(context);
91 } // CommonsJavaScript