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 MarkModuleCollectable(EcmaRuntimeCallInfo *msg); 46 static JSTaggedValue CallJsBoundFunction(EcmaRuntimeCallInfo *msg); 47 static JSTaggedValue CallJsProxy(EcmaRuntimeCallInfo *msg); 48 #if ECMASCRIPT_ENABLE_RUNTIME_STAT 49 static JSTaggedValue StartRuntimeStat(EcmaRuntimeCallInfo *msg); 50 static JSTaggedValue StopRuntimeStat(EcmaRuntimeCallInfo *msg); 51 #endif 52 53 #if ECMASCRIPT_ENABLE_OPT_CODE_PROFILER 54 static JSTaggedValue PrintOptStat(EcmaRuntimeCallInfo *msg); 55 #endif 56 57 #if ECMASCRIPT_ENABLE_FUNCTION_CALL_TIMER 58 static JSTaggedValue PrintFunctionCallStat(EcmaRuntimeCallInfo *msg); 59 #endif 60 61 private: 62 static void PrintString(JSThread *thread, EcmaString *string); 63 static void PrintValue(int64_t value, int64_t tag); 64 static JSTaggedValue Encode(JSThread *thread, const JSHandle<EcmaString> &str, judgURIFunc IsInURISet); 65 static JSTaggedValue Decode(JSThread *thread, const JSHandle<EcmaString> &str, judgURIFunc IsInURISet); 66 static bool IsUnescapedURI(uint16_t ch); 67 static bool IsInUnescapedURISet(uint16_t ch); 68 static bool IsInReservedURISet(uint16_t ch); 69 static bool IsReservedURI(uint16_t ch); 70 static bool IsInMarkURISet(uint16_t ch); 71 static bool IsHexDigits(uint16_t ch); 72 static uint8_t GetValueFromTwoHex(uint16_t front, uint16_t behind); 73 }; 74 } // namespace panda::ecmascript::builtins 75 76 #endif // ECMASCRIPT_BUILTINS_BUILTINS_ERROR_H 77