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 "ark_native_boolean.h"
17
18 using panda::BooleanRef;
ArkNativeBoolean(ArkNativeEngine * engine,Local<JSValueRef> value)19 ArkNativeBoolean::ArkNativeBoolean(ArkNativeEngine* engine, Local<JSValueRef> value) : ArkNativeValue(engine, value) {}
20
ArkNativeBoolean(ArkNativeEngine * engine,bool value)21 ArkNativeBoolean::ArkNativeBoolean(ArkNativeEngine* engine, bool value)
22 : ArkNativeBoolean(engine, JSValueRef::Undefined(engine->GetEcmaVm()))
23 {
24 auto vm = engine->GetEcmaVm();
25 LocalScope scope(vm);
26 Local<BooleanRef> object = BooleanRef::New(vm, value);
27 value_ = Global<JSValueRef>(vm, object);
28 }
29
~ArkNativeBoolean()30 ArkNativeBoolean::~ArkNativeBoolean() {}
31
GetInterface(int interfaceId)32 void* ArkNativeBoolean::GetInterface(int interfaceId)
33 {
34 return (NativeBoolean::INTERFACE_ID == interfaceId) ? (NativeBoolean*)this : nullptr;
35 }
36
operator bool()37 ArkNativeBoolean::operator bool()
38 {
39 auto vm = engine_->GetEcmaVm();
40 LocalScope scope(vm);
41 Global<BooleanRef> value = value_;
42 return value->Value();
43 }
44