1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "jerryscript_native_number.h"
17
JerryScriptNativeNumber(JerryScriptNativeEngine * engine,double value)18 JerryScriptNativeNumber::JerryScriptNativeNumber(JerryScriptNativeEngine* engine, double value)
19 : JerryScriptNativeNumber(engine, jerry_create_number((double)value))
20 {
21 }
22
JerryScriptNativeNumber(JerryScriptNativeEngine * engine,jerry_value_t value)23 JerryScriptNativeNumber::JerryScriptNativeNumber(JerryScriptNativeEngine* engine, jerry_value_t value)
24 : JerryScriptNativeValue(engine, value)
25 {
26 }
27
~JerryScriptNativeNumber()28 JerryScriptNativeNumber::~JerryScriptNativeNumber() {}
29
GetInterface(int interfaceId)30 void* JerryScriptNativeNumber::GetInterface(int interfaceId)
31 {
32 return (NativeNumber::INTERFACE_ID == interfaceId) ? (NativeNumber*)this : nullptr;
33 }
34
operator int32_t()35 JerryScriptNativeNumber::operator int32_t()
36 {
37 return (int32_t)jerry_get_number_value(value_);
38 }
39
operator uint32_t()40 JerryScriptNativeNumber::operator uint32_t()
41 {
42 return (uint32_t)jerry_get_number_value(value_);
43 }
44
operator int64_t()45 JerryScriptNativeNumber::operator int64_t()
46 {
47 return (int64_t)jerry_get_number_value(value_);
48 }
49
operator double()50 JerryScriptNativeNumber::operator double()
51 {
52 return (double)jerry_get_number_value(value_);
53 }
54