diff options
Diffstat (limited to 'mobile_src/SecureElement/SEConverter.cpp')
-rw-r--r-- | mobile_src/SecureElement/SEConverter.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/mobile_src/SecureElement/SEConverter.cpp b/mobile_src/SecureElement/SEConverter.cpp new file mode 100644 index 0000000..ac355e1 --- /dev/null +++ b/mobile_src/SecureElement/SEConverter.cpp @@ -0,0 +1,66 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include <CommonsJavaScript/Validator.h> +#include <CommonsJavaScript/JSUtils.h> +#include "SEConverter.h" +#include <JSWebAPIErrorFactory.h> +#include <Logger.h> + +using namespace std; +using namespace WrtDeviceApis::CommonsJavaScript; +using namespace WrtDeviceApis; +using namespace DeviceAPI::Common; + + +namespace DeviceAPI { +namespace SecureElement { + +SEConverter::SEConverter(JSContextRef context) : Converter(context) +{ + LoggerD("entered"); +} + +SEConverter::~SEConverter() +{ + LoggerD("entered"); +} + + +JSValueRef SEConverter::toJSValueRef(const std::vector<unsigned char>& arg) { + JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL); + + if (NULL == jsResult) { + ThrowMsg(Commons::UnknownException, "Could not create js array object"); + } + + for (size_t i = 0; i < arg.size(); ++i) { + JSValueRef tmpVal = JSValueMakeNumber(m_context, arg[i]); + if (!JSSetArrayElement(m_context, jsResult, i, tmpVal)) { + ThrowMsg(Commons::UnknownException, "Could not insert value into js array"); + } + } + + return jsResult; +} + +JSValueRef SEConverter::makeSeErrorObject(std::string error, std::string message) { + return JSWebAPIErrorFactory::makeErrorObject(m_context, error, message); +} + +} +} |