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#include "ecmascript/global_env.h" 17 18#include "ecmascript/global_dictionary.h" 19#include "ecmascript/symbol_table.h" 20#include "ecmascript/ecma_string_table.h" 21#include "ecmascript/template_map.h" 22 23namespace panda::ecmascript { 24void GlobalEnv::Init(JSThread *thread) 25{ 26 SetRegisterSymbols(thread, SymbolTable::Create(thread)); 27 SetGlobalRecord(thread, GlobalDictionary::Create(thread)); 28 JSTaggedValue emptyStr = thread->GlobalConstants()->GetEmptyString(); 29 EcmaStringTable *stringTable = thread->GetEcmaVM()->GetEcmaStringTable(); 30 stringTable->InternEmptyString(thread, EcmaString::Cast(emptyStr.GetTaggedObject())); 31 SetTemplateMap(thread, TemplateMap::Create(thread)); 32 SetObjectLiteralHClassCache(thread, JSTaggedValue::Hole()); 33 SetJsonObjectHclassCache(thread, JSTaggedValue::Hole()); 34 SetJSThread(thread); 35} 36JSHandle<JSTaggedValue> GlobalEnv::GetSymbol(JSThread *thread, const JSHandle<JSTaggedValue> &string) 37{ 38 JSHandle<JSTaggedValue> symbolFunction(GetSymbolFunction()); 39 return JSObject::GetProperty(thread, symbolFunction, string).GetValue(); 40} 41 42JSHandle<JSTaggedValue> GlobalEnv::GetStringPrototypeFunctionByName(JSThread *thread, const char *name) 43{ 44 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); 45 JSHandle<JSTaggedValue> stringFuncPrototype(thread, 46 JSObject::GetPrototype(JSHandle<JSObject>(GetStringFunction()))); 47 JSHandle<JSTaggedValue> nameKey(factory->NewFromUtf8(name)); 48 return JSObject::GetProperty(thread, stringFuncPrototype, nameKey).GetValue(); 49} 50 51JSHandle<JSTaggedValue> GlobalEnv::GetStringFunctionByName(JSThread *thread, const char *name) 52{ 53 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); 54 JSHandle<JSTaggedValue> stringFuncObj = GetStringFunction(); 55 JSHandle<JSTaggedValue> nameKey(factory->NewFromUtf8(name)); 56 return JSObject::GetProperty(thread, stringFuncObj, nameKey).GetValue(); 57} 58} // namespace panda::ecmascript 59