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 {
22 using namespace WrtDeviceApis::Commons;
24 bool JSUtils::hasProperty(JSStaticValue* properties,
27 JSStaticValue* property = properties;
28 while (property->name) {
29 if (JSStringIsEqualToUTF8CString(name, property->name)) {
37 JSValueRef JSUtils::getJSProperty(JSContextRef context,
39 const std::string &name,
40 JSValueRef *exception)
42 ScopedJSStringRef jsPropName(JSStringCreateWithUTF8CString(name.c_str()));
43 Converter converter(context);
44 JSObjectRef jsObject = converter.toJSObjectRef(jsValue);
45 if (JSObjectHasProperty(context, jsObject, jsPropName.get())) {
46 return JSObjectGetProperty(context, jsObject,
47 jsPropName.get(), exception);
52 JSValueRef JSUtils::getJSProperty(JSContextRef context,
54 const std::string& name)
56 Converter converter(context);
58 ScopedJSStringRef propName(converter.toJSStringRef(name));
59 if (JSObjectHasProperty(context, object, propName.get())) {
60 JSValueRef result = JSObjectGetProperty(context,
64 if (!JSValueIsUndefined(context, result)) {
69 Catch(ConversionException) {}
73 JSValueRef JSUtils::getJSPropertyOrUndefined(JSContextRef context,
75 const std::string& name)
77 Converter converter(context);
79 ScopedJSStringRef propName(converter.toJSStringRef(name));
80 if (JSObjectHasProperty(context, object, propName.get())) {
81 return JSObjectGetProperty(context, object, propName.get(), NULL);
84 Catch(ConversionException) {}
85 return JSValueMakeUndefined(context);
87 } // CommonsJavaScript