mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibJS: Add a barebones Module class
This corresponds to the "Abstract Module Record" from the spec.
This commit is contained in:
parent
df5414f47f
commit
d553fd7f4f
Notes:
sideshowbarker
2024-07-18 03:58:10 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d553fd7f4fa
3 changed files with 59 additions and 0 deletions
|
@ -21,6 +21,7 @@ set(SOURCES
|
|||
Interpreter.cpp
|
||||
Lexer.cpp
|
||||
MarkupGenerator.cpp
|
||||
Module.cpp
|
||||
Parser.cpp
|
||||
Runtime/AbstractOperations.cpp
|
||||
Runtime/AggregateError.cpp
|
||||
|
|
21
Userland/Libraries/LibJS/Module.cpp
Normal file
21
Userland/Libraries/LibJS/Module.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Module.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
Module::Module(Realm& realm)
|
||||
: m_vm(realm.vm())
|
||||
, m_realm(make_handle(&realm))
|
||||
{
|
||||
}
|
||||
|
||||
Module::~Module()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
37
Userland/Libraries/LibJS/Module.h
Normal file
37
Userland/Libraries/LibJS/Module.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
// 16.2.1.4 Abstract Module Records, https://tc39.es/ecma262/#sec-abstract-module-records
|
||||
class Module : public RefCounted<Module> {
|
||||
public:
|
||||
virtual ~Module();
|
||||
|
||||
Realm& realm() { return *m_realm.cell(); }
|
||||
Realm const& realm() const { return *m_realm.cell(); }
|
||||
|
||||
Environment* environment() { return m_environment.cell(); }
|
||||
Object* namespace_() { return m_namespace.cell(); }
|
||||
|
||||
protected:
|
||||
explicit Module(Realm&);
|
||||
|
||||
private:
|
||||
// Handles are not safe unless we keep the VM alive.
|
||||
NonnullRefPtr<VM> m_vm;
|
||||
|
||||
Handle<Realm> m_realm; // [[Realm]]
|
||||
Handle<Environment> m_environment; // [[Environment]]
|
||||
Handle<Object> m_namespace; // [[Namespace]]
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue