Coverage Report

Created: 2022-05-20 06:19

/src/serenity/Userland/Libraries/LibJS/Runtime/Realm.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <LibJS/Runtime/GlobalEnvironment.h>
8
#include <LibJS/Runtime/GlobalObject.h>
9
#include <LibJS/Runtime/Realm.h>
10
#include <LibJS/Runtime/VM.h>
11
12
namespace JS {
13
14
// 9.3.1 CreateRealm ( ), https://tc39.es/ecma262/#sec-createrealm
15
Realm* Realm::create(VM& vm)
16
76
{
17
76
    return vm.heap().allocate_without_global_object<Realm>();
18
76
}
19
20
// 9.3.3 SetRealmGlobalObject ( realmRec, globalObj, thisValue ), https://tc39.es/ecma262/#sec-setrealmglobalobject
21
void Realm::set_global_object(GlobalObject& global_object, Object* this_value)
22
76
{
23
    // NOTE: Step 1 is not supported, the global object must be allocated elsewhere.
24
    // 2. Assert: Type(globalObj) is Object.
25
26
    // Non-standard
27
76
    global_object.set_associated_realm({}, *this);
28
29
    // 3. If thisValue is undefined, set thisValue to globalObj.
30
76
    if (!this_value)
31
0
        this_value = &global_object;
32
33
    // 4. Set realmRec.[[GlobalObject]] to globalObj.
34
76
    m_global_object = &global_object;
35
36
    // 5. Let newGlobalEnv be NewGlobalEnvironment(globalObj, thisValue).
37
    // 6. Set realmRec.[[GlobalEnv]] to newGlobalEnv.
38
76
    m_global_environment = global_object.heap().allocate_without_global_object<GlobalEnvironment>(global_object, *this_value);
39
40
    // 7. Return unused.
41
76
}
42
43
void Realm::visit_edges(Visitor& visitor)
44
62
{
45
62
    visitor.visit(m_global_object);
46
62
    visitor.visit(m_global_environment);
47
62
}
48
49
}