14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_BUILTINS_BUILTINS_BIGINT_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_BUILTINS_BUILTINS_BIGINT_H
184514f5e3Sopenharmony_ci
194514f5e3Sopenharmony_ci#include "ecmascript/base/builtins_base.h"
204514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value.h"
214514f5e3Sopenharmony_ci
224514f5e3Sopenharmony_ci// List of functions in BigInt, excluding the constructor and '@@' properties.
234514f5e3Sopenharmony_ci// V(name, func, length, stubIndex)
244514f5e3Sopenharmony_ci// where BuiltinsBigInt::func refers to the native implementation of BigInt[name].
254514f5e3Sopenharmony_ci//       kungfu::BuiltinsStubCSigns::stubIndex refers to the builtin stub index, or INVALID if no stub available.
264514f5e3Sopenharmony_ci#define BUILTIN_BIGINT_FUNCTIONS(V)                                         \
274514f5e3Sopenharmony_ci    /* BigInt.asIntN (bits, bigint) */                                      \
284514f5e3Sopenharmony_ci    V("asIntN", AsIntN, 2, BigIntAsIntN)                                    \
294514f5e3Sopenharmony_ci    /* BigInt.asUintN ( bits, bigint ) */                                   \
304514f5e3Sopenharmony_ci    V("asUintN", AsUintN, 2, BigIntAsUintN)
314514f5e3Sopenharmony_ci// List of functions in BigInt.prototype, excluding the constructor and '@@' properties.
324514f5e3Sopenharmony_ci// V(name, func, length, stubIndex)
334514f5e3Sopenharmony_ci// where BuiltinsBigInt::func refers to the native implementation of BigInt.prototype[name].
344514f5e3Sopenharmony_ci//       kungfu::BuiltinsStubCSigns::stubIndex refers to the builtin stub index, or INVALID if no stub available.
354514f5e3Sopenharmony_ci#define BUILTIN_BIGINT_PROTOTYPE_FUNCTIONS(V)                               \
364514f5e3Sopenharmony_ci    /* BigInt.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) */           \
374514f5e3Sopenharmony_ci    V("toLocaleString", ToLocaleString, 0, INVALID)                         \
384514f5e3Sopenharmony_ci    /* BigInt.toString ( [radix] ) */                                       \
394514f5e3Sopenharmony_ci    V("toString", ToString, 0, INVALID)                                     \
404514f5e3Sopenharmony_ci    /* BigInt.valueOf ( ) */                                                \
414514f5e3Sopenharmony_ci    V("valueOf", ValueOf, 0, INVALID)
424514f5e3Sopenharmony_ci
434514f5e3Sopenharmony_cinamespace panda::ecmascript::builtins {
444514f5e3Sopenharmony_ciclass BuiltinsBigInt : public base::BuiltinsBase {
454514f5e3Sopenharmony_cipublic:
464514f5e3Sopenharmony_ci    // 21.2.1.1
474514f5e3Sopenharmony_ci    static JSTaggedValue BigIntConstructor(EcmaRuntimeCallInfo *argv);
484514f5e3Sopenharmony_ci    static JSTaggedValue BigIntConstructorInternal(JSThread *thread, JSHandle<JSTaggedValue> value);
494514f5e3Sopenharmony_ci    // 21.2.2.1
504514f5e3Sopenharmony_ci    static JSTaggedValue AsIntN(EcmaRuntimeCallInfo *argv);
514514f5e3Sopenharmony_ci    // 21.2.2.2
524514f5e3Sopenharmony_ci    static JSTaggedValue AsUintN(EcmaRuntimeCallInfo *argv);
534514f5e3Sopenharmony_ci    // 21.2.3.2
544514f5e3Sopenharmony_ci    static JSTaggedValue ToLocaleString(EcmaRuntimeCallInfo *argv);
554514f5e3Sopenharmony_ci    // 21.2.3.3
564514f5e3Sopenharmony_ci    static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv);
574514f5e3Sopenharmony_ci    // 21.2.3.4
584514f5e3Sopenharmony_ci    static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv);
594514f5e3Sopenharmony_ciprivate:
604514f5e3Sopenharmony_ci    static JSTaggedValue ThisBigIntValue(EcmaRuntimeCallInfo *argv);
614514f5e3Sopenharmony_ci
624514f5e3Sopenharmony_cipublic:
634514f5e3Sopenharmony_ci    // Excluding the constructor and '@@' internal properties.
644514f5e3Sopenharmony_ci    static Span<const base::BuiltinFunctionEntry> GetBigIntFunctions()
654514f5e3Sopenharmony_ci    {
664514f5e3Sopenharmony_ci        return Span<const base::BuiltinFunctionEntry>(BIGINT_FUNCTIONS);
674514f5e3Sopenharmony_ci    }
684514f5e3Sopenharmony_ci
694514f5e3Sopenharmony_ci    // Excluding the constructor and '@@' internal properties.
704514f5e3Sopenharmony_ci    static Span<const base::BuiltinFunctionEntry> GetBigIntPrototypeFunctions()
714514f5e3Sopenharmony_ci    {
724514f5e3Sopenharmony_ci        return Span<const base::BuiltinFunctionEntry>(BIGINT_PROTOTYPE_FUNCTIONS);
734514f5e3Sopenharmony_ci    }
744514f5e3Sopenharmony_ci
754514f5e3Sopenharmony_ciprivate:
764514f5e3Sopenharmony_ci#define BUILTIN_BIGINT_FUNCTION_ENTRY(name, func, length, builtinId) \
774514f5e3Sopenharmony_ci    base::BuiltinFunctionEntry::Create(name, BuiltinsBigInt::func, length, kungfu::BuiltinsStubCSigns::builtinId),
784514f5e3Sopenharmony_ci
794514f5e3Sopenharmony_ci    static inline std::array BIGINT_FUNCTIONS = {
804514f5e3Sopenharmony_ci        BUILTIN_BIGINT_FUNCTIONS(BUILTIN_BIGINT_FUNCTION_ENTRY)
814514f5e3Sopenharmony_ci    };
824514f5e3Sopenharmony_ci    static inline std::array BIGINT_PROTOTYPE_FUNCTIONS = {
834514f5e3Sopenharmony_ci        BUILTIN_BIGINT_PROTOTYPE_FUNCTIONS(BUILTIN_BIGINT_FUNCTION_ENTRY)
844514f5e3Sopenharmony_ci    };
854514f5e3Sopenharmony_ci#undef BUILTIN_BIGINT_FUNCTION_ENTRY
864514f5e3Sopenharmony_ci};
874514f5e3Sopenharmony_ci}  // namespace panda::ecmascript::builtins
884514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_BUILTINS_BUILTINS_BIGINT_H