/* * Tencent is pleased to support the open source community by making ScriptX available. * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. * * 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 namespace script { #define REF_IMPL_BASIC_FUNC(ValueType) \ Local::Local(const Local& copy) : val_(copy.val_) {} \ Local::Local(Local&& move) noexcept : val_(move.val_) {} \ Local::~Local() {} \ Local& Local::operator=(const Local& from) { \ Local(from).swap(*this); \ return *this; \ } \ Local& Local::operator=(Local&& move) noexcept { \ Local(std::move(move)).swap(*this); \ return *this; \ } \ void Local::swap(Local& rhs) noexcept { std::swap(val_, rhs.val_); } #define REF_IMPL_BASIC_EQUALS(ValueType) \ bool Local::operator==(const script::Local& other) const { \ return asValue() == other; \ } #define REF_IMPL_BASIC_NOT_VALUE(ValueType) \ Local::Local(InternalLocalRef val) : val_(val) {} \ Local Local::describe() const { return asValue().describe(); } \ std::string Local::describeUtf8() const { return asValue().describeUtf8(); } #define REF_IMPL_TO_VALUE(ValueType) \ Local Local::asValue() const { return Local(/*TMPL: value*/); } REF_IMPL_BASIC_FUNC(Value) REF_IMPL_BASIC_FUNC(Object) REF_IMPL_BASIC_NOT_VALUE(Object) REF_IMPL_BASIC_EQUALS(Object) REF_IMPL_TO_VALUE(Object) REF_IMPL_BASIC_FUNC(String) REF_IMPL_BASIC_NOT_VALUE(String) REF_IMPL_BASIC_EQUALS(String) REF_IMPL_TO_VALUE(String) REF_IMPL_BASIC_FUNC(Number) REF_IMPL_BASIC_NOT_VALUE(Number) REF_IMPL_BASIC_EQUALS(Number) REF_IMPL_TO_VALUE(Number) REF_IMPL_BASIC_FUNC(Boolean) REF_IMPL_BASIC_NOT_VALUE(Boolean) REF_IMPL_BASIC_EQUALS(Boolean) REF_IMPL_TO_VALUE(Boolean) REF_IMPL_BASIC_FUNC(Function) REF_IMPL_BASIC_NOT_VALUE(Function) REF_IMPL_BASIC_EQUALS(Function) REF_IMPL_TO_VALUE(Function) REF_IMPL_BASIC_FUNC(Array) REF_IMPL_BASIC_NOT_VALUE(Array) REF_IMPL_BASIC_EQUALS(Array) REF_IMPL_TO_VALUE(Array) REF_IMPL_BASIC_FUNC(ByteBuffer) REF_IMPL_BASIC_NOT_VALUE(ByteBuffer) REF_IMPL_BASIC_EQUALS(ByteBuffer) REF_IMPL_TO_VALUE(ByteBuffer) REF_IMPL_BASIC_FUNC(Unsupported) REF_IMPL_BASIC_NOT_VALUE(Unsupported) REF_IMPL_BASIC_EQUALS(Unsupported) REF_IMPL_TO_VALUE(Unsupported) // ==== value ==== Local::Local() noexcept : val_() {} Local::Local(InternalLocalRef v8Local) : val_(v8Local) {} bool Local::isNull() const { return false; } void Local::reset() {} ValueKind Local::getKind() const { if (isNull()) { return ValueKind::kNull; } else if (isString()) { return ValueKind::kString; } else if (isNumber()) { return ValueKind::kNumber; } else if (isBoolean()) { return ValueKind::kBoolean; } else if (isFunction()) { return ValueKind::kFunction; } else if (isArray()) { return ValueKind::kArray; } else if (isByteBuffer()) { return ValueKind::kByteBuffer; } else if (isObject()) { return ValueKind::kObject; } else { return ValueKind::kUnsupported; } } bool Local::isString() const { return false; } bool Local::isNumber() const { return false; } bool Local::isBoolean() const { return false; } bool Local::isFunction() const { return false; } bool Local::isArray() const { return false; } bool Local::isByteBuffer() const { return false; } bool Local::isObject() const { return false; } bool Local::isUnsupported() const { return false; } Local Local::asString() const { throw Exception("can't cast value as String"); } Local Local::asNumber() const { throw Exception("can't cast value as Number"); } Local Local::asBoolean() const { throw Exception("can't cast value as Boolean"); } Local Local::asFunction() const { throw Exception("can't cast value as Function"); } Local Local::asArray() const { throw Exception("can't cast value as Array"); } Local Local::asByteBuffer() const { throw Exception("can't cast value as ByteBuffer"); } Local Local::asObject() const { throw Exception("can't cast value as Object"); } Local Local::asUnsupported() const { throw Exception("can't cast value as Unsupported"); } bool Local::operator==(const script::Local& other) const { return false; } Local Local::describe() const { TEMPLATE_NOT_IMPLEMENTED(); } Local Local::get(const script::Local& key) const { return {}; } void Local::set(const script::Local& key, const script::Local& value) const {} void Local::remove(const Local& key) const {} bool Local::has(const Local& key) const { return true; } bool Local::instanceOf(const Local& type) const { return false; } std::vector> Local::getKeys() const { return {}; } float Local::toFloat() const { return static_cast(toDouble()); } double Local::toDouble() const { return 0; } int32_t Local::toInt32() const { return static_cast(toDouble()); } int64_t Local::toInt64() const { return static_cast(toDouble()); } bool Local::value() const { return false; } Local Local::callImpl(const Local& thiz, size_t size, const Local* args) const { return {}; } size_t Local::size() const { return 0; } Local Local::get(size_t index) const { return {}; } void Local::set(size_t index, const script::Local& value) const {} void Local::add(const script::Local& value) const { set(size(), value); } void Local::clear() const {} ByteBuffer::Type Local::getType() const { return ByteBuffer::Type::KFloat32; } bool Local::isShared() const { return true; } void Local::commit() const {} void Local::sync() const {} size_t Local::byteLength() const { return 0; } void* Local::getRawBytes() const { return nullptr; } std::shared_ptr Local::getRawBytesShared() const { return {}; } } // namespace script