* Copyright (c) 2021 Huawei Device 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.
*/
#ifndef ECMASCRIPT_BUILTINS_BUILTINS_FUNCTION_H
#define ECMASCRIPT_BUILTINS_BUILTINS_FUNCTION_H
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/js_tagged_value-inl.h"
#define BUILTIN_FUNCTION_PROTOTYPE_FUNCTIONS(V) \
\
V("apply", FunctionPrototypeApply, 2, FunctionPrototypeApply) \
\
V("bind", FunctionPrototypeBind, 1, FunctionPrototypeBind) \
\
V("call", FunctionPrototypeCall, 1, FunctionPrototypeCall)
namespace panda::ecmascript::builtins {
using BuiltinsPropertyConfig = base::BuiltinsPropertyConfig;
class BuiltinsFunction : public base::BuiltinsBase {
public:
static JSTaggedValue FunctionConstructor(EcmaRuntimeCallInfo *argv);
static JSTaggedValue FunctionPrototypeInvokeSelf(EcmaRuntimeCallInfo *argv);
static JSTaggedValue FunctionPrototypeApply(EcmaRuntimeCallInfo *argv);
static JSTaggedValue FunctionPrototypeApplyInternal(JSThread *thread, JSHandle<JSTaggedValue> func,
JSHandle<JSTaggedValue> thisArg,
JSHandle<JSTaggedValue> arrayObj);
static JSTaggedValue FunctionPrototypeBind(EcmaRuntimeCallInfo *argv);
static JSTaggedValue FunctionPrototypeBindInternal(JSThread *thread, JSHandle<JSTaggedValue> target,
JSHandle<JSTaggedValue> thisArg,
JSHandle<TaggedArray> argsArray);
static JSTaggedValue FunctionPrototypeCall(EcmaRuntimeCallInfo *argv);
static JSTaggedValue FunctionPrototypeToString(EcmaRuntimeCallInfo *argv);
static JSTaggedValue FunctionPrototypeHasInstance(EcmaRuntimeCallInfo *argv);
static Span<const BuiltinsPropertyConfig> GetFunctionPrototypeProperties()
{
return Span<const BuiltinsPropertyConfig>(FUNCTION_PROTOTYPE_PROPERTIES);
}
static Span<const BuiltinsPropertyConfig> GetFunctionProperties()
{
return Span<const BuiltinsPropertyConfig>(FUNCTION_PROPERTIES);
}
static Span<const base::BuiltinFunctionEntry> GetFunctionPrototypeFunctions()
{
return Span<const base::BuiltinFunctionEntry>(FUNCTION_PROTOTYPE_FUNCTIONS);
}
private:
static constexpr std::array FUNCTION_PROTOTYPE_PROPERTIES = {
BuiltinsPropertyConfig("length", false, false, false, true),
BuiltinsPropertyConfig("name", false, false, false, true),
BuiltinsPropertyConfig("constructor", false, true, false, true),
BuiltinsPropertyConfig("caller", true, false, false, true),
BuiltinsPropertyConfig("arguments", true, false, false, true),
BuiltinsPropertyConfig("apply", false, true, false, true),
BuiltinsPropertyConfig("bind", false, true, false, true),
BuiltinsPropertyConfig("call", false, true, false, true),
BuiltinsPropertyConfig("toString", false, true, false, true),
BuiltinsPropertyConfig("[Symbol.hasInstance]", false, false, false, false),
};
static constexpr std::array FUNCTION_PROPERTIES = {
BuiltinsPropertyConfig("length", false, false, false, true),
BuiltinsPropertyConfig("name", false, false, false, true),
BuiltinsPropertyConfig("prototype", false, false, false, false),
};
#define BUILTIN_FUNCTION_FUNCTION_ENTRY(name, func, length, id) \
base::BuiltinFunctionEntry::Create(name, BuiltinsFunction::func, length, BUILTINS_STUB_ID(id)),
static constexpr std::array FUNCTION_PROTOTYPE_FUNCTIONS = {
BUILTIN_FUNCTION_PROTOTYPE_FUNCTIONS(BUILTIN_FUNCTION_FUNCTION_ENTRY)
};
#undef BUILTIN_FUNCTION_FUNCTION_ENTRY
};
}
#endif