2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include "JSLocaleInfo.h"
23 namespace Systeminfo {
24 using namespace WrtDeviceApis::CommonsJavaScript;
25 using namespace WrtDeviceApis::Commons;
28 const char* LOCALE_LANGUAGE_PROPERTY = "language";
29 const char* LOCALE_COUNTRY_PROPERTY = "country";
32 JSClassRef JSLocaleInfo::m_classRef = NULL;
34 JSClassDefinition JSLocaleInfo::m_classInfo = {
36 kJSClassAttributeNone,
54 JSStaticValue JSLocaleInfo::m_properties[] = {
55 { LOCALE_LANGUAGE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
56 { LOCALE_COUNTRY_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
60 const JSClassRef JSLocaleInfo::getClassRef()
63 m_classRef = JSClassCreate(&m_classInfo);
68 const JSClassDefinition* JSLocaleInfo::getClassInfo()
73 void JSLocaleInfo::Initialize(JSContextRef context, JSObjectRef object)
77 void JSLocaleInfo::Finalize(JSObjectRef object)
80 JSLocalePriv* priv = static_cast<JSLocalePriv*>(JSObjectGetPrivate(object));
81 JSObjectSetPrivate(object, NULL);
82 LoggerD("Deleting localeInfo object");
86 bool JSLocaleInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
88 return JSUtils::hasProperty(m_properties, propertyName);
91 JSObjectRef JSLocaleInfo::createJSObject(JSContextRef context, const LocalePropertiesPtr localeInfo)
93 JSLocalePriv *priv = new JSLocalePriv(context, localeInfo);
94 return JSObjectMake(context, getClassRef(), priv);
97 JSValueRef JSLocaleInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
100 JSLocalePriv *priv = static_cast<JSLocalePriv*>(JSObjectGetPrivate(object));
102 LoggerE("Private object not set.");
103 return JSValueMakeUndefined(context);
108 LocalePropertiesPtr localeInfo = priv->getObject();
109 Converter convert(context);
111 if (JSStringIsEqualToUTF8CString(propertyName, LOCALE_LANGUAGE_PROPERTY)) {
112 return convert.toJSValueRef(localeInfo->language);
113 } else if (JSStringIsEqualToUTF8CString(propertyName, LOCALE_COUNTRY_PROPERTY)) {
114 return convert.toJSValueRef(localeInfo->country);
119 LoggerE("Exception: " << _rethrown_exception.GetMessage());
121 return JSValueMakeUndefined(context);