• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ECMASCRIPT_BASE_BUILTINS_BASE_H
17 #define ECMASCRIPT_BASE_BUILTINS_BASE_H
18 
19 #include "ecmascript/base/string_helper.h"
20 #include "ecmascript/ecma_runtime_call_info.h"
21 #include "ecmascript/ecma_string.h"
22 #include "ecmascript/ecma_vm.h"
23 #include "ecmascript/global_env_constants-inl.h"
24 #include "ecmascript/js_symbol.h"
25 #include "ecmascript/js_tagged_value.h"
26 #include "ecmascript/object_factory.h"
27 #include "ecmascript/runtime_call_id.h"
28 #include "ecmascript/tagged_array.h"
29 
30 namespace panda::ecmascript {
31 class JSArray;
32 namespace base {
33 class BuiltinsBase {
34 public:
35     enum ArgsPosition : uint32_t { FIRST = 0, SECOND, THIRD, FOURTH, FIFTH };
36     static JSHandle<TaggedArray> GetArgsArray(EcmaRuntimeCallInfo *msg);
GetConstructor(EcmaRuntimeCallInfo * msg)37     static inline JSHandle<JSTaggedValue> GetConstructor(EcmaRuntimeCallInfo *msg)
38     {
39         return msg->GetFunction();
40     }
41 
GetThis(EcmaRuntimeCallInfo * msg)42     static inline JSHandle<JSTaggedValue> GetThis(EcmaRuntimeCallInfo *msg)
43     {
44         return msg->GetThis();
45     }
46 
GetNewTarget(EcmaRuntimeCallInfo * msg)47     static inline JSHandle<JSTaggedValue> GetNewTarget(EcmaRuntimeCallInfo *msg)
48     {
49         return msg->GetNewTarget();
50     }
51 
GetCallArg(EcmaRuntimeCallInfo * msg,uint32_t position)52     static inline JSHandle<JSTaggedValue> GetCallArg(EcmaRuntimeCallInfo *msg, uint32_t position)
53     {
54         if (position >= msg->GetArgsNumber()) {
55             JSThread *thread = msg->GetThread();
56             return thread->GlobalConstants()->GetHandledUndefined();
57         }
58         return msg->GetCallArg(position);
59     }
60 
GetTaggedInt(int32_t value)61     static inline JSTaggedValue GetTaggedInt(int32_t value)
62     {
63         return JSTaggedValue(value);
64     }
65 
GetTaggedDouble(double value)66     static inline JSTaggedValue GetTaggedDouble(double value)
67     {
68         return JSTaggedValue(value);
69     }
70 
GetTaggedBoolean(bool value)71     static inline JSTaggedValue GetTaggedBoolean(bool value)
72     {
73         return JSTaggedValue(value);
74     }
75 
GetTaggedString(JSThread * thread,const char * str)76     static inline JSTaggedValue GetTaggedString(JSThread *thread, const char *str)
77     {
78         return thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str).GetTaggedValue();
79     }
80 };
81 }  // namespace base
82 }  // namespace panda::ecmascript
83 
84 #endif  // ECMASCRIPT_BASE_BUILTINS_BASE_H
85