v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
module.h
Go to the documentation of this file.
1// Copyright 2017 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_OBJECTS_MODULE_H_
6#define V8_OBJECTS_MODULE_H_
7
8#include "include/v8-script.h"
10#include "src/objects/objects.h"
11#include "src/objects/struct.h"
12
13// Has to be the last include (doesn't have include guards):
15
16namespace v8 {
17namespace internal {
18
19class JSModuleNamespace;
20class SourceTextModuleDescriptor;
21class SourceTextModuleInfo;
22class SourceTextModuleInfoEntry;
23class Zone;
24template <typename T>
25class ZoneForwardList;
26
27#include "torque-generated/src/objects/module-tq.inc"
28
29// Module is the base class for ECMAScript module types, roughly corresponding
30// to Abstract Module Record.
31// https://tc39.github.io/ecma262/#sec-abstract-module-records
32class Module : public TorqueGeneratedModule<Module, HeapObject> {
33 public:
37
49
50#ifdef DEBUG
51 static const char* StatusString(Module::Status status);
52#endif // DEBUG
53
54 // The exception in the case {status} is kErrored.
56
57 // Returns if this module or any transitively requested module is [[Async]],
58 // i.e. has a top-level await.
59 V8_WARN_UNUSED_RESULT bool IsGraphAsync(Isolate* isolate) const;
60
61 // Implementation of spec operation ModuleDeclarationInstantiation.
62 // Returns false if an exception occurred during instantiation, true
63 // otherwise. (In the case where the callback throws an exception, that
64 // exception is propagated.)
66 Isolate* isolate, Handle<Module> module, v8::Local<v8::Context> context,
68 v8::Module::ResolveSourceCallback source_callback);
69
70 // Implementation of spec operation ModuleEvaluation.
72 Isolate* isolate, Handle<Module> module);
73
74 // Get the namespace object for [module]. If it doesn't exist yet, it is
75 // created.
77 Isolate* isolate, Handle<Module> module);
78
81
82 struct Hash;
83
84 protected:
85 friend class Factory;
86
87 // The [must_resolve] argument indicates whether or not an exception should be
88 // thrown in case the module does not provide an export named [name]
89 // (including when a cycle is detected). An exception is always thrown in the
90 // case of conflicting star exports.
91 //
92 // If [must_resolve] is true, a null result indicates an exception. If
93 // [must_resolve] is false, a null result may or may not indicate an
94 // exception (so check manually!).
95 class ResolveSet;
97 Isolate* isolate, Handle<Module> module,
98 DirectHandle<String> module_specifier, Handle<String> export_name,
99 MessageLocation loc, bool must_resolve, ResolveSet* resolve_set);
100
102 Isolate* isolate, DirectHandle<Module> module,
104 v8::Module::ResolveModuleCallback module_callback,
105 v8::Module::ResolveSourceCallback source_callback);
107 Isolate* isolate, Handle<Module> module,
108 ZoneForwardList<Handle<SourceTextModule>>* stack, unsigned* dfs_index,
109 Zone* zone);
110
111 // Set module's status back to kUnlinked and reset other internal state.
112 // This is used when instantiation fails.
113 static void Reset(Isolate* isolate, DirectHandle<Module> module);
114 static void ResetGraph(Isolate* isolate, DirectHandle<Module> module);
115
116 // To set status to kErrored, RecordError should be used.
117 void SetStatus(Status status);
118 void RecordError(Isolate* isolate, Tagged<Object> error);
119
121};
122
123// When importing a module namespace (import * as foo from "bar"), a
124// JSModuleNamespace object (representing module "bar") is created and bound to
125// the declared variable (foo). A module can have at most one namespace object.
127 : public TorqueGeneratedJSModuleNamespace<JSModuleNamespace,
128 JSSpecialObject> {
129 public:
131
132 // Retrieve the value exported by [module] under the given [name]. If there is
133 // no such export, return Just(undefined). If the export is uninitialized,
134 // schedule an exception and return Nothing.
136 Isolate* isolate, DirectHandle<String> name);
137
138 bool HasExport(Isolate* isolate, DirectHandle<String> name);
139
140 // Return the (constant) property attributes for the referenced property,
141 // which is assumed to correspond to an export. If the export is
142 // uninitialized, schedule an exception and return Nothing.
144 LookupIterator* it);
145
149 Maybe<ShouldThrow> should_throw);
150
151 // In-object fields.
152 enum {
155 };
156
157 // We need to include in-object fields
158 // TODO(v8:8944): improve handling of in-object fields
159 static constexpr int kSize =
160 kHeaderSize + (kTaggedSize * kInObjectFieldCount);
161
163};
164
166 : public TorqueGeneratedScriptOrModule<ScriptOrModule, Struct> {
167 public:
169
171
173};
174
175} // namespace internal
176} // namespace v8
177
178#include "src/objects/object-macros-undef.h"
179
180#endif // V8_OBJECTS_MODULE_H_
friend Zone
Definition asm-types.cc:195
static constexpr int kSize
Definition module.h:159
static V8_WARN_UNUSED_RESULT Maybe< bool > DefineOwnProperty(Isolate *isolate, DirectHandle< JSModuleNamespace > o, DirectHandle< Object > key, PropertyDescriptor *desc, Maybe< ShouldThrow > should_throw)
Definition module.cc:453
V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > GetExport(Isolate *isolate, DirectHandle< String > name)
Definition module.cc:405
static V8_WARN_UNUSED_RESULT Maybe< PropertyAttributes > GetPropertyAttributes(LookupIterator *it)
Definition module.cc:428
bool HasExport(Isolate *isolate, DirectHandle< String > name)
Definition module.cc:400
static void ResetGraph(Isolate *isolate, DirectHandle< Module > module)
Definition module.cc:125
V8_WARN_UNUSED_RESULT bool IsGraphAsync(Isolate *isolate) const
Definition module.cc:490
void RecordError(Isolate *isolate, Tagged< Object > error)
Definition module.cc:104
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Evaluate(Isolate *isolate, Handle< Module > module)
Definition module.cc:272
Tagged< Object > GetException()
Definition module.cc:180
void SetStatus(Status status)
Definition module.cc:97
static V8_WARN_UNUSED_RESULT bool FinishInstantiate(Isolate *isolate, Handle< Module > module, ZoneForwardList< Handle< SourceTextModule > > *stack, unsigned *dfs_index, Zone *zone)
Definition module.cc:255
static V8_WARN_UNUSED_RESULT MaybeHandle< Cell > ResolveExport(Isolate *isolate, Handle< Module > module, DirectHandle< String > module_specifier, Handle< String > export_name, MessageLocation loc, bool must_resolve, ResolveSet *resolve_set)
Definition module.cc:187
static DirectHandle< JSModuleNamespace > GetModuleNamespace(Isolate *isolate, Handle< Module > module)
Definition module.cc:324
static void Reset(Isolate *isolate, DirectHandle< Module > module)
Definition module.cc:158
static V8_WARN_UNUSED_RESULT bool Instantiate(Isolate *isolate, Handle< Module > module, v8::Local< v8::Context > context, v8::Module::ResolveModuleCallback module_callback, v8::Module::ResolveSourceCallback source_callback)
Definition module.cc:206
static V8_WARN_UNUSED_RESULT bool PrepareInstantiate(Isolate *isolate, DirectHandle< Module > module, v8::Local< v8::Context > context, v8::Module::ResolveModuleCallback module_callback, v8::Module::ResolveSourceCallback source_callback)
Definition module.cc:234
constexpr int kTaggedSize
Definition globals.h:542
#define DECL_VERIFIER(Name)
#define NEVER_READ_ONLY_SPACE
#define DECL_PRINTER(Name)
#define TQ_OBJECT_CONSTRUCTORS(Type)
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:671