Repository navigation
Expand file tree
/
Copy pathAOTModuleNamespace.h
More file actions
94 lines (74 loc) · 3.99 KB
/
Copy pathAOTModuleNamespace.h
File metadata and controls
94 lines (74 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (C) 2026 Oven, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#if ENABLE(AOT)
#include "AOTRecordTypes.h"
#include "AOTVector.h"
#include "AbstractModuleRecord.h"
#include "ArgList.h"
#include "JSCellButterfly.h"
#include "JSObject.h"
namespace JSC { namespace AOT {
class Modules;
struct ModuleExportData;
class ModuleNamespace final : public JSNonFinalObject {
public:
using Base = JSNonFinalObject;
using ModulePhase = AbstractModuleRecord::ModulePhase;
static constexpr unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetOwnPropertyNames | OverridesPut | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | GetOwnPropertySlotIsImpure | GetOwnPropertySlotIsImpureForPropertyAbsence | IsImmutablePrototypeExoticObject;
static constexpr DestructionMode needsDestruction = DoesNotNeedDestruction;
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm) { return &vm.cellSpace(); }
struct DynamicExports {
JSCellButterfly* names { nullptr };
JSObject* capturedValues { nullptr };
JSObject* liveSources { nullptr };
};
static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype, bool shouldPreventExtensions);
static ModuleNamespace* create(VM&, Structure*, ModuleID, ModulePhase, const DynamicExports&);
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;
ModuleID module() const { return m_module; }
bool isDeferred() const { return m_isDeferred; }
// A read of a deferred namespace object may evaluate the module, so that object does not have the module's namespace layout.
bool hasNamespaceLayoutOf(ModuleID module) const { return m_module == module && !m_isDeferred; }
std::optional<unsigned> find(UniquedStringImpl*) const;
bool hasExport(UniquedStringImpl* name) const { return find(name) || isDynamicExport(name); }
// Reads every export once, in the order of the keys, as [[OwnPropertyKeys]] and [[Get]] of each key would, without a lookup by name.
bool tryReadExports(JSGlobalObject*, Vector<UniquedStringImpl*, 8>& names, MarkedArgumentBuffer& values);
ModuleNamespace* createNamespaceForRequire(JSGlobalObject*);
bool hasOwnStructure() const { return m_hasOwnStructure; }
void ensureOwnStructure(VM&);
static bool getOwnPropertySlot(JSObject*, JSGlobalObject*, PropertyName, PropertySlot&);
static bool getOwnPropertySlotByIndex(JSObject*, JSGlobalObject*, unsigned, PropertySlot&);
static void getOwnPropertyNames(JSObject*, JSGlobalObject*, PropertyNameArrayBuilder&, DontEnumPropertiesMode);
static bool put(JSCell*, JSGlobalObject*, PropertyName, JSValue, PutPropertySlot&);
static bool putByIndex(JSCell*, JSGlobalObject*, unsigned, JSValue, bool shouldThrow);
static bool deleteProperty(JSCell*, JSGlobalObject*, PropertyName, DeletePropertySlot&);
static bool deletePropertyByIndex(JSCell*, JSGlobalObject*, unsigned);
static bool defineOwnProperty(JSObject*, JSGlobalObject*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
private:
ModuleNamespace(VM&, Structure*, ModuleID, ModulePhase, const DynamicExports&);
Modules& modules() const;
std::span<const ModuleExportData> exports() const;
bool isAmbiguousExport(unsigned index) const;
bool isSymbolLikeKey(UniquedStringImpl*) const;
bool isOrdinaryKey(PropertyName) const;
bool isESModuleMarker(PropertyName) const;
bool isDynamicExport(UniquedStringImpl*) const;
JSValue readDynamicExport(JSGlobalObject*, PropertyName);
bool evaluateIfNeeded(JSGlobalObject*);
WriteBarrier<ModuleNamespace> m_requiredNamespace;
WriteBarrier<JSCellButterfly> m_dynamicExportNames;
WriteBarrier<JSObject> m_capturedValues;
WriteBarrier<JSObject> m_liveSources;
ModuleID m_module;
bool m_isDeferred;
bool m_mayNeedEvaluation;
bool m_hasESModuleMarker { false };
bool m_hasOwnStructure { false };
};
} } // namespace JSC::AOT
#endif // ENABLE(AOT)