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_FUNCTION_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_BUILTINS_BUILTINS_FUNCTION_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include "ecmascript/base/builtins_base.h" 204514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value-inl.h" 214514f5e3Sopenharmony_ci 224514f5e3Sopenharmony_ci#define BUILTIN_FUNCTION_PROTOTYPE_FUNCTIONS(V) \ 234514f5e3Sopenharmony_ci /* Function.prototype.apply ( thisArg, argArray ) */ \ 244514f5e3Sopenharmony_ci V("apply", FunctionPrototypeApply, 2, FunctionPrototypeApply) \ 254514f5e3Sopenharmony_ci /* Function.prototype.bind ( thisArg , ...args) */ \ 264514f5e3Sopenharmony_ci V("bind", FunctionPrototypeBind, 1, FunctionPrototypeBind) \ 274514f5e3Sopenharmony_ci /* Function.prototype.call (thisArg , ...args) */ \ 284514f5e3Sopenharmony_ci V("call", FunctionPrototypeCall, 1, FunctionPrototypeCall) 294514f5e3Sopenharmony_ci 304514f5e3Sopenharmony_cinamespace panda::ecmascript::builtins { 314514f5e3Sopenharmony_ciusing BuiltinsPropertyConfig = base::BuiltinsPropertyConfig; 324514f5e3Sopenharmony_ciclass BuiltinsFunction : public base::BuiltinsBase { 334514f5e3Sopenharmony_cipublic: 344514f5e3Sopenharmony_ci // ecma 19.2.1 Function (p1, p2, ... , pn, body) 354514f5e3Sopenharmony_ci static JSTaggedValue FunctionConstructor(EcmaRuntimeCallInfo *argv); 364514f5e3Sopenharmony_ci 374514f5e3Sopenharmony_ci // ecma 19.2.3 The Function prototype object is itself a built-in function object. 384514f5e3Sopenharmony_ci static JSTaggedValue FunctionPrototypeInvokeSelf(EcmaRuntimeCallInfo *argv); 394514f5e3Sopenharmony_ci 404514f5e3Sopenharmony_ci // ecma 19.2.3.1 Function.prototype.apply (thisArg, argArray) 414514f5e3Sopenharmony_ci static JSTaggedValue FunctionPrototypeApply(EcmaRuntimeCallInfo *argv); 424514f5e3Sopenharmony_ci static JSTaggedValue FunctionPrototypeApplyInternal(JSThread *thread, JSHandle<JSTaggedValue> func, 434514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> thisArg, 444514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> arrayObj); 454514f5e3Sopenharmony_ci 464514f5e3Sopenharmony_ci // ecma 19.2.3.2 Function.prototype.bind (thisArg , ...args) 474514f5e3Sopenharmony_ci static JSTaggedValue FunctionPrototypeBind(EcmaRuntimeCallInfo *argv); 484514f5e3Sopenharmony_ci static JSTaggedValue FunctionPrototypeBindInternal(JSThread *thread, JSHandle<JSTaggedValue> target, 494514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> thisArg, 504514f5e3Sopenharmony_ci JSHandle<TaggedArray> argsArray); 514514f5e3Sopenharmony_ci 524514f5e3Sopenharmony_ci // ecma 19.2.3.3 Function.prototype.call (thisArg , ...args) 534514f5e3Sopenharmony_ci static JSTaggedValue FunctionPrototypeCall(EcmaRuntimeCallInfo *argv); 544514f5e3Sopenharmony_ci 554514f5e3Sopenharmony_ci // ecma 19.2.3.5 Function.prototype.toString () 564514f5e3Sopenharmony_ci static JSTaggedValue FunctionPrototypeToString(EcmaRuntimeCallInfo *argv); 574514f5e3Sopenharmony_ci 584514f5e3Sopenharmony_ci // ecma 19.2.3.6 Function.prototype[@@hasInstance] (V) 594514f5e3Sopenharmony_ci static JSTaggedValue FunctionPrototypeHasInstance(EcmaRuntimeCallInfo *argv); 604514f5e3Sopenharmony_ci 614514f5e3Sopenharmony_ci static Span<const BuiltinsPropertyConfig> GetFunctionPrototypeProperties() 624514f5e3Sopenharmony_ci { 634514f5e3Sopenharmony_ci return Span<const BuiltinsPropertyConfig>(FUNCTION_PROTOTYPE_PROPERTIES); 644514f5e3Sopenharmony_ci } 654514f5e3Sopenharmony_ci 664514f5e3Sopenharmony_ci static Span<const BuiltinsPropertyConfig> GetFunctionProperties() 674514f5e3Sopenharmony_ci { 684514f5e3Sopenharmony_ci return Span<const BuiltinsPropertyConfig>(FUNCTION_PROPERTIES); 694514f5e3Sopenharmony_ci } 704514f5e3Sopenharmony_ci 714514f5e3Sopenharmony_ci static Span<const base::BuiltinFunctionEntry> GetFunctionPrototypeFunctions() 724514f5e3Sopenharmony_ci { 734514f5e3Sopenharmony_ci return Span<const base::BuiltinFunctionEntry>(FUNCTION_PROTOTYPE_FUNCTIONS); 744514f5e3Sopenharmony_ci } 754514f5e3Sopenharmony_ciprivate: 764514f5e3Sopenharmony_ci static constexpr std::array FUNCTION_PROTOTYPE_PROPERTIES = { 774514f5e3Sopenharmony_ci BuiltinsPropertyConfig("length", false, false, false, true), 784514f5e3Sopenharmony_ci BuiltinsPropertyConfig("name", false, false, false, true), 794514f5e3Sopenharmony_ci BuiltinsPropertyConfig("constructor", false, true, false, true), 804514f5e3Sopenharmony_ci BuiltinsPropertyConfig("caller", true, false, false, true), 814514f5e3Sopenharmony_ci BuiltinsPropertyConfig("arguments", true, false, false, true), 824514f5e3Sopenharmony_ci BuiltinsPropertyConfig("apply", false, true, false, true), 834514f5e3Sopenharmony_ci BuiltinsPropertyConfig("bind", false, true, false, true), 844514f5e3Sopenharmony_ci BuiltinsPropertyConfig("call", false, true, false, true), 854514f5e3Sopenharmony_ci BuiltinsPropertyConfig("toString", false, true, false, true), 864514f5e3Sopenharmony_ci BuiltinsPropertyConfig("[Symbol.hasInstance]", false, false, false, false), 874514f5e3Sopenharmony_ci }; 884514f5e3Sopenharmony_ci 894514f5e3Sopenharmony_ci static constexpr std::array FUNCTION_PROPERTIES = { 904514f5e3Sopenharmony_ci BuiltinsPropertyConfig("length", false, false, false, true), 914514f5e3Sopenharmony_ci BuiltinsPropertyConfig("name", false, false, false, true), 924514f5e3Sopenharmony_ci BuiltinsPropertyConfig("prototype", false, false, false, false), 934514f5e3Sopenharmony_ci }; 944514f5e3Sopenharmony_ci 954514f5e3Sopenharmony_ci#define BUILTIN_FUNCTION_FUNCTION_ENTRY(name, func, length, id) \ 964514f5e3Sopenharmony_ci base::BuiltinFunctionEntry::Create(name, BuiltinsFunction::func, length, kungfu::BuiltinsStubCSigns::id), 974514f5e3Sopenharmony_ci 984514f5e3Sopenharmony_ci static constexpr std::array FUNCTION_PROTOTYPE_FUNCTIONS = { 994514f5e3Sopenharmony_ci BUILTIN_FUNCTION_PROTOTYPE_FUNCTIONS(BUILTIN_FUNCTION_FUNCTION_ENTRY) 1004514f5e3Sopenharmony_ci }; 1014514f5e3Sopenharmony_ci#undef BUILTIN_FUNCTION_FUNCTION_ENTRY 1024514f5e3Sopenharmony_ci}; 1034514f5e3Sopenharmony_ci} // namespace panda::ecmascript::builtins 1044514f5e3Sopenharmony_ci#endif // ECMASCRIPT_BUILTINS_BUILTINS_FUNCTION_H 105