| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#ifndef builtin_ModuleObject_h |
| 8 |
#define builtin_ModuleObject_h |
| 9 |
|
| 10 |
#include "mozilla/HashTable.h" // mozilla::{HashMap, DefaultHasher} |
| 11 |
#include "mozilla/Maybe.h" // mozilla::Maybe |
| 12 |
#include "mozilla/Span.h" |
| 13 |
|
| 14 |
#include <stddef.h> // size_t |
| 15 |
#include <stdint.h> // int32_t, uint32_t |
| 16 |
|
| 17 |
#include "gc/Barrier.h" // HeapPtr |
| 18 |
#include "gc/ZoneAllocator.h" // CellAllocPolicy |
| 19 |
#include "js/Class.h" // JSClass, ObjectOpResult |
| 20 |
#include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin |
| 21 |
#include "js/GCVector.h" |
| 22 |
#include "js/Id.h" // jsid |
| 23 |
#include "js/Modules.h" |
| 24 |
#include "js/Proxy.h" // BaseProxyHandler |
| 25 |
#include "js/RootingAPI.h" // Rooted, Handle, MutableHandle |
| 26 |
#include "js/TypeDecls.h" // HandleValue, HandleId, HandleObject, HandleScript, MutableHandleValue, MutableHandleIdVector, MutableHandleObject |
| 27 |
#include "js/UniquePtr.h" // UniquePtr |
| 28 |
#include "vm/JSObject.h" // JSObject |
| 29 |
#include "vm/NativeObject.h" // NativeObject |
| 30 |
#include "vm/ProxyObject.h" // ProxyObject |
| 31 |
#include "vm/SharedStencil.h" // FunctionDeclarationVector |
| 32 |
|
| 33 |
class JSAtom; |
| 34 |
class JSScript; |
| 35 |
class JSTracer; |
| 36 |
|
| 37 |
namespace JS { |
| 38 |
class PropertyDescriptor; |
| 39 |
class Value; |
| 40 |
} // namespace JS |
| 41 |
|
| 42 |
namespace js { |
| 43 |
|
| 44 |
class ArrayObject; |
| 45 |
class CyclicModuleFields; |
| 46 |
class SyntheticModuleFields; |
| 47 |
class ListObject; |
| 48 |
class ModuleEnvironmentObject; |
| 49 |
class ModuleObject; |
| 50 |
class PromiseObject; |
| 51 |
class ScriptSourceObject; |
| 52 |
|
| 53 |
class ImportAttribute { |
| 54 |
const HeapPtr<JSAtom*> key_; |
| 55 |
const HeapPtr<JSString*> value_; |
| 56 |
|
| 57 |
public: |
| 58 |
ImportAttribute(Handle<JSAtom*> key, Handle<JSString*> value); |
| 59 |
|
| 60 |
JSAtom* key() const { return key_; } |
| 61 |
JSString* value() const { return value_; } |
| 62 |
|
| 63 |
void trace(JSTracer* trc); |
| 64 |
}; |
| 65 |
|
| 66 |
using ImportAttributeVector = GCVector<ImportAttribute, 0, SystemAllocPolicy>; |
| 67 |
|
| 68 |
class ModuleRequestObject : public NativeObject { |
| 69 |
public: |
| 70 |
enum { |
| 71 |
SpecifierSlot = 0, |
| 72 |
FirstUnsupportedAttributeKeySlot, |
| 73 |
ModuleTypeSlot, |
| 74 |
SlotCount |
| 75 |
}; |
| 76 |
|
| 77 |
static const JSClass class_; |
| 78 |
static bool isInstance(HandleValue value); |
| 79 |
[[nodiscard]] static ModuleRequestObject* create( |
| 80 |
JSContext* cx, Handle<JSAtom*> specifier, |
| 81 |
Handle<ImportAttributeVector> maybeAttributes); |
| 82 |
[[nodiscard]] static ModuleRequestObject* create(JSContext* cx, |
| 83 |
Handle<JSAtom*> specifier, |
| 84 |
JS::ModuleType moduleType); |
| 85 |
|
| 86 |
JSAtom* specifier() const; |
| 87 |
JS::ModuleType moduleType() const; |
| 88 |
|
| 89 |
// We process import attributes earlier in the process, but according to the |
| 90 |
// spec, we should error during module evaluation if we encounter an |
| 91 |
// unsupported attribute. We want to generate a nice error message, so we need |
| 92 |
// to keep track of the first unsupported key we encounter. |
| 93 |
void setFirstUnsupportedAttributeKey(Handle<JSAtom*> key); |
| 94 |
bool hasFirstUnsupportedAttributeKey() const; |
| 95 |
JSAtom* getFirstUnsupportedAttributeKey() const; |
| 96 |
}; |
| 97 |
|
| 98 |
using ModuleRequestVector = |
| 99 |
GCVector<HeapPtr<ModuleRequestObject*>, 0, SystemAllocPolicy>; |
| 100 |
|
| 101 |
class ImportEntry { |
| 102 |
const HeapPtr<ModuleRequestObject*> moduleRequest_; |
| 103 |
const HeapPtr<JSAtom*> importName_; |
| 104 |
const HeapPtr<JSAtom*> localName_; |
| 105 |
|
| 106 |
// Line number (1-origin). |
| 107 |
const uint32_t lineNumber_; |
| 108 |
|
| 109 |
// Column number in UTF-16 code units. |
| 110 |
const JS::ColumnNumberOneOrigin columnNumber_; |
| 111 |
|
| 112 |
public: |
| 113 |
ImportEntry(Handle<ModuleRequestObject*> moduleRequest, |
| 114 |
Handle<JSAtom*> maybeImportName, Handle<JSAtom*> localName, |
| 115 |
uint32_t lineNumber, JS::ColumnNumberOneOrigin columnNumber); |
| 116 |
|
| 117 |
ModuleRequestObject* moduleRequest() const { return moduleRequest_; } |
| 118 |
JSAtom* importName() const { return importName_; } |
| 119 |
JSAtom* localName() const { return localName_; } |
| 120 |
uint32_t lineNumber() const { return lineNumber_; } |
| 121 |
JS::ColumnNumberOneOrigin columnNumber() const { return columnNumber_; } |
| 122 |
|
| 123 |
void trace(JSTracer* trc); |
| 124 |
}; |
| 125 |
|
| 126 |
using ImportEntryVector = GCVector<ImportEntry, 0, SystemAllocPolicy>; |
| 127 |
|
| 128 |
class ExportEntry { |
| 129 |
const HeapPtr<JSAtom*> exportName_; |
| 130 |
const HeapPtr<ModuleRequestObject*> moduleRequest_; |
| 131 |
const HeapPtr<JSAtom*> importName_; |
| 132 |
const HeapPtr<JSAtom*> localName_; |
| 133 |
|
| 134 |
// Line number (1-origin). |
| 135 |
const uint32_t lineNumber_; |
| 136 |
|
| 137 |
// Column number in UTF-16 code units. |
| 138 |
const JS::ColumnNumberOneOrigin columnNumber_; |
| 139 |
|
| 140 |
public: |
| 141 |
ExportEntry(Handle<JSAtom*> maybeExportName, |
| 142 |
Handle<ModuleRequestObject*> maybeModuleRequest, |
| 143 |
Handle<JSAtom*> maybeImportName, Handle<JSAtom*> maybeLocalName, |
| 144 |
uint32_t lineNumber, JS::ColumnNumberOneOrigin columnNumber); |
| 145 |
JSAtom* exportName() const { return exportName_; } |
| 146 |
ModuleRequestObject* moduleRequest() const { return moduleRequest_; } |
| 147 |
JSAtom* importName() const { return importName_; } |
| 148 |
JSAtom* localName() const { return localName_; } |
| 149 |
uint32_t lineNumber() const { return lineNumber_; } |
| 150 |
JS::ColumnNumberOneOrigin columnNumber() const { return columnNumber_; } |
| 151 |
|
| 152 |
void trace(JSTracer* trc); |
| 153 |
}; |
| 154 |
|
| 155 |
using ExportEntryVector = GCVector<ExportEntry, 0, SystemAllocPolicy>; |
| 156 |
|
| 157 |
class RequestedModule { |
| 158 |
const HeapPtr<ModuleRequestObject*> moduleRequest_; |
| 159 |
|
| 160 |
// Line number (1-origin). |
| 161 |
const uint32_t lineNumber_; |
| 162 |
|
| 163 |
// Column number in UTF-16 code units. |
| 164 |
const JS::ColumnNumberOneOrigin columnNumber_; |
| 165 |
|
| 166 |
public: |
| 167 |
RequestedModule(Handle<ModuleRequestObject*> moduleRequest, |
| 168 |
uint32_t lineNumber, JS::ColumnNumberOneOrigin columnNumber); |
| 169 |
ModuleRequestObject* moduleRequest() const { return moduleRequest_; } |
| 170 |
uint32_t lineNumber() const { return lineNumber_; } |
| 171 |
JS::ColumnNumberOneOrigin columnNumber() const { return columnNumber_; } |
| 172 |
|
| 173 |
void trace(JSTracer* trc); |
| 174 |
}; |
| 175 |
|
| 176 |
using RequestedModuleVector = GCVector<RequestedModule, 0, SystemAllocPolicy>; |
| 177 |
|
| 178 |
class ResolvedBindingObject : public NativeObject { |
| 179 |
public: |
| 180 |
enum { ModuleSlot = 0, BindingNameSlot, SlotCount }; |
| 181 |
|
| 182 |
static const JSClass class_; |
| 183 |
static bool isInstance(HandleValue value); |
| 184 |
static ResolvedBindingObject* create(JSContext* cx, |
| 185 |
Handle<ModuleObject*> module, |
| 186 |
Handle<JSAtom*> bindingName); |
| 187 |
ModuleObject* module() const; |
| 188 |
JSAtom* bindingName() const; |
| 189 |
}; |
| 190 |
|
| 191 |
class IndirectBindingMap { |
| 192 |
public: |
| 193 |
void trace(JSTracer* trc); |
| 194 |
|
| 195 |
bool put(JSContext* cx, HandleId name, |
| 196 |
Handle<ModuleEnvironmentObject*> environment, HandleId targetName); |
| 197 |
|
| 198 |
size_t count() const { return map_ ? map_->count() : 0; } |
| 199 |
|
| 200 |
bool has(jsid name) const { return map_ ? map_->has(name) : false; } |
| 201 |
|
| 202 |
bool lookup(jsid name, ModuleEnvironmentObject** envOut, |
| 203 |
mozilla::Maybe<PropertyInfo>* propOut) const; |
| 204 |
|
| 205 |
template <typename Func> |
| 206 |
void forEachExportedName(Func func) const { |
| 207 |
if (!map_) { |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
for (auto r = map_->all(); !r.empty(); r.popFront()) { |
| 212 |
func(r.front().key()); |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
private: |
| 217 |
struct Binding { |
| 218 |
Binding(ModuleEnvironmentObject* environment, jsid targetName, |
| 219 |
PropertyInfo prop); |
| 220 |
HeapPtr<ModuleEnvironmentObject*> environment; |
| 221 |
#ifdef DEBUG |
| 222 |
HeapPtr<jsid> targetName; |
| 223 |
#endif |
| 224 |
PropertyInfo prop; |
| 225 |
}; |
| 226 |
|
| 227 |
using Map = mozilla::HashMap<PreBarriered<jsid>, Binding, |
| 228 |
mozilla::DefaultHasher<PreBarriered<jsid>>, |
| 229 |
CellAllocPolicy>; |
| 230 |
|
| 231 |
mozilla::Maybe<Map> map_; |
| 232 |
}; |
| 233 |
|
| 234 |
// Vector of atoms representing the names exported from a module namespace. |
| 235 |
// |
| 236 |
// This is used both on the stack and in the heap. |
| 237 |
using ExportNameVector = GCVector<HeapPtr<JSAtom*>, 0, SystemAllocPolicy>; |
| 238 |
|
| 239 |
class ModuleNamespaceObject : public ProxyObject { |
| 240 |
public: |
| 241 |
enum ModuleNamespaceSlot { ExportsSlot = 0, BindingsSlot }; |
| 242 |
|
| 243 |
static bool isInstance(HandleValue value); |
| 244 |
static ModuleNamespaceObject* create( |
| 245 |
JSContext* cx, Handle<ModuleObject*> module, |
| 246 |
MutableHandle<UniquePtr<ExportNameVector>> exports, |
| 247 |
MutableHandle<UniquePtr<IndirectBindingMap>> bindings); |
| 248 |
|
| 249 |
ModuleObject& module(); |
| 250 |
const ExportNameVector& exports() const; |
| 251 |
IndirectBindingMap& bindings(); |
| 252 |
|
| 253 |
bool addBinding(JSContext* cx, Handle<JSAtom*> exportedName, |
| 254 |
Handle<ModuleObject*> targetModule, |
| 255 |
Handle<JSAtom*> targetName); |
| 256 |
|
| 257 |
private: |
| 258 |
struct ProxyHandler : public BaseProxyHandler { |
| 259 |
constexpr ProxyHandler() : BaseProxyHandler(&family, false) {} |
| 260 |
|
| 261 |
bool getOwnPropertyDescriptor( |
| 262 |
JSContext* cx, HandleObject proxy, HandleId id, |
| 263 |
MutableHandle<mozilla::Maybe<PropertyDescriptor>> desc) const override; |
| 264 |
bool defineProperty(JSContext* cx, HandleObject proxy, HandleId id, |
| 265 |
Handle<PropertyDescriptor> desc, |
| 266 |
ObjectOpResult& result) const override; |
| 267 |
bool ownPropertyKeys(JSContext* cx, HandleObject proxy, |
| 268 |
MutableHandleIdVector props) const override; |
| 269 |
bool delete_(JSContext* cx, HandleObject proxy, HandleId id, |
| 270 |
ObjectOpResult& result) const override; |
| 271 |
bool getPrototype(JSContext* cx, HandleObject proxy, |
| 272 |
MutableHandleObject protop) const override; |
| 273 |
bool setPrototype(JSContext* cx, HandleObject proxy, HandleObject proto, |
| 274 |
ObjectOpResult& result) const override; |
| 275 |
bool getPrototypeIfOrdinary(JSContext* cx, HandleObject proxy, |
| 276 |
bool* isOrdinary, |
| 277 |
MutableHandleObject protop) const override; |
| 278 |
bool setImmutablePrototype(JSContext* cx, HandleObject proxy, |
| 279 |
bool* succeeded) const override; |
| 280 |
|
| 281 |
bool preventExtensions(JSContext* cx, HandleObject proxy, |
| 282 |
ObjectOpResult& result) const override; |
| 283 |
bool isExtensible(JSContext* cx, HandleObject proxy, |
| 284 |
bool* extensible) const override; |
| 285 |
bool has(JSContext* cx, HandleObject proxy, HandleId id, |
| 286 |
bool* bp) const override; |
| 287 |
bool get(JSContext* cx, HandleObject proxy, HandleValue receiver, |
| 288 |
HandleId id, MutableHandleValue vp) const override; |
| 289 |
bool set(JSContext* cx, HandleObject proxy, HandleId id, HandleValue v, |
| 290 |
HandleValue receiver, ObjectOpResult& result) const override; |
| 291 |
|
| 292 |
void trace(JSTracer* trc, JSObject* proxy) const override; |
| 293 |
void finalize(JS::GCContext* gcx, JSObject* proxy) const override; |
| 294 |
|
| 295 |
static const char family; |
| 296 |
}; |
| 297 |
|
| 298 |
bool hasBindings() const; |
| 299 |
bool hasExports() const; |
| 300 |
|
| 301 |
ExportNameVector& mutableExports(); |
| 302 |
|
| 303 |
public: |
| 304 |
static const ProxyHandler proxyHandler; |
| 305 |
}; |
| 306 |
|
| 307 |
// Value types of [[Status]] in a Cyclic Module Record |
| 308 |
// https://tc39.es/ecma262/#table-cyclic-module-fields |
| 309 |
enum class ModuleStatus : int8_t { |
| 310 |
Unlinked, |
| 311 |
Linking, |
| 312 |
Linked, |
| 313 |
Evaluating, |
| 314 |
EvaluatingAsync, |
| 315 |
Evaluated, |
| 316 |
|
| 317 |
// Sub-state of Evaluated with error value set. |
| 318 |
// |
| 319 |
// This is not returned from ModuleObject::status(); use hadEvaluationError() |
| 320 |
// to check this. |
| 321 |
Evaluated_Error |
| 322 |
}; |
| 323 |
|
| 324 |
// Special values for CyclicModuleFields' asyncEvaluatingPostOrderSlot field, |
| 325 |
// which is used as part of the implementation of the AsyncEvaluation field of |
| 326 |
// cyclic module records. |
| 327 |
// |
| 328 |
// The spec requires us to be able to tell the order in which the field was set |
| 329 |
// to true for async evaluating modules. |
| 330 |
// |
| 331 |
// This is arranged by using an integer to record the order. After evaluation is |
| 332 |
// complete the value is set to ASYNC_EVALUATING_POST_ORDER_CLEARED. |
| 333 |
// |
| 334 |
// See https://tc39.es/ecma262/#sec-cyclic-module-records for field defintion. |
| 335 |
// See https://tc39.es/ecma262/#sec-async-module-execution-fulfilled for sort |
| 336 |
// requirement. |
| 337 |
|
| 338 |
// Initial value for the runtime's counter used to generate these values. |
| 339 |
constexpr uint32_t ASYNC_EVALUATING_POST_ORDER_INIT = 1; |
| 340 |
|
| 341 |
// Value that the field is set to after being cleared. |
| 342 |
constexpr uint32_t ASYNC_EVALUATING_POST_ORDER_CLEARED = 0; |
| 343 |
|
| 344 |
// Currently, the ModuleObject class is used to represent both the Source Text |
| 345 |
// Module Record and the Synthetic Module Record. Ideally, this is something |
| 346 |
// that should be refactored to follow the same hierarchy as in the spec. |
| 347 |
// TODO: See Bug 1880519. |
| 348 |
class ModuleObject : public NativeObject { |
| 349 |
public: |
| 350 |
// Module fields including those for AbstractModuleRecords described by: |
| 351 |
// https://tc39.es/ecma262/#sec-abstract-module-records |
| 352 |
enum ModuleSlot { |
| 353 |
ScriptSlot = 0, |
| 354 |
EnvironmentSlot, |
| 355 |
NamespaceSlot, |
| 356 |
CyclicModuleFieldsSlot, |
| 357 |
// `SyntheticModuleFields` if a synthetic module. Otherwise `undefined`. |
| 358 |
SyntheticModuleFieldsSlot, |
| 359 |
SlotCount |
| 360 |
}; |
| 361 |
|
| 362 |
static const JSClass class_; |
| 363 |
|
| 364 |
static bool isInstance(HandleValue value); |
| 365 |
|
| 366 |
static ModuleObject* create(JSContext* cx); |
| 367 |
|
| 368 |
static ModuleObject* createSynthetic( |
| 369 |
JSContext* cx, MutableHandle<ExportNameVector> exportNames); |
| 370 |
|
| 371 |
// Initialize the slots on this object that are dependent on the script. |
| 372 |
void initScriptSlots(HandleScript script); |
| 373 |
|
| 374 |
void setInitialEnvironment( |
| 375 |
Handle<ModuleEnvironmentObject*> initialEnvironment); |
| 376 |
|
| 377 |
void initFunctionDeclarations(UniquePtr<FunctionDeclarationVector> decls); |
| 378 |
void initImportExportData( |
| 379 |
MutableHandle<RequestedModuleVector> requestedModules, |
| 380 |
MutableHandle<ImportEntryVector> importEntries, |
| 381 |
MutableHandle<ExportEntryVector> exportEntries, uint32_t localExportCount, |
| 382 |
uint32_t indirectExportCount, uint32_t starExportCount); |
| 383 |
static bool Freeze(JSContext* cx, Handle<ModuleObject*> self); |
| 384 |
#ifdef DEBUG |
| 385 |
static bool AssertFrozen(JSContext* cx, Handle<ModuleObject*> self); |
| 386 |
#endif |
| 387 |
|
| 388 |
JSScript* maybeScript() const; |
| 389 |
JSScript* script() const; |
| 390 |
const char* filename() const; |
| 391 |
ModuleEnvironmentObject& initialEnvironment() const; |
| 392 |
ModuleEnvironmentObject* environment() const; |
| 393 |
ModuleNamespaceObject* namespace_(); |
| 394 |
ModuleStatus status() const; |
| 395 |
mozilla::Maybe<uint32_t> maybeDfsIndex() const; |
| 396 |
uint32_t dfsIndex() const; |
| 397 |
mozilla::Maybe<uint32_t> maybeDfsAncestorIndex() const; |
| 398 |
uint32_t dfsAncestorIndex() const; |
| 399 |
bool hadEvaluationError() const; |
| 400 |
Value maybeEvaluationError() const; |
| 401 |
Value evaluationError() const; |
| 402 |
JSObject* metaObject() const; |
| 403 |
ScriptSourceObject* scriptSourceObject() const; |
| 404 |
mozilla::Span<const RequestedModule> requestedModules() const; |
| 405 |
mozilla::Span<const ImportEntry> importEntries() const; |
| 406 |
mozilla::Span<const ExportEntry> localExportEntries() const; |
| 407 |
mozilla::Span<const ExportEntry> indirectExportEntries() const; |
| 408 |
mozilla::Span<const ExportEntry> starExportEntries() const; |
| 409 |
const ExportNameVector& syntheticExportNames() const; |
| 410 |
|
| 411 |
IndirectBindingMap& importBindings(); |
| 412 |
|
| 413 |
void setStatus(ModuleStatus newStatus); |
| 414 |
void setDfsIndex(uint32_t index); |
| 415 |
void setDfsAncestorIndex(uint32_t index); |
| 416 |
void clearDfsIndexes(); |
| 417 |
|
| 418 |
static PromiseObject* createTopLevelCapability(JSContext* cx, |
| 419 |
Handle<ModuleObject*> module); |
| 420 |
bool hasTopLevelAwait() const; |
| 421 |
bool isAsyncEvaluating() const; |
| 422 |
void setAsyncEvaluating(); |
| 423 |
void setEvaluationError(HandleValue newValue); |
| 424 |
void setPendingAsyncDependencies(uint32_t newValue); |
| 425 |
void setInitialTopLevelCapability(Handle<PromiseObject*> capability); |
| 426 |
bool hasTopLevelCapability() const; |
| 427 |
PromiseObject* maybeTopLevelCapability() const; |
| 428 |
PromiseObject* topLevelCapability() const; |
| 429 |
ListObject* asyncParentModules() const; |
| 430 |
mozilla::Maybe<uint32_t> maybePendingAsyncDependencies() const; |
| 431 |
uint32_t pendingAsyncDependencies() const; |
| 432 |
mozilla::Maybe<uint32_t> maybeAsyncEvaluatingPostOrder() const; |
| 433 |
uint32_t getAsyncEvaluatingPostOrder() const; |
| 434 |
void clearAsyncEvaluatingPostOrder(); |
| 435 |
void setCycleRoot(ModuleObject* cycleRoot); |
| 436 |
ModuleObject* getCycleRoot() const; |
| 437 |
bool hasCyclicModuleFields() const; |
| 438 |
bool hasSyntheticModuleFields() const; |
| 439 |
|
| 440 |
static void onTopLevelEvaluationFinished(ModuleObject* module); |
| 441 |
|
| 442 |
static bool appendAsyncParentModule(JSContext* cx, Handle<ModuleObject*> self, |
| 443 |
Handle<ModuleObject*> parent); |
| 444 |
|
| 445 |
[[nodiscard]] static bool topLevelCapabilityResolve( |
| 446 |
JSContext* cx, Handle<ModuleObject*> module); |
| 447 |
[[nodiscard]] static bool topLevelCapabilityReject( |
| 448 |
JSContext* cx, Handle<ModuleObject*> module, HandleValue error); |
| 449 |
|
| 450 |
void setMetaObject(JSObject* obj); |
| 451 |
|
| 452 |
static bool instantiateFunctionDeclarations(JSContext* cx, |
| 453 |
Handle<ModuleObject*> self); |
| 454 |
|
| 455 |
static bool execute(JSContext* cx, Handle<ModuleObject*> self); |
| 456 |
|
| 457 |
static ModuleNamespaceObject* createNamespace( |
| 458 |
JSContext* cx, Handle<ModuleObject*> self, |
| 459 |
MutableHandle<UniquePtr<ExportNameVector>> exports); |
| 460 |
void clearNamespaceOnFailure(); |
| 461 |
|
| 462 |
static bool createEnvironment(JSContext* cx, Handle<ModuleObject*> self); |
| 463 |
static bool createSyntheticEnvironment(JSContext* cx, |
| 464 |
Handle<ModuleObject*> self, |
| 465 |
JS::HandleVector<Value> values); |
| 466 |
|
| 467 |
void initAsyncSlots(JSContext* cx, bool hasTopLevelAwait, |
| 468 |
Handle<ListObject*> asyncParentModules); |
| 469 |
|
| 470 |
private: |
| 471 |
static const JSClassOps classOps_; |
| 472 |
|
| 473 |
static void trace(JSTracer* trc, JSObject* obj); |
| 474 |
static void finalize(JS::GCContext* gcx, JSObject* obj); |
| 475 |
|
| 476 |
CyclicModuleFields* cyclicModuleFields(); |
| 477 |
const CyclicModuleFields* cyclicModuleFields() const; |
| 478 |
|
| 479 |
SyntheticModuleFields* syntheticModuleFields(); |
| 480 |
const SyntheticModuleFields* syntheticModuleFields() const; |
| 481 |
}; |
| 482 |
|
| 483 |
JSObject* GetOrCreateModuleMetaObject(JSContext* cx, HandleObject module); |
| 484 |
|
| 485 |
ModuleObject* CallModuleResolveHook(JSContext* cx, |
| 486 |
HandleValue referencingPrivate, |
| 487 |
HandleObject moduleRequest); |
| 488 |
|
| 489 |
JSObject* StartDynamicModuleImport(JSContext* cx, HandleScript script, |
| 490 |
HandleValue specifier, HandleValue options); |
| 491 |
|
| 492 |
bool OnModuleEvaluationFailure(JSContext* cx, HandleObject evaluationPromise, |
| 493 |
JS::ModuleErrorBehaviour errorBehaviour); |
| 494 |
|
| 495 |
bool FinishDynamicModuleImport(JSContext* cx, HandleObject evaluationPromise, |
| 496 |
HandleValue referencingPrivate, |
| 497 |
HandleObject moduleRequest, |
| 498 |
HandleObject promise); |
| 499 |
|
| 500 |
} // namespace js |
| 501 |
|
| 502 |
template <> |
| 503 |
inline bool JSObject::is<js::ModuleNamespaceObject>() const { |
| 504 |
return js::IsDerivedProxyObject(this, |
| 505 |
&js::ModuleNamespaceObject::proxyHandler); |
| 506 |
} |
| 507 |
|
| 508 |
#endif /* builtin_ModuleObject_h */ |