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 #include "ecma_module.h"
18 #include "ecmascript/builtins/builtins_promise_handler.h"
19 #include "ecmascript/jspandafile/program_object-inl.h"
20 #include "ecmascript/ic/ic_handler.h"
21 #include "ecmascript/ic/proto_change_details.h"
22 #include "ecmascript/jobs/micro_job_queue.h"
23 #include "ecmascript/js_generator_object.h"
24 #include "ecmascript/js_handle.h"
25 #include "ecmascript/js_promise.h"
26 #include "ecmascript/object_factory.h"
27 #include "js_array.h"
28 #include "js_realm.h"
29
30 namespace panda::ecmascript {
GetSymbol(JSThread * thread,const JSHandle<JSTaggedValue> & string)31 JSHandle<JSTaggedValue> GlobalEnv::GetSymbol(JSThread *thread, const JSHandle<JSTaggedValue> &string)
32 {
33 JSHandle<JSTaggedValue> symbolFunction(GetSymbolFunction());
34 return JSObject::GetProperty(thread, symbolFunction, string).GetValue();
35 }
36
GetStringPrototypeFunctionByName(JSThread * thread,const char * name)37 JSHandle<JSTaggedValue> GlobalEnv::GetStringPrototypeFunctionByName(JSThread *thread, const char *name)
38 {
39 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
40 JSHandle<JSObject> stringFuncObj(GetStringFunction());
41 JSHandle<JSTaggedValue> stringFuncPrototype(thread, stringFuncObj->GetPrototype(thread));
42 JSHandle<JSTaggedValue> nameKey(factory->NewFromString(name));
43 return JSObject::GetProperty(thread, stringFuncPrototype, nameKey).GetValue();
44 }
45
GetStringFunctionByName(JSThread * thread,const char * name)46 JSHandle<JSTaggedValue> GlobalEnv::GetStringFunctionByName(JSThread *thread, const char *name)
47 {
48 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
49 JSHandle<JSTaggedValue> stringFuncObj = GetStringFunction();
50 JSHandle<JSTaggedValue> nameKey(factory->NewFromString(name));
51 return JSObject::GetProperty(thread, stringFuncObj, nameKey).GetValue();
52 }
53 } // namespace panda::ecmascript
54