• 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_BUILTINS_BUILTINS_GLOBAL_H
17 #define ECMASCRIPT_BUILTINS_BUILTINS_GLOBAL_H
18 
19 #include "ecmascript/base/builtins_base.h"
20 #include "ecmascript/js_thread.h"
21 
22 namespace panda::ecmascript::builtins {
23 static constexpr uint8_t BIT_MASK = 0x0F;
24 static constexpr uint8_t BIT_MASK_FF = 0xFF;
25 static constexpr uint16_t BIT16_MASK = 0x3FF;
26 static constexpr uint8_t BIT_MASK_ONE = 0x80;
27 static constexpr uint8_t BIT_MASK_TWO = 0xC0;
28 using judgURIFunc = bool (*)(uint16_t);
29 
30 class BuiltinsGlobal : public base::BuiltinsBase {
31 public:
32     // 18.2.1
33     static JSTaggedValue NotSupportEval(EcmaRuntimeCallInfo *msg);
34     // 18.2.2
35     static JSTaggedValue IsFinite(EcmaRuntimeCallInfo *msg);
36     // 18.2.3
37     static JSTaggedValue IsNaN(EcmaRuntimeCallInfo *msg);
38     // 18.2.6
39     static JSTaggedValue DecodeURI(EcmaRuntimeCallInfo *msg);
40     static JSTaggedValue EncodeURI(EcmaRuntimeCallInfo *msg);
41     static JSTaggedValue DecodeURIComponent(EcmaRuntimeCallInfo *msg);
42     static JSTaggedValue EncodeURIComponent(EcmaRuntimeCallInfo *msg);
43 
44     static JSTaggedValue PrintEntrypoint(EcmaRuntimeCallInfo *msg);
45     static JSTaggedValue CallJsBoundFunction(EcmaRuntimeCallInfo *msg);
46     static JSTaggedValue CallJsProxy(EcmaRuntimeCallInfo *msg);
47 #if ECMASCRIPT_ENABLE_RUNTIME_STAT
48     static JSTaggedValue StartRuntimeStat(EcmaRuntimeCallInfo *msg);
49     static JSTaggedValue StopRuntimeStat(EcmaRuntimeCallInfo *msg);
50 #endif
51 
52 private:
53     static void PrintString(JSThread *thread, EcmaString *string);
54     static void PrintValue(int64_t value, int64_t tag);
55     static JSTaggedValue Encode(JSThread *thread, const JSHandle<EcmaString> &str, judgURIFunc IsInURISet);
56     static JSTaggedValue Decode(JSThread *thread, const JSHandle<EcmaString> &str, judgURIFunc IsInURISet);
57     static bool IsUnescapedURI(uint16_t ch);
58     static bool IsInUnescapedURISet(uint16_t ch);
59     static bool IsInReservedURISet(uint16_t ch);
60     static bool IsReservedURI(uint16_t ch);
61     static bool IsInMarkURISet(uint16_t ch);
62     static bool IsHexDigits(uint16_t ch);
63     static uint8_t GetValueFromTwoHex(uint16_t front, uint16_t behind);
64 };
65 }  // namespace panda::ecmascript::builtins
66 
67 #endif  // ECMASCRIPT_BUILTINS_BUILTINS_ERROR_H
68