2021-09-04 08:06:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-12-24 10:37:44 +00:00
|
|
|
#include "ecmascript/global_env.h"
|
2022-03-26 09:00:26 +00:00
|
|
|
|
|
|
|
#include "ecmascript/global_dictionary.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/builtins/builtins_promise_handler.h"
|
|
|
|
#include "ecmascript/ic/ic_handler.h"
|
|
|
|
#include "ecmascript/ic/proto_change_details.h"
|
|
|
|
#include "ecmascript/jobs/micro_job_queue.h"
|
2022-04-05 13:28:18 +00:00
|
|
|
#include "ecmascript/jspandafile/program_object.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/js_generator_object.h"
|
|
|
|
#include "ecmascript/js_handle.h"
|
|
|
|
#include "ecmascript/js_promise.h"
|
|
|
|
#include "ecmascript/object_factory.h"
|
2022-03-26 09:00:26 +00:00
|
|
|
#include "ecmascript/symbol_table.h"
|
2022-05-11 09:36:28 +00:00
|
|
|
#include "ecmascript/ecma_string_table.h"
|
2022-03-26 09:00:26 +00:00
|
|
|
#include "ecmascript/template_map.h"
|
2022-05-11 09:36:28 +00:00
|
|
|
#include "ecmascript/js_array.h"
|
|
|
|
#include "ecmascript/js_realm.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
namespace panda::ecmascript {
|
2022-03-26 09:00:26 +00:00
|
|
|
void GlobalEnv::Init(JSThread *thread)
|
|
|
|
{
|
|
|
|
SetRegisterSymbols(thread, SymbolTable::Create(thread));
|
|
|
|
SetGlobalRecord(thread, GlobalDictionary::Create(thread));
|
|
|
|
JSTaggedValue emptyStr = thread->GlobalConstants()->GetEmptyString();
|
|
|
|
EcmaStringTable *stringTable = thread->GetEcmaVM()->GetEcmaStringTable();
|
2024-01-24 13:24:07 +00:00
|
|
|
stringTable->InternEmptyString(thread, EcmaString::Cast(emptyStr.GetTaggedObject()));
|
2022-03-26 09:00:26 +00:00
|
|
|
SetTemplateMap(thread, TemplateMap::Create(thread));
|
2022-04-11 12:01:28 +00:00
|
|
|
SetObjectLiteralHClassCache(thread, JSTaggedValue::Hole());
|
2023-09-04 06:53:18 +00:00
|
|
|
SetJsonObjectHclassCache(thread, JSTaggedValue::Hole());
|
2024-01-11 12:01:51 +00:00
|
|
|
SetJSThread(thread);
|
2022-03-26 09:00:26 +00:00
|
|
|
}
|
2021-09-04 08:06:49 +00:00
|
|
|
JSHandle<JSTaggedValue> GlobalEnv::GetSymbol(JSThread *thread, const JSHandle<JSTaggedValue> &string)
|
|
|
|
{
|
|
|
|
JSHandle<JSTaggedValue> symbolFunction(GetSymbolFunction());
|
|
|
|
return JSObject::GetProperty(thread, symbolFunction, string).GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSHandle<JSTaggedValue> GlobalEnv::GetStringPrototypeFunctionByName(JSThread *thread, const char *name)
|
|
|
|
{
|
|
|
|
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
2022-04-09 06:48:08 +00:00
|
|
|
JSHandle<JSTaggedValue> stringFuncPrototype(thread,
|
|
|
|
JSObject::GetPrototype(JSHandle<JSObject>(GetStringFunction())));
|
2022-04-09 02:34:11 +00:00
|
|
|
JSHandle<JSTaggedValue> nameKey(factory->NewFromUtf8(name));
|
2021-09-04 08:06:49 +00:00
|
|
|
return JSObject::GetProperty(thread, stringFuncPrototype, nameKey).GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSHandle<JSTaggedValue> GlobalEnv::GetStringFunctionByName(JSThread *thread, const char *name)
|
|
|
|
{
|
|
|
|
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
|
|
|
JSHandle<JSTaggedValue> stringFuncObj = GetStringFunction();
|
2022-04-09 02:34:11 +00:00
|
|
|
JSHandle<JSTaggedValue> nameKey(factory->NewFromUtf8(name));
|
2021-09-04 08:06:49 +00:00
|
|
|
return JSObject::GetProperty(thread, stringFuncObj, nameKey).GetValue();
|
|
|
|
}
|
|
|
|
} // namespace panda::ecmascript
|