11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#include "src/objects/source-text-module.h" 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci#include "src/api/api-inl.h" 81cb0ef41Sopenharmony_ci#include "src/ast/modules.h" 91cb0ef41Sopenharmony_ci#include "src/builtins/accessors.h" 101cb0ef41Sopenharmony_ci#include "src/common/assert-scope.h" 111cb0ef41Sopenharmony_ci#include "src/objects/js-generator-inl.h" 121cb0ef41Sopenharmony_ci#include "src/objects/module-inl.h" 131cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h" 141cb0ef41Sopenharmony_ci#include "src/objects/shared-function-info.h" 151cb0ef41Sopenharmony_ci#include "src/utils/ostreams.h" 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cinamespace v8 { 181cb0ef41Sopenharmony_cinamespace internal { 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cistruct StringHandleHash { 211cb0ef41Sopenharmony_ci V8_INLINE size_t operator()(Handle<String> string) const { 221cb0ef41Sopenharmony_ci return string->EnsureHash(); 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci}; 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_cistruct StringHandleEqual { 271cb0ef41Sopenharmony_ci V8_INLINE bool operator()(Handle<String> lhs, Handle<String> rhs) const { 281cb0ef41Sopenharmony_ci return lhs->Equals(*rhs); 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci}; 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciclass UnorderedStringSet 331cb0ef41Sopenharmony_ci : public std::unordered_set<Handle<String>, StringHandleHash, 341cb0ef41Sopenharmony_ci StringHandleEqual, 351cb0ef41Sopenharmony_ci ZoneAllocator<Handle<String>>> { 361cb0ef41Sopenharmony_ci public: 371cb0ef41Sopenharmony_ci explicit UnorderedStringSet(Zone* zone) 381cb0ef41Sopenharmony_ci : std::unordered_set<Handle<String>, StringHandleHash, StringHandleEqual, 391cb0ef41Sopenharmony_ci ZoneAllocator<Handle<String>>>( 401cb0ef41Sopenharmony_ci 2 /* bucket count */, StringHandleHash(), StringHandleEqual(), 411cb0ef41Sopenharmony_ci ZoneAllocator<Handle<String>>(zone)) {} 421cb0ef41Sopenharmony_ci}; 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ciclass UnorderedStringMap 451cb0ef41Sopenharmony_ci : public std::unordered_map< 461cb0ef41Sopenharmony_ci Handle<String>, Handle<Object>, StringHandleHash, StringHandleEqual, 471cb0ef41Sopenharmony_ci ZoneAllocator<std::pair<const Handle<String>, Handle<Object>>>> { 481cb0ef41Sopenharmony_ci public: 491cb0ef41Sopenharmony_ci explicit UnorderedStringMap(Zone* zone) 501cb0ef41Sopenharmony_ci : std::unordered_map< 511cb0ef41Sopenharmony_ci Handle<String>, Handle<Object>, StringHandleHash, StringHandleEqual, 521cb0ef41Sopenharmony_ci ZoneAllocator<std::pair<const Handle<String>, Handle<Object>>>>( 531cb0ef41Sopenharmony_ci 2 /* bucket count */, StringHandleHash(), StringHandleEqual(), 541cb0ef41Sopenharmony_ci ZoneAllocator<std::pair<const Handle<String>, Handle<Object>>>( 551cb0ef41Sopenharmony_ci zone)) {} 561cb0ef41Sopenharmony_ci}; 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ciclass Module::ResolveSet 591cb0ef41Sopenharmony_ci : public std::unordered_map< 601cb0ef41Sopenharmony_ci Handle<Module>, UnorderedStringSet*, ModuleHandleHash, 611cb0ef41Sopenharmony_ci ModuleHandleEqual, 621cb0ef41Sopenharmony_ci ZoneAllocator<std::pair<const Handle<Module>, UnorderedStringSet*>>> { 631cb0ef41Sopenharmony_ci public: 641cb0ef41Sopenharmony_ci explicit ResolveSet(Zone* zone) 651cb0ef41Sopenharmony_ci : std::unordered_map<Handle<Module>, UnorderedStringSet*, 661cb0ef41Sopenharmony_ci ModuleHandleHash, ModuleHandleEqual, 671cb0ef41Sopenharmony_ci ZoneAllocator<std::pair<const Handle<Module>, 681cb0ef41Sopenharmony_ci UnorderedStringSet*>>>( 691cb0ef41Sopenharmony_ci 2 /* bucket count */, ModuleHandleHash(), ModuleHandleEqual(), 701cb0ef41Sopenharmony_ci ZoneAllocator<std::pair<const Handle<Module>, UnorderedStringSet*>>( 711cb0ef41Sopenharmony_ci zone)), 721cb0ef41Sopenharmony_ci zone_(zone) {} 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci Zone* zone() const { return zone_; } 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci private: 771cb0ef41Sopenharmony_ci Zone* zone_; 781cb0ef41Sopenharmony_ci}; 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_cistruct SourceTextModule::AsyncEvaluatingOrdinalCompare { 811cb0ef41Sopenharmony_ci bool operator()(Handle<SourceTextModule> lhs, 821cb0ef41Sopenharmony_ci Handle<SourceTextModule> rhs) const { 831cb0ef41Sopenharmony_ci DCHECK(lhs->IsAsyncEvaluating()); 841cb0ef41Sopenharmony_ci DCHECK(rhs->IsAsyncEvaluating()); 851cb0ef41Sopenharmony_ci return lhs->async_evaluating_ordinal() < rhs->async_evaluating_ordinal(); 861cb0ef41Sopenharmony_ci } 871cb0ef41Sopenharmony_ci}; 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ciSharedFunctionInfo SourceTextModule::GetSharedFunctionInfo() const { 901cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 911cb0ef41Sopenharmony_ci switch (status()) { 921cb0ef41Sopenharmony_ci case kUnlinked: 931cb0ef41Sopenharmony_ci case kPreLinking: 941cb0ef41Sopenharmony_ci return SharedFunctionInfo::cast(code()); 951cb0ef41Sopenharmony_ci case kLinking: 961cb0ef41Sopenharmony_ci return JSFunction::cast(code()).shared(); 971cb0ef41Sopenharmony_ci case kLinked: 981cb0ef41Sopenharmony_ci case kEvaluating: 991cb0ef41Sopenharmony_ci case kEvaluatingAsync: 1001cb0ef41Sopenharmony_ci case kEvaluated: 1011cb0ef41Sopenharmony_ci return JSGeneratorObject::cast(code()).function().shared(); 1021cb0ef41Sopenharmony_ci case kErrored: 1031cb0ef41Sopenharmony_ci return SharedFunctionInfo::cast(code()); 1041cb0ef41Sopenharmony_ci } 1051cb0ef41Sopenharmony_ci UNREACHABLE(); 1061cb0ef41Sopenharmony_ci} 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ciScript SourceTextModule::GetScript() const { 1091cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 1101cb0ef41Sopenharmony_ci return Script::cast(GetSharedFunctionInfo().script()); 1111cb0ef41Sopenharmony_ci} 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_ciint SourceTextModule::ExportIndex(int cell_index) { 1141cb0ef41Sopenharmony_ci DCHECK_EQ(SourceTextModuleDescriptor::GetCellIndexKind(cell_index), 1151cb0ef41Sopenharmony_ci SourceTextModuleDescriptor::kExport); 1161cb0ef41Sopenharmony_ci return cell_index - 1; 1171cb0ef41Sopenharmony_ci} 1181cb0ef41Sopenharmony_ci 1191cb0ef41Sopenharmony_ciint SourceTextModule::ImportIndex(int cell_index) { 1201cb0ef41Sopenharmony_ci DCHECK_EQ(SourceTextModuleDescriptor::GetCellIndexKind(cell_index), 1211cb0ef41Sopenharmony_ci SourceTextModuleDescriptor::kImport); 1221cb0ef41Sopenharmony_ci return -cell_index - 1; 1231cb0ef41Sopenharmony_ci} 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_civoid SourceTextModule::CreateIndirectExport( 1261cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, Handle<String> name, 1271cb0ef41Sopenharmony_ci Handle<SourceTextModuleInfoEntry> entry) { 1281cb0ef41Sopenharmony_ci Handle<ObjectHashTable> exports(module->exports(), isolate); 1291cb0ef41Sopenharmony_ci DCHECK(exports->Lookup(name).IsTheHole(isolate)); 1301cb0ef41Sopenharmony_ci exports = ObjectHashTable::Put(exports, name, entry); 1311cb0ef41Sopenharmony_ci module->set_exports(*exports); 1321cb0ef41Sopenharmony_ci} 1331cb0ef41Sopenharmony_ci 1341cb0ef41Sopenharmony_civoid SourceTextModule::CreateExport(Isolate* isolate, 1351cb0ef41Sopenharmony_ci Handle<SourceTextModule> module, 1361cb0ef41Sopenharmony_ci int cell_index, Handle<FixedArray> names) { 1371cb0ef41Sopenharmony_ci DCHECK_LT(0, names->length()); 1381cb0ef41Sopenharmony_ci Handle<Cell> cell = 1391cb0ef41Sopenharmony_ci isolate->factory()->NewCell(isolate->factory()->undefined_value()); 1401cb0ef41Sopenharmony_ci module->regular_exports().set(ExportIndex(cell_index), *cell); 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_ci Handle<ObjectHashTable> exports(module->exports(), isolate); 1431cb0ef41Sopenharmony_ci for (int i = 0, n = names->length(); i < n; ++i) { 1441cb0ef41Sopenharmony_ci Handle<String> name(String::cast(names->get(i)), isolate); 1451cb0ef41Sopenharmony_ci DCHECK(exports->Lookup(name).IsTheHole(isolate)); 1461cb0ef41Sopenharmony_ci exports = ObjectHashTable::Put(exports, name, cell); 1471cb0ef41Sopenharmony_ci } 1481cb0ef41Sopenharmony_ci module->set_exports(*exports); 1491cb0ef41Sopenharmony_ci} 1501cb0ef41Sopenharmony_ci 1511cb0ef41Sopenharmony_ciCell SourceTextModule::GetCell(int cell_index) { 1521cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 1531cb0ef41Sopenharmony_ci Object cell; 1541cb0ef41Sopenharmony_ci switch (SourceTextModuleDescriptor::GetCellIndexKind(cell_index)) { 1551cb0ef41Sopenharmony_ci case SourceTextModuleDescriptor::kImport: 1561cb0ef41Sopenharmony_ci cell = regular_imports().get(ImportIndex(cell_index)); 1571cb0ef41Sopenharmony_ci break; 1581cb0ef41Sopenharmony_ci case SourceTextModuleDescriptor::kExport: 1591cb0ef41Sopenharmony_ci cell = regular_exports().get(ExportIndex(cell_index)); 1601cb0ef41Sopenharmony_ci break; 1611cb0ef41Sopenharmony_ci case SourceTextModuleDescriptor::kInvalid: 1621cb0ef41Sopenharmony_ci UNREACHABLE(); 1631cb0ef41Sopenharmony_ci } 1641cb0ef41Sopenharmony_ci return Cell::cast(cell); 1651cb0ef41Sopenharmony_ci} 1661cb0ef41Sopenharmony_ci 1671cb0ef41Sopenharmony_ciHandle<Object> SourceTextModule::LoadVariable(Isolate* isolate, 1681cb0ef41Sopenharmony_ci Handle<SourceTextModule> module, 1691cb0ef41Sopenharmony_ci int cell_index) { 1701cb0ef41Sopenharmony_ci return handle(module->GetCell(cell_index).value(), isolate); 1711cb0ef41Sopenharmony_ci} 1721cb0ef41Sopenharmony_ci 1731cb0ef41Sopenharmony_civoid SourceTextModule::StoreVariable(Handle<SourceTextModule> module, 1741cb0ef41Sopenharmony_ci int cell_index, Handle<Object> value) { 1751cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 1761cb0ef41Sopenharmony_ci DCHECK_EQ(SourceTextModuleDescriptor::GetCellIndexKind(cell_index), 1771cb0ef41Sopenharmony_ci SourceTextModuleDescriptor::kExport); 1781cb0ef41Sopenharmony_ci module->GetCell(cell_index).set_value(*value); 1791cb0ef41Sopenharmony_ci} 1801cb0ef41Sopenharmony_ci 1811cb0ef41Sopenharmony_ciMaybeHandle<Cell> SourceTextModule::ResolveExport( 1821cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, 1831cb0ef41Sopenharmony_ci Handle<String> module_specifier, Handle<String> export_name, 1841cb0ef41Sopenharmony_ci MessageLocation loc, bool must_resolve, Module::ResolveSet* resolve_set) { 1851cb0ef41Sopenharmony_ci Handle<Object> object(module->exports().Lookup(export_name), isolate); 1861cb0ef41Sopenharmony_ci if (object->IsCell()) { 1871cb0ef41Sopenharmony_ci // Already resolved (e.g. because it's a local export). 1881cb0ef41Sopenharmony_ci return Handle<Cell>::cast(object); 1891cb0ef41Sopenharmony_ci } 1901cb0ef41Sopenharmony_ci 1911cb0ef41Sopenharmony_ci // Check for cycle before recursing. 1921cb0ef41Sopenharmony_ci { 1931cb0ef41Sopenharmony_ci // Attempt insertion with a null string set. 1941cb0ef41Sopenharmony_ci auto result = resolve_set->insert({module, nullptr}); 1951cb0ef41Sopenharmony_ci UnorderedStringSet*& name_set = result.first->second; 1961cb0ef41Sopenharmony_ci if (result.second) { 1971cb0ef41Sopenharmony_ci // |module| wasn't in the map previously, so allocate a new name set. 1981cb0ef41Sopenharmony_ci Zone* zone = resolve_set->zone(); 1991cb0ef41Sopenharmony_ci name_set = zone->New<UnorderedStringSet>(zone); 2001cb0ef41Sopenharmony_ci } else if (name_set->count(export_name)) { 2011cb0ef41Sopenharmony_ci // Cycle detected. 2021cb0ef41Sopenharmony_ci if (must_resolve) { 2031cb0ef41Sopenharmony_ci return isolate->ThrowAt<Cell>( 2041cb0ef41Sopenharmony_ci isolate->factory()->NewSyntaxError( 2051cb0ef41Sopenharmony_ci MessageTemplate::kCyclicModuleDependency, export_name, 2061cb0ef41Sopenharmony_ci module_specifier), 2071cb0ef41Sopenharmony_ci &loc); 2081cb0ef41Sopenharmony_ci } 2091cb0ef41Sopenharmony_ci return MaybeHandle<Cell>(); 2101cb0ef41Sopenharmony_ci } 2111cb0ef41Sopenharmony_ci name_set->insert(export_name); 2121cb0ef41Sopenharmony_ci } 2131cb0ef41Sopenharmony_ci 2141cb0ef41Sopenharmony_ci if (object->IsSourceTextModuleInfoEntry()) { 2151cb0ef41Sopenharmony_ci // Not yet resolved indirect export. 2161cb0ef41Sopenharmony_ci Handle<SourceTextModuleInfoEntry> entry = 2171cb0ef41Sopenharmony_ci Handle<SourceTextModuleInfoEntry>::cast(object); 2181cb0ef41Sopenharmony_ci Handle<String> import_name(String::cast(entry->import_name()), isolate); 2191cb0ef41Sopenharmony_ci Handle<Script> script(module->GetScript(), isolate); 2201cb0ef41Sopenharmony_ci MessageLocation new_loc(script, entry->beg_pos(), entry->end_pos()); 2211cb0ef41Sopenharmony_ci 2221cb0ef41Sopenharmony_ci Handle<Cell> cell; 2231cb0ef41Sopenharmony_ci if (!ResolveImport(isolate, module, import_name, entry->module_request(), 2241cb0ef41Sopenharmony_ci new_loc, true, resolve_set) 2251cb0ef41Sopenharmony_ci .ToHandle(&cell)) { 2261cb0ef41Sopenharmony_ci DCHECK(isolate->has_pending_exception()); 2271cb0ef41Sopenharmony_ci return MaybeHandle<Cell>(); 2281cb0ef41Sopenharmony_ci } 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_ci // The export table may have changed but the entry in question should be 2311cb0ef41Sopenharmony_ci // unchanged. 2321cb0ef41Sopenharmony_ci Handle<ObjectHashTable> exports(module->exports(), isolate); 2331cb0ef41Sopenharmony_ci DCHECK(exports->Lookup(export_name).IsSourceTextModuleInfoEntry()); 2341cb0ef41Sopenharmony_ci 2351cb0ef41Sopenharmony_ci exports = ObjectHashTable::Put(exports, export_name, cell); 2361cb0ef41Sopenharmony_ci module->set_exports(*exports); 2371cb0ef41Sopenharmony_ci return cell; 2381cb0ef41Sopenharmony_ci } 2391cb0ef41Sopenharmony_ci 2401cb0ef41Sopenharmony_ci DCHECK(object->IsTheHole(isolate)); 2411cb0ef41Sopenharmony_ci return SourceTextModule::ResolveExportUsingStarExports( 2421cb0ef41Sopenharmony_ci isolate, module, module_specifier, export_name, loc, must_resolve, 2431cb0ef41Sopenharmony_ci resolve_set); 2441cb0ef41Sopenharmony_ci} 2451cb0ef41Sopenharmony_ci 2461cb0ef41Sopenharmony_ciMaybeHandle<Cell> SourceTextModule::ResolveImport( 2471cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, Handle<String> name, 2481cb0ef41Sopenharmony_ci int module_request_index, MessageLocation loc, bool must_resolve, 2491cb0ef41Sopenharmony_ci Module::ResolveSet* resolve_set) { 2501cb0ef41Sopenharmony_ci Handle<Module> requested_module( 2511cb0ef41Sopenharmony_ci Module::cast(module->requested_modules().get(module_request_index)), 2521cb0ef41Sopenharmony_ci isolate); 2531cb0ef41Sopenharmony_ci Handle<ModuleRequest> module_request( 2541cb0ef41Sopenharmony_ci ModuleRequest::cast( 2551cb0ef41Sopenharmony_ci module->info().module_requests().get(module_request_index)), 2561cb0ef41Sopenharmony_ci isolate); 2571cb0ef41Sopenharmony_ci Handle<String> module_specifier(String::cast(module_request->specifier()), 2581cb0ef41Sopenharmony_ci isolate); 2591cb0ef41Sopenharmony_ci MaybeHandle<Cell> result = 2601cb0ef41Sopenharmony_ci Module::ResolveExport(isolate, requested_module, module_specifier, name, 2611cb0ef41Sopenharmony_ci loc, must_resolve, resolve_set); 2621cb0ef41Sopenharmony_ci DCHECK_IMPLIES(isolate->has_pending_exception(), result.is_null()); 2631cb0ef41Sopenharmony_ci return result; 2641cb0ef41Sopenharmony_ci} 2651cb0ef41Sopenharmony_ci 2661cb0ef41Sopenharmony_ciMaybeHandle<Cell> SourceTextModule::ResolveExportUsingStarExports( 2671cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, 2681cb0ef41Sopenharmony_ci Handle<String> module_specifier, Handle<String> export_name, 2691cb0ef41Sopenharmony_ci MessageLocation loc, bool must_resolve, Module::ResolveSet* resolve_set) { 2701cb0ef41Sopenharmony_ci if (!export_name->Equals(ReadOnlyRoots(isolate).default_string())) { 2711cb0ef41Sopenharmony_ci // Go through all star exports looking for the given name. If multiple star 2721cb0ef41Sopenharmony_ci // exports provide the name, make sure they all map it to the same cell. 2731cb0ef41Sopenharmony_ci Handle<Cell> unique_cell; 2741cb0ef41Sopenharmony_ci Handle<FixedArray> special_exports(module->info().special_exports(), 2751cb0ef41Sopenharmony_ci isolate); 2761cb0ef41Sopenharmony_ci for (int i = 0, n = special_exports->length(); i < n; ++i) { 2771cb0ef41Sopenharmony_ci i::Handle<i::SourceTextModuleInfoEntry> entry( 2781cb0ef41Sopenharmony_ci i::SourceTextModuleInfoEntry::cast(special_exports->get(i)), isolate); 2791cb0ef41Sopenharmony_ci if (!entry->export_name().IsUndefined(isolate)) { 2801cb0ef41Sopenharmony_ci continue; // Indirect export. 2811cb0ef41Sopenharmony_ci } 2821cb0ef41Sopenharmony_ci 2831cb0ef41Sopenharmony_ci Handle<Script> script(module->GetScript(), isolate); 2841cb0ef41Sopenharmony_ci MessageLocation new_loc(script, entry->beg_pos(), entry->end_pos()); 2851cb0ef41Sopenharmony_ci 2861cb0ef41Sopenharmony_ci Handle<Cell> cell; 2871cb0ef41Sopenharmony_ci if (ResolveImport(isolate, module, export_name, entry->module_request(), 2881cb0ef41Sopenharmony_ci new_loc, false, resolve_set) 2891cb0ef41Sopenharmony_ci .ToHandle(&cell)) { 2901cb0ef41Sopenharmony_ci if (unique_cell.is_null()) unique_cell = cell; 2911cb0ef41Sopenharmony_ci if (*unique_cell != *cell) { 2921cb0ef41Sopenharmony_ci return isolate->ThrowAt<Cell>(isolate->factory()->NewSyntaxError( 2931cb0ef41Sopenharmony_ci MessageTemplate::kAmbiguousExport, 2941cb0ef41Sopenharmony_ci module_specifier, export_name), 2951cb0ef41Sopenharmony_ci &loc); 2961cb0ef41Sopenharmony_ci } 2971cb0ef41Sopenharmony_ci } else if (isolate->has_pending_exception()) { 2981cb0ef41Sopenharmony_ci return MaybeHandle<Cell>(); 2991cb0ef41Sopenharmony_ci } 3001cb0ef41Sopenharmony_ci } 3011cb0ef41Sopenharmony_ci 3021cb0ef41Sopenharmony_ci if (!unique_cell.is_null()) { 3031cb0ef41Sopenharmony_ci // Found a unique star export for this name. 3041cb0ef41Sopenharmony_ci Handle<ObjectHashTable> exports(module->exports(), isolate); 3051cb0ef41Sopenharmony_ci DCHECK(exports->Lookup(export_name).IsTheHole(isolate)); 3061cb0ef41Sopenharmony_ci exports = ObjectHashTable::Put(exports, export_name, unique_cell); 3071cb0ef41Sopenharmony_ci module->set_exports(*exports); 3081cb0ef41Sopenharmony_ci return unique_cell; 3091cb0ef41Sopenharmony_ci } 3101cb0ef41Sopenharmony_ci } 3111cb0ef41Sopenharmony_ci 3121cb0ef41Sopenharmony_ci // Unresolvable. 3131cb0ef41Sopenharmony_ci if (must_resolve) { 3141cb0ef41Sopenharmony_ci return isolate->ThrowAt<Cell>( 3151cb0ef41Sopenharmony_ci isolate->factory()->NewSyntaxError(MessageTemplate::kUnresolvableExport, 3161cb0ef41Sopenharmony_ci module_specifier, export_name), 3171cb0ef41Sopenharmony_ci &loc); 3181cb0ef41Sopenharmony_ci } 3191cb0ef41Sopenharmony_ci return MaybeHandle<Cell>(); 3201cb0ef41Sopenharmony_ci} 3211cb0ef41Sopenharmony_ci 3221cb0ef41Sopenharmony_cibool SourceTextModule::PrepareInstantiate( 3231cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, 3241cb0ef41Sopenharmony_ci v8::Local<v8::Context> context, v8::Module::ResolveModuleCallback callback, 3251cb0ef41Sopenharmony_ci Module::DeprecatedResolveCallback callback_without_import_assertions) { 3261cb0ef41Sopenharmony_ci DCHECK_EQ(callback != nullptr, callback_without_import_assertions == nullptr); 3271cb0ef41Sopenharmony_ci // Obtain requested modules. 3281cb0ef41Sopenharmony_ci Handle<SourceTextModuleInfo> module_info(module->info(), isolate); 3291cb0ef41Sopenharmony_ci Handle<FixedArray> module_requests(module_info->module_requests(), isolate); 3301cb0ef41Sopenharmony_ci Handle<FixedArray> requested_modules(module->requested_modules(), isolate); 3311cb0ef41Sopenharmony_ci for (int i = 0, length = module_requests->length(); i < length; ++i) { 3321cb0ef41Sopenharmony_ci Handle<ModuleRequest> module_request( 3331cb0ef41Sopenharmony_ci ModuleRequest::cast(module_requests->get(i)), isolate); 3341cb0ef41Sopenharmony_ci Handle<String> specifier(module_request->specifier(), isolate); 3351cb0ef41Sopenharmony_ci v8::Local<v8::Module> api_requested_module; 3361cb0ef41Sopenharmony_ci if (callback) { 3371cb0ef41Sopenharmony_ci Handle<FixedArray> import_assertions(module_request->import_assertions(), 3381cb0ef41Sopenharmony_ci isolate); 3391cb0ef41Sopenharmony_ci if (!callback(context, v8::Utils::ToLocal(specifier), 3401cb0ef41Sopenharmony_ci v8::Utils::FixedArrayToLocal(import_assertions), 3411cb0ef41Sopenharmony_ci v8::Utils::ToLocal(Handle<Module>::cast(module))) 3421cb0ef41Sopenharmony_ci .ToLocal(&api_requested_module)) { 3431cb0ef41Sopenharmony_ci isolate->PromoteScheduledException(); 3441cb0ef41Sopenharmony_ci return false; 3451cb0ef41Sopenharmony_ci } 3461cb0ef41Sopenharmony_ci } else { 3471cb0ef41Sopenharmony_ci if (!callback_without_import_assertions( 3481cb0ef41Sopenharmony_ci context, v8::Utils::ToLocal(specifier), 3491cb0ef41Sopenharmony_ci v8::Utils::ToLocal(Handle<Module>::cast(module))) 3501cb0ef41Sopenharmony_ci .ToLocal(&api_requested_module)) { 3511cb0ef41Sopenharmony_ci isolate->PromoteScheduledException(); 3521cb0ef41Sopenharmony_ci return false; 3531cb0ef41Sopenharmony_ci } 3541cb0ef41Sopenharmony_ci } 3551cb0ef41Sopenharmony_ci Handle<Module> requested_module = Utils::OpenHandle(*api_requested_module); 3561cb0ef41Sopenharmony_ci requested_modules->set(i, *requested_module); 3571cb0ef41Sopenharmony_ci } 3581cb0ef41Sopenharmony_ci 3591cb0ef41Sopenharmony_ci // Recurse. 3601cb0ef41Sopenharmony_ci for (int i = 0, length = requested_modules->length(); i < length; ++i) { 3611cb0ef41Sopenharmony_ci Handle<Module> requested_module(Module::cast(requested_modules->get(i)), 3621cb0ef41Sopenharmony_ci isolate); 3631cb0ef41Sopenharmony_ci if (!Module::PrepareInstantiate(isolate, requested_module, context, 3641cb0ef41Sopenharmony_ci callback, 3651cb0ef41Sopenharmony_ci callback_without_import_assertions)) { 3661cb0ef41Sopenharmony_ci return false; 3671cb0ef41Sopenharmony_ci } 3681cb0ef41Sopenharmony_ci } 3691cb0ef41Sopenharmony_ci 3701cb0ef41Sopenharmony_ci // Set up local exports. 3711cb0ef41Sopenharmony_ci // TODO(neis): Create regular_exports array here instead of in factory method? 3721cb0ef41Sopenharmony_ci for (int i = 0, n = module_info->RegularExportCount(); i < n; ++i) { 3731cb0ef41Sopenharmony_ci int cell_index = module_info->RegularExportCellIndex(i); 3741cb0ef41Sopenharmony_ci Handle<FixedArray> export_names(module_info->RegularExportExportNames(i), 3751cb0ef41Sopenharmony_ci isolate); 3761cb0ef41Sopenharmony_ci CreateExport(isolate, module, cell_index, export_names); 3771cb0ef41Sopenharmony_ci } 3781cb0ef41Sopenharmony_ci 3791cb0ef41Sopenharmony_ci // Partially set up indirect exports. 3801cb0ef41Sopenharmony_ci // For each indirect export, we create the appropriate slot in the export 3811cb0ef41Sopenharmony_ci // table and store its SourceTextModuleInfoEntry there. When we later find 3821cb0ef41Sopenharmony_ci // the correct Cell in the module that actually provides the value, we replace 3831cb0ef41Sopenharmony_ci // the SourceTextModuleInfoEntry by that Cell (see ResolveExport). 3841cb0ef41Sopenharmony_ci Handle<FixedArray> special_exports(module_info->special_exports(), isolate); 3851cb0ef41Sopenharmony_ci for (int i = 0, n = special_exports->length(); i < n; ++i) { 3861cb0ef41Sopenharmony_ci Handle<SourceTextModuleInfoEntry> entry( 3871cb0ef41Sopenharmony_ci SourceTextModuleInfoEntry::cast(special_exports->get(i)), isolate); 3881cb0ef41Sopenharmony_ci Handle<Object> export_name(entry->export_name(), isolate); 3891cb0ef41Sopenharmony_ci if (export_name->IsUndefined(isolate)) continue; // Star export. 3901cb0ef41Sopenharmony_ci CreateIndirectExport(isolate, module, Handle<String>::cast(export_name), 3911cb0ef41Sopenharmony_ci entry); 3921cb0ef41Sopenharmony_ci } 3931cb0ef41Sopenharmony_ci 3941cb0ef41Sopenharmony_ci DCHECK_EQ(module->status(), kPreLinking); 3951cb0ef41Sopenharmony_ci return true; 3961cb0ef41Sopenharmony_ci} 3971cb0ef41Sopenharmony_ci 3981cb0ef41Sopenharmony_cibool SourceTextModule::RunInitializationCode(Isolate* isolate, 3991cb0ef41Sopenharmony_ci Handle<SourceTextModule> module) { 4001cb0ef41Sopenharmony_ci DCHECK_EQ(module->status(), kLinking); 4011cb0ef41Sopenharmony_ci Handle<JSFunction> function(JSFunction::cast(module->code()), isolate); 4021cb0ef41Sopenharmony_ci DCHECK_EQ(MODULE_SCOPE, function->shared().scope_info().scope_type()); 4031cb0ef41Sopenharmony_ci Handle<Object> receiver = isolate->factory()->undefined_value(); 4041cb0ef41Sopenharmony_ci 4051cb0ef41Sopenharmony_ci Handle<ScopeInfo> scope_info(function->shared().scope_info(), isolate); 4061cb0ef41Sopenharmony_ci Handle<Context> context = isolate->factory()->NewModuleContext( 4071cb0ef41Sopenharmony_ci module, isolate->native_context(), scope_info); 4081cb0ef41Sopenharmony_ci function->set_context(*context); 4091cb0ef41Sopenharmony_ci 4101cb0ef41Sopenharmony_ci MaybeHandle<Object> maybe_generator = 4111cb0ef41Sopenharmony_ci Execution::Call(isolate, function, receiver, 0, {}); 4121cb0ef41Sopenharmony_ci Handle<Object> generator; 4131cb0ef41Sopenharmony_ci if (!maybe_generator.ToHandle(&generator)) { 4141cb0ef41Sopenharmony_ci DCHECK(isolate->has_pending_exception()); 4151cb0ef41Sopenharmony_ci return false; 4161cb0ef41Sopenharmony_ci } 4171cb0ef41Sopenharmony_ci DCHECK_EQ(*function, Handle<JSGeneratorObject>::cast(generator)->function()); 4181cb0ef41Sopenharmony_ci module->set_code(JSGeneratorObject::cast(*generator)); 4191cb0ef41Sopenharmony_ci return true; 4201cb0ef41Sopenharmony_ci} 4211cb0ef41Sopenharmony_ci 4221cb0ef41Sopenharmony_cibool SourceTextModule::MaybeTransitionComponent( 4231cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, 4241cb0ef41Sopenharmony_ci ZoneForwardList<Handle<SourceTextModule>>* stack, Status new_status) { 4251cb0ef41Sopenharmony_ci DCHECK(new_status == kLinked || new_status == kEvaluated); 4261cb0ef41Sopenharmony_ci SLOW_DCHECK( 4271cb0ef41Sopenharmony_ci // {module} is on the {stack}. 4281cb0ef41Sopenharmony_ci std::count_if(stack->begin(), stack->end(), 4291cb0ef41Sopenharmony_ci [&](Handle<Module> m) { return *m == *module; }) == 1); 4301cb0ef41Sopenharmony_ci DCHECK_LE(module->dfs_ancestor_index(), module->dfs_index()); 4311cb0ef41Sopenharmony_ci if (module->dfs_ancestor_index() == module->dfs_index()) { 4321cb0ef41Sopenharmony_ci // This is the root of its strongly connected component. 4331cb0ef41Sopenharmony_ci Handle<SourceTextModule> cycle_root = module; 4341cb0ef41Sopenharmony_ci Handle<SourceTextModule> ancestor; 4351cb0ef41Sopenharmony_ci do { 4361cb0ef41Sopenharmony_ci ancestor = stack->front(); 4371cb0ef41Sopenharmony_ci stack->pop_front(); 4381cb0ef41Sopenharmony_ci DCHECK_EQ(ancestor->status(), 4391cb0ef41Sopenharmony_ci new_status == kLinked ? kLinking : kEvaluating); 4401cb0ef41Sopenharmony_ci if (new_status == kLinked) { 4411cb0ef41Sopenharmony_ci if (!SourceTextModule::RunInitializationCode(isolate, ancestor)) 4421cb0ef41Sopenharmony_ci return false; 4431cb0ef41Sopenharmony_ci } else if (new_status == kEvaluated) { 4441cb0ef41Sopenharmony_ci DCHECK(ancestor->cycle_root().IsTheHole(isolate)); 4451cb0ef41Sopenharmony_ci ancestor->set_cycle_root(*cycle_root); 4461cb0ef41Sopenharmony_ci } 4471cb0ef41Sopenharmony_ci ancestor->SetStatus(new_status); 4481cb0ef41Sopenharmony_ci } while (*ancestor != *module); 4491cb0ef41Sopenharmony_ci } 4501cb0ef41Sopenharmony_ci return true; 4511cb0ef41Sopenharmony_ci} 4521cb0ef41Sopenharmony_ci 4531cb0ef41Sopenharmony_cibool SourceTextModule::FinishInstantiate( 4541cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, 4551cb0ef41Sopenharmony_ci ZoneForwardList<Handle<SourceTextModule>>* stack, unsigned* dfs_index, 4561cb0ef41Sopenharmony_ci Zone* zone) { 4571cb0ef41Sopenharmony_ci // Instantiate SharedFunctionInfo and mark module as instantiating for 4581cb0ef41Sopenharmony_ci // the recursion. 4591cb0ef41Sopenharmony_ci Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(module->code()), 4601cb0ef41Sopenharmony_ci isolate); 4611cb0ef41Sopenharmony_ci Handle<JSFunction> function = 4621cb0ef41Sopenharmony_ci Factory::JSFunctionBuilder{isolate, shared, isolate->native_context()} 4631cb0ef41Sopenharmony_ci .Build(); 4641cb0ef41Sopenharmony_ci module->set_code(*function); 4651cb0ef41Sopenharmony_ci module->SetStatus(kLinking); 4661cb0ef41Sopenharmony_ci module->set_dfs_index(*dfs_index); 4671cb0ef41Sopenharmony_ci module->set_dfs_ancestor_index(*dfs_index); 4681cb0ef41Sopenharmony_ci stack->push_front(module); 4691cb0ef41Sopenharmony_ci (*dfs_index)++; 4701cb0ef41Sopenharmony_ci 4711cb0ef41Sopenharmony_ci // Recurse. 4721cb0ef41Sopenharmony_ci Handle<FixedArray> requested_modules(module->requested_modules(), isolate); 4731cb0ef41Sopenharmony_ci for (int i = 0, length = requested_modules->length(); i < length; ++i) { 4741cb0ef41Sopenharmony_ci Handle<Module> requested_module(Module::cast(requested_modules->get(i)), 4751cb0ef41Sopenharmony_ci isolate); 4761cb0ef41Sopenharmony_ci if (!Module::FinishInstantiate(isolate, requested_module, stack, dfs_index, 4771cb0ef41Sopenharmony_ci zone)) { 4781cb0ef41Sopenharmony_ci return false; 4791cb0ef41Sopenharmony_ci } 4801cb0ef41Sopenharmony_ci 4811cb0ef41Sopenharmony_ci DCHECK_NE(requested_module->status(), kEvaluating); 4821cb0ef41Sopenharmony_ci DCHECK_GE(requested_module->status(), kLinking); 4831cb0ef41Sopenharmony_ci SLOW_DCHECK( 4841cb0ef41Sopenharmony_ci // {requested_module} is instantiating iff it's on the {stack}. 4851cb0ef41Sopenharmony_ci (requested_module->status() == kLinking) == 4861cb0ef41Sopenharmony_ci std::count_if(stack->begin(), stack->end(), [&](Handle<Module> m) { 4871cb0ef41Sopenharmony_ci return *m == *requested_module; 4881cb0ef41Sopenharmony_ci })); 4891cb0ef41Sopenharmony_ci 4901cb0ef41Sopenharmony_ci if (requested_module->status() == kLinking) { 4911cb0ef41Sopenharmony_ci // SyntheticModules go straight to kLinked so this must be a 4921cb0ef41Sopenharmony_ci // SourceTextModule 4931cb0ef41Sopenharmony_ci module->set_dfs_ancestor_index(std::min( 4941cb0ef41Sopenharmony_ci module->dfs_ancestor_index(), 4951cb0ef41Sopenharmony_ci SourceTextModule::cast(*requested_module).dfs_ancestor_index())); 4961cb0ef41Sopenharmony_ci } 4971cb0ef41Sopenharmony_ci } 4981cb0ef41Sopenharmony_ci 4991cb0ef41Sopenharmony_ci Handle<Script> script(module->GetScript(), isolate); 5001cb0ef41Sopenharmony_ci Handle<SourceTextModuleInfo> module_info(module->info(), isolate); 5011cb0ef41Sopenharmony_ci 5021cb0ef41Sopenharmony_ci // Resolve imports. 5031cb0ef41Sopenharmony_ci Handle<FixedArray> regular_imports(module_info->regular_imports(), isolate); 5041cb0ef41Sopenharmony_ci for (int i = 0, n = regular_imports->length(); i < n; ++i) { 5051cb0ef41Sopenharmony_ci Handle<SourceTextModuleInfoEntry> entry( 5061cb0ef41Sopenharmony_ci SourceTextModuleInfoEntry::cast(regular_imports->get(i)), isolate); 5071cb0ef41Sopenharmony_ci Handle<String> name(String::cast(entry->import_name()), isolate); 5081cb0ef41Sopenharmony_ci MessageLocation loc(script, entry->beg_pos(), entry->end_pos()); 5091cb0ef41Sopenharmony_ci ResolveSet resolve_set(zone); 5101cb0ef41Sopenharmony_ci Handle<Cell> cell; 5111cb0ef41Sopenharmony_ci if (!ResolveImport(isolate, module, name, entry->module_request(), loc, 5121cb0ef41Sopenharmony_ci true, &resolve_set) 5131cb0ef41Sopenharmony_ci .ToHandle(&cell)) { 5141cb0ef41Sopenharmony_ci return false; 5151cb0ef41Sopenharmony_ci } 5161cb0ef41Sopenharmony_ci module->regular_imports().set(ImportIndex(entry->cell_index()), *cell); 5171cb0ef41Sopenharmony_ci } 5181cb0ef41Sopenharmony_ci 5191cb0ef41Sopenharmony_ci // Resolve indirect exports. 5201cb0ef41Sopenharmony_ci Handle<FixedArray> special_exports(module_info->special_exports(), isolate); 5211cb0ef41Sopenharmony_ci for (int i = 0, n = special_exports->length(); i < n; ++i) { 5221cb0ef41Sopenharmony_ci Handle<SourceTextModuleInfoEntry> entry( 5231cb0ef41Sopenharmony_ci SourceTextModuleInfoEntry::cast(special_exports->get(i)), isolate); 5241cb0ef41Sopenharmony_ci Handle<Object> name(entry->export_name(), isolate); 5251cb0ef41Sopenharmony_ci if (name->IsUndefined(isolate)) continue; // Star export. 5261cb0ef41Sopenharmony_ci MessageLocation loc(script, entry->beg_pos(), entry->end_pos()); 5271cb0ef41Sopenharmony_ci ResolveSet resolve_set(zone); 5281cb0ef41Sopenharmony_ci if (ResolveExport(isolate, module, Handle<String>(), 5291cb0ef41Sopenharmony_ci Handle<String>::cast(name), loc, true, &resolve_set) 5301cb0ef41Sopenharmony_ci .is_null()) { 5311cb0ef41Sopenharmony_ci return false; 5321cb0ef41Sopenharmony_ci } 5331cb0ef41Sopenharmony_ci } 5341cb0ef41Sopenharmony_ci 5351cb0ef41Sopenharmony_ci return MaybeTransitionComponent(isolate, module, stack, kLinked); 5361cb0ef41Sopenharmony_ci} 5371cb0ef41Sopenharmony_ci 5381cb0ef41Sopenharmony_civoid SourceTextModule::FetchStarExports(Isolate* isolate, 5391cb0ef41Sopenharmony_ci Handle<SourceTextModule> module, 5401cb0ef41Sopenharmony_ci Zone* zone, 5411cb0ef41Sopenharmony_ci UnorderedModuleSet* visited) { 5421cb0ef41Sopenharmony_ci DCHECK_GE(module->status(), Module::kLinking); 5431cb0ef41Sopenharmony_ci 5441cb0ef41Sopenharmony_ci if (module->module_namespace().IsJSModuleNamespace()) return; // Shortcut. 5451cb0ef41Sopenharmony_ci 5461cb0ef41Sopenharmony_ci bool cycle = !visited->insert(module).second; 5471cb0ef41Sopenharmony_ci if (cycle) return; 5481cb0ef41Sopenharmony_ci Handle<ObjectHashTable> exports(module->exports(), isolate); 5491cb0ef41Sopenharmony_ci UnorderedStringMap more_exports(zone); 5501cb0ef41Sopenharmony_ci 5511cb0ef41Sopenharmony_ci // TODO(neis): Only allocate more_exports if there are star exports. 5521cb0ef41Sopenharmony_ci // Maybe split special_exports into indirect_exports and star_exports. 5531cb0ef41Sopenharmony_ci 5541cb0ef41Sopenharmony_ci ReadOnlyRoots roots(isolate); 5551cb0ef41Sopenharmony_ci Handle<FixedArray> special_exports(module->info().special_exports(), isolate); 5561cb0ef41Sopenharmony_ci for (int i = 0, n = special_exports->length(); i < n; ++i) { 5571cb0ef41Sopenharmony_ci Handle<SourceTextModuleInfoEntry> entry( 5581cb0ef41Sopenharmony_ci SourceTextModuleInfoEntry::cast(special_exports->get(i)), isolate); 5591cb0ef41Sopenharmony_ci if (!entry->export_name().IsUndefined(roots)) { 5601cb0ef41Sopenharmony_ci continue; // Indirect export. 5611cb0ef41Sopenharmony_ci } 5621cb0ef41Sopenharmony_ci 5631cb0ef41Sopenharmony_ci Handle<Module> requested_module( 5641cb0ef41Sopenharmony_ci Module::cast(module->requested_modules().get(entry->module_request())), 5651cb0ef41Sopenharmony_ci isolate); 5661cb0ef41Sopenharmony_ci 5671cb0ef41Sopenharmony_ci // Recurse. 5681cb0ef41Sopenharmony_ci if (requested_module->IsSourceTextModule()) 5691cb0ef41Sopenharmony_ci FetchStarExports(isolate, 5701cb0ef41Sopenharmony_ci Handle<SourceTextModule>::cast(requested_module), zone, 5711cb0ef41Sopenharmony_ci visited); 5721cb0ef41Sopenharmony_ci 5731cb0ef41Sopenharmony_ci // Collect all of [requested_module]'s exports that must be added to 5741cb0ef41Sopenharmony_ci // [module]'s exports (i.e. to [exports]). We record these in 5751cb0ef41Sopenharmony_ci // [more_exports]. Ambiguities (conflicting exports) are marked by mapping 5761cb0ef41Sopenharmony_ci // the name to undefined instead of a Cell. 5771cb0ef41Sopenharmony_ci Handle<ObjectHashTable> requested_exports(requested_module->exports(), 5781cb0ef41Sopenharmony_ci isolate); 5791cb0ef41Sopenharmony_ci for (InternalIndex index : requested_exports->IterateEntries()) { 5801cb0ef41Sopenharmony_ci Object key; 5811cb0ef41Sopenharmony_ci if (!requested_exports->ToKey(roots, index, &key)) continue; 5821cb0ef41Sopenharmony_ci Handle<String> name(String::cast(key), isolate); 5831cb0ef41Sopenharmony_ci 5841cb0ef41Sopenharmony_ci if (name->Equals(roots.default_string())) continue; 5851cb0ef41Sopenharmony_ci if (!exports->Lookup(name).IsTheHole(roots)) continue; 5861cb0ef41Sopenharmony_ci 5871cb0ef41Sopenharmony_ci Handle<Cell> cell(Cell::cast(requested_exports->ValueAt(index)), isolate); 5881cb0ef41Sopenharmony_ci auto insert_result = more_exports.insert(std::make_pair(name, cell)); 5891cb0ef41Sopenharmony_ci if (!insert_result.second) { 5901cb0ef41Sopenharmony_ci auto it = insert_result.first; 5911cb0ef41Sopenharmony_ci if (*it->second == *cell || it->second->IsUndefined(roots)) { 5921cb0ef41Sopenharmony_ci // We already recorded this mapping before, or the name is already 5931cb0ef41Sopenharmony_ci // known to be ambiguous. In either case, there's nothing to do. 5941cb0ef41Sopenharmony_ci } else { 5951cb0ef41Sopenharmony_ci DCHECK(it->second->IsCell()); 5961cb0ef41Sopenharmony_ci // Different star exports provide different cells for this name, hence 5971cb0ef41Sopenharmony_ci // mark the name as ambiguous. 5981cb0ef41Sopenharmony_ci it->second = roots.undefined_value_handle(); 5991cb0ef41Sopenharmony_ci } 6001cb0ef41Sopenharmony_ci } 6011cb0ef41Sopenharmony_ci } 6021cb0ef41Sopenharmony_ci } 6031cb0ef41Sopenharmony_ci 6041cb0ef41Sopenharmony_ci // Copy [more_exports] into [exports]. 6051cb0ef41Sopenharmony_ci for (const auto& elem : more_exports) { 6061cb0ef41Sopenharmony_ci if (elem.second->IsUndefined(isolate)) continue; // Ambiguous export. 6071cb0ef41Sopenharmony_ci DCHECK(!elem.first->Equals(ReadOnlyRoots(isolate).default_string())); 6081cb0ef41Sopenharmony_ci DCHECK(elem.second->IsCell()); 6091cb0ef41Sopenharmony_ci exports = ObjectHashTable::Put(exports, elem.first, elem.second); 6101cb0ef41Sopenharmony_ci } 6111cb0ef41Sopenharmony_ci module->set_exports(*exports); 6121cb0ef41Sopenharmony_ci} 6131cb0ef41Sopenharmony_ci 6141cb0ef41Sopenharmony_civoid SourceTextModule::GatherAsyncParentCompletions( 6151cb0ef41Sopenharmony_ci Isolate* isolate, Zone* zone, Handle<SourceTextModule> start, 6161cb0ef41Sopenharmony_ci AsyncParentCompletionSet* exec_list) { 6171cb0ef41Sopenharmony_ci // The spec algorithm is recursive. It is transformed to an equivalent 6181cb0ef41Sopenharmony_ci // iterative one here. 6191cb0ef41Sopenharmony_ci ZoneStack<Handle<SourceTextModule>> worklist(zone); 6201cb0ef41Sopenharmony_ci worklist.push(start); 6211cb0ef41Sopenharmony_ci 6221cb0ef41Sopenharmony_ci while (!worklist.empty()) { 6231cb0ef41Sopenharmony_ci Handle<SourceTextModule> module = worklist.top(); 6241cb0ef41Sopenharmony_ci worklist.pop(); 6251cb0ef41Sopenharmony_ci 6261cb0ef41Sopenharmony_ci // 1. Assert: module.[[Status]] is evaluated. 6271cb0ef41Sopenharmony_ci DCHECK_EQ(module->status(), kEvaluated); 6281cb0ef41Sopenharmony_ci 6291cb0ef41Sopenharmony_ci // 2. For each Module m of module.[[AsyncParentModules]], do 6301cb0ef41Sopenharmony_ci for (int i = module->AsyncParentModuleCount(); i-- > 0;) { 6311cb0ef41Sopenharmony_ci Handle<SourceTextModule> m = module->GetAsyncParentModule(isolate, i); 6321cb0ef41Sopenharmony_ci 6331cb0ef41Sopenharmony_ci // a. If execList does not contain m and 6341cb0ef41Sopenharmony_ci // m.[[CycleRoot]].[[EvaluationError]] is empty, then 6351cb0ef41Sopenharmony_ci if (exec_list->find(m) == exec_list->end() && 6361cb0ef41Sopenharmony_ci m->GetCycleRoot(isolate)->status() != kErrored) { 6371cb0ef41Sopenharmony_ci // i. Assert: m.[[EvaluationError]] is empty. 6381cb0ef41Sopenharmony_ci DCHECK_NE(m->status(), kErrored); 6391cb0ef41Sopenharmony_ci 6401cb0ef41Sopenharmony_ci // ii. Assert: m.[[AsyncEvaluating]] is true. 6411cb0ef41Sopenharmony_ci DCHECK(m->IsAsyncEvaluating()); 6421cb0ef41Sopenharmony_ci 6431cb0ef41Sopenharmony_ci // iii. Assert: m.[[PendingAsyncDependencies]] > 0. 6441cb0ef41Sopenharmony_ci DCHECK(m->HasPendingAsyncDependencies()); 6451cb0ef41Sopenharmony_ci 6461cb0ef41Sopenharmony_ci // iv. Set m.[[PendingAsyncDependencies]] to 6471cb0ef41Sopenharmony_ci // m.[[PendingAsyncDependencies]] - 1. 6481cb0ef41Sopenharmony_ci m->DecrementPendingAsyncDependencies(); 6491cb0ef41Sopenharmony_ci 6501cb0ef41Sopenharmony_ci // v. If m.[[PendingAsyncDependencies]] is equal to 0, then 6511cb0ef41Sopenharmony_ci if (!m->HasPendingAsyncDependencies()) { 6521cb0ef41Sopenharmony_ci // 1. Append m to execList. 6531cb0ef41Sopenharmony_ci exec_list->insert(m); 6541cb0ef41Sopenharmony_ci 6551cb0ef41Sopenharmony_ci // 2. If m.[[Async]] is false, 6561cb0ef41Sopenharmony_ci // perform ! GatherAsyncParentCompletions(m, execList). 6571cb0ef41Sopenharmony_ci if (!m->async()) worklist.push(m); 6581cb0ef41Sopenharmony_ci } 6591cb0ef41Sopenharmony_ci } 6601cb0ef41Sopenharmony_ci } 6611cb0ef41Sopenharmony_ci } 6621cb0ef41Sopenharmony_ci 6631cb0ef41Sopenharmony_ci // 3. Return undefined. 6641cb0ef41Sopenharmony_ci} 6651cb0ef41Sopenharmony_ci 6661cb0ef41Sopenharmony_ciHandle<JSModuleNamespace> SourceTextModule::GetModuleNamespace( 6671cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, int module_request) { 6681cb0ef41Sopenharmony_ci Handle<Module> requested_module( 6691cb0ef41Sopenharmony_ci Module::cast(module->requested_modules().get(module_request)), isolate); 6701cb0ef41Sopenharmony_ci return Module::GetModuleNamespace(isolate, requested_module); 6711cb0ef41Sopenharmony_ci} 6721cb0ef41Sopenharmony_ci 6731cb0ef41Sopenharmony_ciMaybeHandle<JSObject> SourceTextModule::GetImportMeta( 6741cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module) { 6751cb0ef41Sopenharmony_ci Handle<HeapObject> import_meta(module->import_meta(kAcquireLoad), isolate); 6761cb0ef41Sopenharmony_ci if (import_meta->IsTheHole(isolate)) { 6771cb0ef41Sopenharmony_ci if (!isolate->RunHostInitializeImportMetaObjectCallback(module).ToHandle( 6781cb0ef41Sopenharmony_ci &import_meta)) { 6791cb0ef41Sopenharmony_ci return {}; 6801cb0ef41Sopenharmony_ci } 6811cb0ef41Sopenharmony_ci module->set_import_meta(*import_meta, kReleaseStore); 6821cb0ef41Sopenharmony_ci } 6831cb0ef41Sopenharmony_ci return Handle<JSObject>::cast(import_meta); 6841cb0ef41Sopenharmony_ci} 6851cb0ef41Sopenharmony_ci 6861cb0ef41Sopenharmony_ciMaybeHandle<Object> SourceTextModule::Evaluate( 6871cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module) { 6881cb0ef41Sopenharmony_ci CHECK(module->status() == kLinked || module->status() == kEvaluated); 6891cb0ef41Sopenharmony_ci 6901cb0ef41Sopenharmony_ci // 5. Let stack be a new empty List. 6911cb0ef41Sopenharmony_ci Zone zone(isolate->allocator(), ZONE_NAME); 6921cb0ef41Sopenharmony_ci ZoneForwardList<Handle<SourceTextModule>> stack(&zone); 6931cb0ef41Sopenharmony_ci unsigned dfs_index = 0; 6941cb0ef41Sopenharmony_ci 6951cb0ef41Sopenharmony_ci // 6. Let capability be ! NewPromiseCapability(%Promise%). 6961cb0ef41Sopenharmony_ci Handle<JSPromise> capability = isolate->factory()->NewJSPromise(); 6971cb0ef41Sopenharmony_ci 6981cb0ef41Sopenharmony_ci // 7. Set module.[[TopLevelCapability]] to capability. 6991cb0ef41Sopenharmony_ci module->set_top_level_capability(*capability); 7001cb0ef41Sopenharmony_ci DCHECK(module->top_level_capability().IsJSPromise()); 7011cb0ef41Sopenharmony_ci 7021cb0ef41Sopenharmony_ci // 8. Let result be InnerModuleEvaluation(module, stack, 0). 7031cb0ef41Sopenharmony_ci // 9. If result is an abrupt completion, then 7041cb0ef41Sopenharmony_ci Handle<Object> unused_result; 7051cb0ef41Sopenharmony_ci if (!InnerModuleEvaluation(isolate, module, &stack, &dfs_index) 7061cb0ef41Sopenharmony_ci .ToHandle(&unused_result)) { 7071cb0ef41Sopenharmony_ci // a. For each Cyclic Module Record m in stack, do 7081cb0ef41Sopenharmony_ci for (auto& descendant : stack) { 7091cb0ef41Sopenharmony_ci // i. Assert: m.[[Status]] is "evaluating". 7101cb0ef41Sopenharmony_ci CHECK_EQ(descendant->status(), kEvaluating); 7111cb0ef41Sopenharmony_ci // ii. Set m.[[Status]] to "evaluated". 7121cb0ef41Sopenharmony_ci // iii. Set m.[[EvaluationError]] to result. 7131cb0ef41Sopenharmony_ci Module::RecordErrorUsingPendingException(isolate, descendant); 7141cb0ef41Sopenharmony_ci } 7151cb0ef41Sopenharmony_ci 7161cb0ef41Sopenharmony_ci // If the exception was a termination exception, rejecting the promise 7171cb0ef41Sopenharmony_ci // would resume execution, and our API contract is to return an empty 7181cb0ef41Sopenharmony_ci // handle. The module's status should be set to kErrored and the 7191cb0ef41Sopenharmony_ci // exception field should be set to `null`. 7201cb0ef41Sopenharmony_ci if (!isolate->is_catchable_by_javascript(isolate->pending_exception())) { 7211cb0ef41Sopenharmony_ci CHECK_EQ(module->status(), kErrored); 7221cb0ef41Sopenharmony_ci CHECK_EQ(module->exception(), *isolate->factory()->null_value()); 7231cb0ef41Sopenharmony_ci return {}; 7241cb0ef41Sopenharmony_ci } 7251cb0ef41Sopenharmony_ci CHECK_EQ(module->exception(), isolate->pending_exception()); 7261cb0ef41Sopenharmony_ci 7271cb0ef41Sopenharmony_ci // d. Perform ! Call(capability.[[Reject]], undefined, 7281cb0ef41Sopenharmony_ci // «result.[[Value]]»). 7291cb0ef41Sopenharmony_ci isolate->clear_pending_exception(); 7301cb0ef41Sopenharmony_ci JSPromise::Reject(capability, handle(module->exception(), isolate)); 7311cb0ef41Sopenharmony_ci } else { 7321cb0ef41Sopenharmony_ci // 10. Otherwise, 7331cb0ef41Sopenharmony_ci // a. Assert: module.[[Status]] is "evaluated"... 7341cb0ef41Sopenharmony_ci CHECK_EQ(module->status(), kEvaluated); 7351cb0ef41Sopenharmony_ci 7361cb0ef41Sopenharmony_ci // b. If module.[[AsyncEvaluating]] is false, then 7371cb0ef41Sopenharmony_ci if (!module->IsAsyncEvaluating()) { 7381cb0ef41Sopenharmony_ci // i. Perform ! Call(capability.[[Resolve]], undefined, 7391cb0ef41Sopenharmony_ci // «undefined»). 7401cb0ef41Sopenharmony_ci JSPromise::Resolve(capability, isolate->factory()->undefined_value()) 7411cb0ef41Sopenharmony_ci .ToHandleChecked(); 7421cb0ef41Sopenharmony_ci } 7431cb0ef41Sopenharmony_ci 7441cb0ef41Sopenharmony_ci // c. Assert: stack is empty. 7451cb0ef41Sopenharmony_ci DCHECK(stack.empty()); 7461cb0ef41Sopenharmony_ci } 7471cb0ef41Sopenharmony_ci 7481cb0ef41Sopenharmony_ci // 11. Return capability.[[Promise]]. 7491cb0ef41Sopenharmony_ci return capability; 7501cb0ef41Sopenharmony_ci} 7511cb0ef41Sopenharmony_ci 7521cb0ef41Sopenharmony_ciMaybe<bool> SourceTextModule::AsyncModuleExecutionFulfilled( 7531cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module) { 7541cb0ef41Sopenharmony_ci // 1. If module.[[Status]] is evaluated, then 7551cb0ef41Sopenharmony_ci if (module->status() == kErrored) { 7561cb0ef41Sopenharmony_ci // a. Assert: module.[[EvaluationError]] is not empty. 7571cb0ef41Sopenharmony_ci DCHECK(!module->exception().IsTheHole(isolate)); 7581cb0ef41Sopenharmony_ci // b. Return. 7591cb0ef41Sopenharmony_ci return Just(true); 7601cb0ef41Sopenharmony_ci } 7611cb0ef41Sopenharmony_ci // 3. Assert: module.[[AsyncEvaluating]] is true. 7621cb0ef41Sopenharmony_ci DCHECK(module->IsAsyncEvaluating()); 7631cb0ef41Sopenharmony_ci // 4. Assert: module.[[EvaluationError]] is empty. 7641cb0ef41Sopenharmony_ci CHECK_EQ(module->status(), kEvaluated); 7651cb0ef41Sopenharmony_ci // 5. Set module.[[AsyncEvaluating]] to false. 7661cb0ef41Sopenharmony_ci isolate->DidFinishModuleAsyncEvaluation(module->async_evaluating_ordinal()); 7671cb0ef41Sopenharmony_ci module->set_async_evaluating_ordinal(kAsyncEvaluateDidFinish); 7681cb0ef41Sopenharmony_ci // TODO(cbruni): update to match spec. 7691cb0ef41Sopenharmony_ci // 7. If module.[[TopLevelCapability]] is not empty, then 7701cb0ef41Sopenharmony_ci if (!module->top_level_capability().IsUndefined(isolate)) { 7711cb0ef41Sopenharmony_ci // a. Assert: module.[[CycleRoot]] is equal to module. 7721cb0ef41Sopenharmony_ci DCHECK_EQ(*module->GetCycleRoot(isolate), *module); 7731cb0ef41Sopenharmony_ci // i. Perform ! Call(module.[[TopLevelCapability]].[[Resolve]], undefined, 7741cb0ef41Sopenharmony_ci // «undefined»). 7751cb0ef41Sopenharmony_ci Handle<JSPromise> capability( 7761cb0ef41Sopenharmony_ci JSPromise::cast(module->top_level_capability()), isolate); 7771cb0ef41Sopenharmony_ci JSPromise::Resolve(capability, isolate->factory()->undefined_value()) 7781cb0ef41Sopenharmony_ci .ToHandleChecked(); 7791cb0ef41Sopenharmony_ci } 7801cb0ef41Sopenharmony_ci 7811cb0ef41Sopenharmony_ci // 8. Let execList be a new empty List. 7821cb0ef41Sopenharmony_ci Zone zone(isolate->allocator(), ZONE_NAME); 7831cb0ef41Sopenharmony_ci AsyncParentCompletionSet exec_list(&zone); 7841cb0ef41Sopenharmony_ci 7851cb0ef41Sopenharmony_ci // 9. Perform ! GatherAsyncParentCompletions(module, execList). 7861cb0ef41Sopenharmony_ci GatherAsyncParentCompletions(isolate, &zone, module, &exec_list); 7871cb0ef41Sopenharmony_ci 7881cb0ef41Sopenharmony_ci // 10. Let sortedExecList be a List of elements that are the elements of 7891cb0ef41Sopenharmony_ci // execList, in the order in which they had their [[AsyncEvaluating]] 7901cb0ef41Sopenharmony_ci // fields set to true in InnerModuleEvaluation. 7911cb0ef41Sopenharmony_ci // 7921cb0ef41Sopenharmony_ci // This step is implemented by AsyncParentCompletionSet, which is a set 7931cb0ef41Sopenharmony_ci // ordered on async_evaluating_ordinal. 7941cb0ef41Sopenharmony_ci 7951cb0ef41Sopenharmony_ci // 11. Assert: All elements of sortedExecList have their [[AsyncEvaluating]] 7961cb0ef41Sopenharmony_ci // field set to true, [[PendingAsyncDependencies]] field set to 0 and 7971cb0ef41Sopenharmony_ci // [[EvaluationError]] field set to undefined. 7981cb0ef41Sopenharmony_ci#ifdef DEBUG 7991cb0ef41Sopenharmony_ci for (Handle<SourceTextModule> m : exec_list) { 8001cb0ef41Sopenharmony_ci DCHECK(m->IsAsyncEvaluating()); 8011cb0ef41Sopenharmony_ci DCHECK(!m->HasPendingAsyncDependencies()); 8021cb0ef41Sopenharmony_ci DCHECK_NE(m->status(), kErrored); 8031cb0ef41Sopenharmony_ci } 8041cb0ef41Sopenharmony_ci#endif 8051cb0ef41Sopenharmony_ci 8061cb0ef41Sopenharmony_ci // 12. For each Module m of sortedExecList, do 8071cb0ef41Sopenharmony_ci for (Handle<SourceTextModule> m : exec_list) { 8081cb0ef41Sopenharmony_ci // i. If m.[[AsyncEvaluating]] is false, then 8091cb0ef41Sopenharmony_ci if (!m->IsAsyncEvaluating()) { 8101cb0ef41Sopenharmony_ci // a. Assert: m.[[EvaluatingError]] is not empty. 8111cb0ef41Sopenharmony_ci DCHECK_EQ(m->status(), kErrored); 8121cb0ef41Sopenharmony_ci } else if (m->async()) { 8131cb0ef41Sopenharmony_ci // ii. Otherwise, if m.[[Async]] is *true*, then 8141cb0ef41Sopenharmony_ci // a. Perform ! ExecuteAsyncModule(m). 8151cb0ef41Sopenharmony_ci // The execution may have been terminated and can not be resumed, so just 8161cb0ef41Sopenharmony_ci // raise the exception. 8171cb0ef41Sopenharmony_ci MAYBE_RETURN(ExecuteAsyncModule(isolate, m), Nothing<bool>()); 8181cb0ef41Sopenharmony_ci } else { 8191cb0ef41Sopenharmony_ci // iii. Otherwise, 8201cb0ef41Sopenharmony_ci // a. Let _result_ be m.ExecuteModule(). 8211cb0ef41Sopenharmony_ci Handle<Object> unused_result; 8221cb0ef41Sopenharmony_ci // b. If _result_ is an abrupt completion, 8231cb0ef41Sopenharmony_ci if (!ExecuteModule(isolate, m).ToHandle(&unused_result)) { 8241cb0ef41Sopenharmony_ci // 1. Perform ! AsyncModuleExecutionRejected(m, result.[[Value]]). 8251cb0ef41Sopenharmony_ci Handle<Object> exception(isolate->pending_exception(), isolate); 8261cb0ef41Sopenharmony_ci isolate->clear_pending_exception(); 8271cb0ef41Sopenharmony_ci AsyncModuleExecutionRejected(isolate, m, exception); 8281cb0ef41Sopenharmony_ci } else { 8291cb0ef41Sopenharmony_ci // c. Otherwise, 8301cb0ef41Sopenharmony_ci // 1. Set m.[[AsyncEvaluating]] to false. 8311cb0ef41Sopenharmony_ci isolate->DidFinishModuleAsyncEvaluation(m->async_evaluating_ordinal()); 8321cb0ef41Sopenharmony_ci m->set_async_evaluating_ordinal(kAsyncEvaluateDidFinish); 8331cb0ef41Sopenharmony_ci 8341cb0ef41Sopenharmony_ci // 2. If m.[[TopLevelCapability]] is not empty, then 8351cb0ef41Sopenharmony_ci if (!m->top_level_capability().IsUndefined(isolate)) { 8361cb0ef41Sopenharmony_ci // i. Assert: m.[[CycleRoot]] is equal to m. 8371cb0ef41Sopenharmony_ci DCHECK_EQ(*m->GetCycleRoot(isolate), *m); 8381cb0ef41Sopenharmony_ci 8391cb0ef41Sopenharmony_ci // ii. Perform ! Call(m.[[TopLevelCapability]].[[Resolve]], 8401cb0ef41Sopenharmony_ci // undefined, «undefined»). 8411cb0ef41Sopenharmony_ci Handle<JSPromise> capability( 8421cb0ef41Sopenharmony_ci JSPromise::cast(m->top_level_capability()), isolate); 8431cb0ef41Sopenharmony_ci JSPromise::Resolve(capability, isolate->factory()->undefined_value()) 8441cb0ef41Sopenharmony_ci .ToHandleChecked(); 8451cb0ef41Sopenharmony_ci } 8461cb0ef41Sopenharmony_ci } 8471cb0ef41Sopenharmony_ci } 8481cb0ef41Sopenharmony_ci } 8491cb0ef41Sopenharmony_ci 8501cb0ef41Sopenharmony_ci // 10. Return undefined. 8511cb0ef41Sopenharmony_ci return Just(true); 8521cb0ef41Sopenharmony_ci} 8531cb0ef41Sopenharmony_ci 8541cb0ef41Sopenharmony_civoid SourceTextModule::AsyncModuleExecutionRejected( 8551cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, 8561cb0ef41Sopenharmony_ci Handle<Object> exception) { 8571cb0ef41Sopenharmony_ci // 1. If module.[[Status]] is evaluated, then 8581cb0ef41Sopenharmony_ci if (module->status() == kErrored) { 8591cb0ef41Sopenharmony_ci // a. Assert: module.[[EvaluationError]] is not empty. 8601cb0ef41Sopenharmony_ci DCHECK(!module->exception().IsTheHole(isolate)); 8611cb0ef41Sopenharmony_ci // b. Return. 8621cb0ef41Sopenharmony_ci return; 8631cb0ef41Sopenharmony_ci } 8641cb0ef41Sopenharmony_ci 8651cb0ef41Sopenharmony_ci // TODO(cbruni): update to match spec. 8661cb0ef41Sopenharmony_ci DCHECK(isolate->is_catchable_by_javascript(*exception)); 8671cb0ef41Sopenharmony_ci // 1. Assert: module.[[Status]] is "evaluated". 8681cb0ef41Sopenharmony_ci CHECK(module->status() == kEvaluated || module->status() == kErrored); 8691cb0ef41Sopenharmony_ci // 2. If module.[[AsyncEvaluating]] is false, 8701cb0ef41Sopenharmony_ci if (!module->IsAsyncEvaluating()) { 8711cb0ef41Sopenharmony_ci // a. Assert: module.[[EvaluationError]] is not empty. 8721cb0ef41Sopenharmony_ci CHECK_EQ(module->status(), kErrored); 8731cb0ef41Sopenharmony_ci // b. Return undefined. 8741cb0ef41Sopenharmony_ci return; 8751cb0ef41Sopenharmony_ci } 8761cb0ef41Sopenharmony_ci 8771cb0ef41Sopenharmony_ci // 5. Set module.[[EvaluationError]] to ThrowCompletion(error). 8781cb0ef41Sopenharmony_ci Module::RecordError(isolate, module, exception); 8791cb0ef41Sopenharmony_ci 8801cb0ef41Sopenharmony_ci // 6. Set module.[[AsyncEvaluating]] to false. 8811cb0ef41Sopenharmony_ci isolate->DidFinishModuleAsyncEvaluation(module->async_evaluating_ordinal()); 8821cb0ef41Sopenharmony_ci module->set_async_evaluating_ordinal(kAsyncEvaluateDidFinish); 8831cb0ef41Sopenharmony_ci 8841cb0ef41Sopenharmony_ci // 7. For each Module m of module.[[AsyncParentModules]], do 8851cb0ef41Sopenharmony_ci for (int i = 0; i < module->AsyncParentModuleCount(); i++) { 8861cb0ef41Sopenharmony_ci Handle<SourceTextModule> m = module->GetAsyncParentModule(isolate, i); 8871cb0ef41Sopenharmony_ci // TODO(cbruni): update to match spec. 8881cb0ef41Sopenharmony_ci // a. If module.[[DFSIndex]] is not equal to module.[[DFSAncestorIndex]], 8891cb0ef41Sopenharmony_ci // then 8901cb0ef41Sopenharmony_ci if (module->dfs_index() != module->dfs_ancestor_index()) { 8911cb0ef41Sopenharmony_ci // i. Assert: m.[[DFSAncestorIndex]] is equal to 8921cb0ef41Sopenharmony_ci // module.[[DFSAncestorIndex]]. 8931cb0ef41Sopenharmony_ci DCHECK_EQ(m->dfs_ancestor_index(), module->dfs_ancestor_index()); 8941cb0ef41Sopenharmony_ci } 8951cb0ef41Sopenharmony_ci // b. Perform ! AsyncModuleExecutionRejected(m, error). 8961cb0ef41Sopenharmony_ci AsyncModuleExecutionRejected(isolate, m, exception); 8971cb0ef41Sopenharmony_ci } 8981cb0ef41Sopenharmony_ci 8991cb0ef41Sopenharmony_ci // 8. If module.[[TopLevelCapability]] is not empty, then 9001cb0ef41Sopenharmony_ci if (!module->top_level_capability().IsUndefined(isolate)) { 9011cb0ef41Sopenharmony_ci // a. Assert: module.[[CycleRoot]] is equal to module. 9021cb0ef41Sopenharmony_ci DCHECK_EQ(*module->GetCycleRoot(isolate), *module); 9031cb0ef41Sopenharmony_ci // b. Perform ! Call(module.[[TopLevelCapability]].[[Reject]], 9041cb0ef41Sopenharmony_ci // undefined, «error»). 9051cb0ef41Sopenharmony_ci Handle<JSPromise> capability( 9061cb0ef41Sopenharmony_ci JSPromise::cast(module->top_level_capability()), isolate); 9071cb0ef41Sopenharmony_ci JSPromise::Reject(capability, exception); 9081cb0ef41Sopenharmony_ci } 9091cb0ef41Sopenharmony_ci} 9101cb0ef41Sopenharmony_ci 9111cb0ef41Sopenharmony_ci// static 9121cb0ef41Sopenharmony_ciMaybe<bool> SourceTextModule::ExecuteAsyncModule( 9131cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module) { 9141cb0ef41Sopenharmony_ci // 1. Assert: module.[[Status]] is "evaluating" or "evaluated". 9151cb0ef41Sopenharmony_ci CHECK(module->status() == kEvaluating || module->status() == kEvaluated); 9161cb0ef41Sopenharmony_ci 9171cb0ef41Sopenharmony_ci // 2. Assert: module.[[Async]] is true. 9181cb0ef41Sopenharmony_ci DCHECK(module->async()); 9191cb0ef41Sopenharmony_ci 9201cb0ef41Sopenharmony_ci // 3. Set module.[[AsyncEvaluating]] to true. 9211cb0ef41Sopenharmony_ci module->set_async_evaluating_ordinal( 9221cb0ef41Sopenharmony_ci isolate->NextModuleAsyncEvaluatingOrdinal()); 9231cb0ef41Sopenharmony_ci 9241cb0ef41Sopenharmony_ci // 4. Let capability be ! NewPromiseCapability(%Promise%). 9251cb0ef41Sopenharmony_ci Handle<JSPromise> capability = isolate->factory()->NewJSPromise(); 9261cb0ef41Sopenharmony_ci 9271cb0ef41Sopenharmony_ci // 5. Let stepsFulfilled be the steps of a CallAsyncModuleFulfilled 9281cb0ef41Sopenharmony_ci Handle<JSFunction> steps_fulfilled( 9291cb0ef41Sopenharmony_ci isolate->native_context()->call_async_module_fulfilled(), isolate); 9301cb0ef41Sopenharmony_ci 9311cb0ef41Sopenharmony_ci base::ScopedVector<Handle<Object>> empty_argv(0); 9321cb0ef41Sopenharmony_ci 9331cb0ef41Sopenharmony_ci // 6. Let onFulfilled be CreateBuiltinFunction(stepsFulfilled, 9341cb0ef41Sopenharmony_ci // «[[Module]]»). 9351cb0ef41Sopenharmony_ci // 7. Set onFulfilled.[[Module]] to module. 9361cb0ef41Sopenharmony_ci Handle<JSBoundFunction> on_fulfilled = 9371cb0ef41Sopenharmony_ci isolate->factory() 9381cb0ef41Sopenharmony_ci ->NewJSBoundFunction(steps_fulfilled, module, empty_argv) 9391cb0ef41Sopenharmony_ci .ToHandleChecked(); 9401cb0ef41Sopenharmony_ci 9411cb0ef41Sopenharmony_ci // 8. Let stepsRejected be the steps of a CallAsyncModuleRejected. 9421cb0ef41Sopenharmony_ci Handle<JSFunction> steps_rejected( 9431cb0ef41Sopenharmony_ci isolate->native_context()->call_async_module_rejected(), isolate); 9441cb0ef41Sopenharmony_ci 9451cb0ef41Sopenharmony_ci // 9. Let onRejected be CreateBuiltinFunction(stepsRejected, «[[Module]]»). 9461cb0ef41Sopenharmony_ci // 10. Set onRejected.[[Module]] to module. 9471cb0ef41Sopenharmony_ci Handle<JSBoundFunction> on_rejected = 9481cb0ef41Sopenharmony_ci isolate->factory() 9491cb0ef41Sopenharmony_ci ->NewJSBoundFunction(steps_rejected, module, empty_argv) 9501cb0ef41Sopenharmony_ci .ToHandleChecked(); 9511cb0ef41Sopenharmony_ci 9521cb0ef41Sopenharmony_ci // 11. Perform ! PerformPromiseThen(capability.[[Promise]], 9531cb0ef41Sopenharmony_ci // onFulfilled, onRejected). 9541cb0ef41Sopenharmony_ci Handle<Object> argv[] = {on_fulfilled, on_rejected}; 9551cb0ef41Sopenharmony_ci Execution::CallBuiltin(isolate, isolate->promise_then(), capability, 9561cb0ef41Sopenharmony_ci arraysize(argv), argv) 9571cb0ef41Sopenharmony_ci .ToHandleChecked(); 9581cb0ef41Sopenharmony_ci 9591cb0ef41Sopenharmony_ci // 12. Perform ! module.ExecuteModule(capability). 9601cb0ef41Sopenharmony_ci // Note: In V8 we have broken module.ExecuteModule into 9611cb0ef41Sopenharmony_ci // ExecuteModule for synchronous module execution and 9621cb0ef41Sopenharmony_ci // InnerExecuteAsyncModule for asynchronous execution. 9631cb0ef41Sopenharmony_ci MaybeHandle<Object> ret = 9641cb0ef41Sopenharmony_ci InnerExecuteAsyncModule(isolate, module, capability); 9651cb0ef41Sopenharmony_ci if (ret.is_null()) { 9661cb0ef41Sopenharmony_ci // The evaluation of async module can not throwing a JavaScript observable 9671cb0ef41Sopenharmony_ci // exception. 9681cb0ef41Sopenharmony_ci DCHECK(isolate->has_pending_exception()); 9691cb0ef41Sopenharmony_ci DCHECK_EQ(isolate->pending_exception(), 9701cb0ef41Sopenharmony_ci ReadOnlyRoots(isolate).termination_exception()); 9711cb0ef41Sopenharmony_ci return Nothing<bool>(); 9721cb0ef41Sopenharmony_ci } 9731cb0ef41Sopenharmony_ci 9741cb0ef41Sopenharmony_ci // 13. Return. 9751cb0ef41Sopenharmony_ci return Just<bool>(true); 9761cb0ef41Sopenharmony_ci} 9771cb0ef41Sopenharmony_ci 9781cb0ef41Sopenharmony_ciMaybeHandle<Object> SourceTextModule::InnerExecuteAsyncModule( 9791cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, 9801cb0ef41Sopenharmony_ci Handle<JSPromise> capability) { 9811cb0ef41Sopenharmony_ci // If we have an async module, then it has an associated 9821cb0ef41Sopenharmony_ci // JSAsyncFunctionObject, which we then evaluate with the passed in promise 9831cb0ef41Sopenharmony_ci // capability. 9841cb0ef41Sopenharmony_ci Handle<JSAsyncFunctionObject> async_function_object( 9851cb0ef41Sopenharmony_ci JSAsyncFunctionObject::cast(module->code()), isolate); 9861cb0ef41Sopenharmony_ci async_function_object->set_promise(*capability); 9871cb0ef41Sopenharmony_ci Handle<JSFunction> resume( 9881cb0ef41Sopenharmony_ci isolate->native_context()->async_module_evaluate_internal(), isolate); 9891cb0ef41Sopenharmony_ci Handle<Object> result; 9901cb0ef41Sopenharmony_ci ASSIGN_RETURN_ON_EXCEPTION( 9911cb0ef41Sopenharmony_ci isolate, result, 9921cb0ef41Sopenharmony_ci Execution::TryCall(isolate, resume, async_function_object, 0, nullptr, 9931cb0ef41Sopenharmony_ci Execution::MessageHandling::kKeepPending, nullptr, 9941cb0ef41Sopenharmony_ci false), 9951cb0ef41Sopenharmony_ci Object); 9961cb0ef41Sopenharmony_ci return result; 9971cb0ef41Sopenharmony_ci} 9981cb0ef41Sopenharmony_ci 9991cb0ef41Sopenharmony_ciMaybeHandle<Object> SourceTextModule::ExecuteModule( 10001cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module) { 10011cb0ef41Sopenharmony_ci // Synchronous modules have an associated JSGeneratorObject. 10021cb0ef41Sopenharmony_ci Handle<JSGeneratorObject> generator(JSGeneratorObject::cast(module->code()), 10031cb0ef41Sopenharmony_ci isolate); 10041cb0ef41Sopenharmony_ci Handle<JSFunction> resume( 10051cb0ef41Sopenharmony_ci isolate->native_context()->generator_next_internal(), isolate); 10061cb0ef41Sopenharmony_ci Handle<Object> result; 10071cb0ef41Sopenharmony_ci 10081cb0ef41Sopenharmony_ci ASSIGN_RETURN_ON_EXCEPTION( 10091cb0ef41Sopenharmony_ci isolate, result, 10101cb0ef41Sopenharmony_ci Execution::TryCall(isolate, resume, generator, 0, nullptr, 10111cb0ef41Sopenharmony_ci Execution::MessageHandling::kKeepPending, nullptr, 10121cb0ef41Sopenharmony_ci false), 10131cb0ef41Sopenharmony_ci Object); 10141cb0ef41Sopenharmony_ci DCHECK(JSIteratorResult::cast(*result).done().BooleanValue(isolate)); 10151cb0ef41Sopenharmony_ci return handle(JSIteratorResult::cast(*result).value(), isolate); 10161cb0ef41Sopenharmony_ci} 10171cb0ef41Sopenharmony_ci 10181cb0ef41Sopenharmony_ciMaybeHandle<Object> SourceTextModule::InnerModuleEvaluation( 10191cb0ef41Sopenharmony_ci Isolate* isolate, Handle<SourceTextModule> module, 10201cb0ef41Sopenharmony_ci ZoneForwardList<Handle<SourceTextModule>>* stack, unsigned* dfs_index) { 10211cb0ef41Sopenharmony_ci STACK_CHECK(isolate, MaybeHandle<Object>()); 10221cb0ef41Sopenharmony_ci 10231cb0ef41Sopenharmony_ci // InnerModuleEvaluation(module, stack, index) 10241cb0ef41Sopenharmony_ci // 2. If module.[[Status]] is "evaluated", then 10251cb0ef41Sopenharmony_ci // a. If module.[[EvaluationError]] is undefined, return index. 10261cb0ef41Sopenharmony_ci // (We return undefined instead) 10271cb0ef41Sopenharmony_ci if (module->status() == kEvaluated || module->status() == kEvaluating) { 10281cb0ef41Sopenharmony_ci return isolate->factory()->undefined_value(); 10291cb0ef41Sopenharmony_ci } 10301cb0ef41Sopenharmony_ci 10311cb0ef41Sopenharmony_ci // b. Otherwise return module.[[EvaluationError]]. 10321cb0ef41Sopenharmony_ci // (We throw on isolate and return a MaybeHandle<Object> 10331cb0ef41Sopenharmony_ci // instead) 10341cb0ef41Sopenharmony_ci if (module->status() == kErrored) { 10351cb0ef41Sopenharmony_ci isolate->Throw(module->exception()); 10361cb0ef41Sopenharmony_ci return MaybeHandle<Object>(); 10371cb0ef41Sopenharmony_ci } 10381cb0ef41Sopenharmony_ci 10391cb0ef41Sopenharmony_ci // 4. Assert: module.[[Status]] is "linked". 10401cb0ef41Sopenharmony_ci CHECK_EQ(module->status(), kLinked); 10411cb0ef41Sopenharmony_ci 10421cb0ef41Sopenharmony_ci // 5. Set module.[[Status]] to "evaluating". 10431cb0ef41Sopenharmony_ci module->SetStatus(kEvaluating); 10441cb0ef41Sopenharmony_ci 10451cb0ef41Sopenharmony_ci // 6. Set module.[[DFSIndex]] to index. 10461cb0ef41Sopenharmony_ci module->set_dfs_index(*dfs_index); 10471cb0ef41Sopenharmony_ci 10481cb0ef41Sopenharmony_ci // 7. Set module.[[DFSAncestorIndex]] to index. 10491cb0ef41Sopenharmony_ci module->set_dfs_ancestor_index(*dfs_index); 10501cb0ef41Sopenharmony_ci 10511cb0ef41Sopenharmony_ci // 8. Set module.[[PendingAsyncDependencies]] to 0. 10521cb0ef41Sopenharmony_ci DCHECK(!module->HasPendingAsyncDependencies()); 10531cb0ef41Sopenharmony_ci 10541cb0ef41Sopenharmony_ci // 9. Set module.[[AsyncParentModules]] to a new empty List. 10551cb0ef41Sopenharmony_ci module->set_async_parent_modules(ReadOnlyRoots(isolate).empty_array_list()); 10561cb0ef41Sopenharmony_ci 10571cb0ef41Sopenharmony_ci // 10. Set index to index + 1. 10581cb0ef41Sopenharmony_ci (*dfs_index)++; 10591cb0ef41Sopenharmony_ci 10601cb0ef41Sopenharmony_ci // 11. Append module to stack. 10611cb0ef41Sopenharmony_ci stack->push_front(module); 10621cb0ef41Sopenharmony_ci 10631cb0ef41Sopenharmony_ci // Recursion. 10641cb0ef41Sopenharmony_ci Handle<FixedArray> requested_modules(module->requested_modules(), isolate); 10651cb0ef41Sopenharmony_ci 10661cb0ef41Sopenharmony_ci // 12. For each String required that is an element of 10671cb0ef41Sopenharmony_ci // module.[[RequestedModules]], do 10681cb0ef41Sopenharmony_ci for (int i = 0, length = requested_modules->length(); i < length; ++i) { 10691cb0ef41Sopenharmony_ci Handle<Module> requested_module(Module::cast(requested_modules->get(i)), 10701cb0ef41Sopenharmony_ci isolate); 10711cb0ef41Sopenharmony_ci // d. If requiredModule is a Cyclic Module Record, then 10721cb0ef41Sopenharmony_ci if (requested_module->IsSourceTextModule()) { 10731cb0ef41Sopenharmony_ci Handle<SourceTextModule> required_module( 10741cb0ef41Sopenharmony_ci SourceTextModule::cast(*requested_module), isolate); 10751cb0ef41Sopenharmony_ci RETURN_ON_EXCEPTION( 10761cb0ef41Sopenharmony_ci isolate, 10771cb0ef41Sopenharmony_ci InnerModuleEvaluation(isolate, required_module, stack, dfs_index), 10781cb0ef41Sopenharmony_ci Object); 10791cb0ef41Sopenharmony_ci 10801cb0ef41Sopenharmony_ci // i. Assert: requiredModule.[[Status]] is either "evaluating" or 10811cb0ef41Sopenharmony_ci // "evaluated". 10821cb0ef41Sopenharmony_ci // (We also assert the module cannot be errored, because if it was 10831cb0ef41Sopenharmony_ci // we would have already returned from InnerModuleEvaluation) 10841cb0ef41Sopenharmony_ci CHECK_GE(required_module->status(), kEvaluating); 10851cb0ef41Sopenharmony_ci CHECK_NE(required_module->status(), kErrored); 10861cb0ef41Sopenharmony_ci 10871cb0ef41Sopenharmony_ci // ii. Assert: requiredModule.[[Status]] is "evaluating" if and 10881cb0ef41Sopenharmony_ci // only if requiredModule is in stack. 10891cb0ef41Sopenharmony_ci SLOW_DCHECK( 10901cb0ef41Sopenharmony_ci (requested_module->status() == kEvaluating) == 10911cb0ef41Sopenharmony_ci std::count_if(stack->begin(), stack->end(), [&](Handle<Module> m) { 10921cb0ef41Sopenharmony_ci return *m == *requested_module; 10931cb0ef41Sopenharmony_ci })); 10941cb0ef41Sopenharmony_ci 10951cb0ef41Sopenharmony_ci // iii. If requiredModule.[[Status]] is "evaluating", then 10961cb0ef41Sopenharmony_ci if (required_module->status() == kEvaluating) { 10971cb0ef41Sopenharmony_ci // 1. Set module.[[DFSAncestorIndex]] to 10981cb0ef41Sopenharmony_ci // min( 10991cb0ef41Sopenharmony_ci // module.[[DFSAncestorIndex]], 11001cb0ef41Sopenharmony_ci // requiredModule.[[DFSAncestorIndex]]). 11011cb0ef41Sopenharmony_ci module->set_dfs_ancestor_index( 11021cb0ef41Sopenharmony_ci std::min(module->dfs_ancestor_index(), 11031cb0ef41Sopenharmony_ci required_module->dfs_ancestor_index())); 11041cb0ef41Sopenharmony_ci } else { 11051cb0ef41Sopenharmony_ci // iv. Otherwise, 11061cb0ef41Sopenharmony_ci // 1. Set requiredModule to requiredModule.[[CycleRoot]]. 11071cb0ef41Sopenharmony_ci required_module = required_module->GetCycleRoot(isolate); 11081cb0ef41Sopenharmony_ci 11091cb0ef41Sopenharmony_ci // 2. Assert: requiredModule.[[Status]] is "evaluated". 11101cb0ef41Sopenharmony_ci CHECK_GE(required_module->status(), kEvaluated); 11111cb0ef41Sopenharmony_ci 11121cb0ef41Sopenharmony_ci // 3. If requiredModule.[[EvaluationError]] is not undefined, 11131cb0ef41Sopenharmony_ci // return module.[[EvaluationError]]. 11141cb0ef41Sopenharmony_ci // (If there was an exception on the original required module 11151cb0ef41Sopenharmony_ci // we would have already returned. This check handles the case 11161cb0ef41Sopenharmony_ci // where the AsyncCycleRoot has an error. Instead of returning 11171cb0ef41Sopenharmony_ci // the exception, we throw on isolate and return a 11181cb0ef41Sopenharmony_ci // MaybeHandle<Object>) 11191cb0ef41Sopenharmony_ci if (required_module->status() == kErrored) { 11201cb0ef41Sopenharmony_ci isolate->Throw(required_module->exception()); 11211cb0ef41Sopenharmony_ci return MaybeHandle<Object>(); 11221cb0ef41Sopenharmony_ci } 11231cb0ef41Sopenharmony_ci } 11241cb0ef41Sopenharmony_ci // v. If requiredModule.[[AsyncEvaluating]] is true, then 11251cb0ef41Sopenharmony_ci if (required_module->IsAsyncEvaluating()) { 11261cb0ef41Sopenharmony_ci // 1. Set module.[[PendingAsyncDependencies]] to 11271cb0ef41Sopenharmony_ci // module.[[PendingAsyncDependencies]] + 1. 11281cb0ef41Sopenharmony_ci module->IncrementPendingAsyncDependencies(); 11291cb0ef41Sopenharmony_ci 11301cb0ef41Sopenharmony_ci // 2. Append module to requiredModule.[[AsyncParentModules]]. 11311cb0ef41Sopenharmony_ci AddAsyncParentModule(isolate, required_module, module); 11321cb0ef41Sopenharmony_ci } 11331cb0ef41Sopenharmony_ci } else { 11341cb0ef41Sopenharmony_ci RETURN_ON_EXCEPTION(isolate, Module::Evaluate(isolate, requested_module), 11351cb0ef41Sopenharmony_ci Object); 11361cb0ef41Sopenharmony_ci } 11371cb0ef41Sopenharmony_ci } 11381cb0ef41Sopenharmony_ci 11391cb0ef41Sopenharmony_ci // The spec returns the module index for proper numbering of dependencies. 11401cb0ef41Sopenharmony_ci // However, we pass the module index by pointer instead. 11411cb0ef41Sopenharmony_ci // 11421cb0ef41Sopenharmony_ci // Before async modules v8 returned the value result from calling next 11431cb0ef41Sopenharmony_ci // on the module's implicit iterator. We preserve this behavior for 11441cb0ef41Sopenharmony_ci // synchronous modules, but return undefined for AsyncModules. 11451cb0ef41Sopenharmony_ci Handle<Object> result = isolate->factory()->undefined_value(); 11461cb0ef41Sopenharmony_ci 11471cb0ef41Sopenharmony_ci // 14. If module.[[PendingAsyncDependencies]] > 0 or module.[[Async]] is 11481cb0ef41Sopenharmony_ci // true, then 11491cb0ef41Sopenharmony_ci if (module->HasPendingAsyncDependencies() || module->async()) { 11501cb0ef41Sopenharmony_ci // a. Assert: module.[[AsyncEvaluating]] is false and was never previously 11511cb0ef41Sopenharmony_ci // set to true. 11521cb0ef41Sopenharmony_ci DCHECK_EQ(module->async_evaluating_ordinal(), kNotAsyncEvaluated); 11531cb0ef41Sopenharmony_ci 11541cb0ef41Sopenharmony_ci // b. Set module.[[AsyncEvaluating]] to true. 11551cb0ef41Sopenharmony_ci // NOTE: The order in which modules transition to async evaluating is 11561cb0ef41Sopenharmony_ci // significant. 11571cb0ef41Sopenharmony_ci module->set_async_evaluating_ordinal( 11581cb0ef41Sopenharmony_ci isolate->NextModuleAsyncEvaluatingOrdinal()); 11591cb0ef41Sopenharmony_ci 11601cb0ef41Sopenharmony_ci // c. If module.[[PendingAsyncDependencies]] is 0, 11611cb0ef41Sopenharmony_ci // perform ! ExecuteAsyncModule(_module_). 11621cb0ef41Sopenharmony_ci // The execution may have been terminated and can not be resumed, so just 11631cb0ef41Sopenharmony_ci // raise the exception. 11641cb0ef41Sopenharmony_ci if (!module->HasPendingAsyncDependencies()) { 11651cb0ef41Sopenharmony_ci MAYBE_RETURN(SourceTextModule::ExecuteAsyncModule(isolate, module), 11661cb0ef41Sopenharmony_ci MaybeHandle<Object>()); 11671cb0ef41Sopenharmony_ci } 11681cb0ef41Sopenharmony_ci } else { 11691cb0ef41Sopenharmony_ci // 15. Otherwise, perform ? module.ExecuteModule(). 11701cb0ef41Sopenharmony_ci ASSIGN_RETURN_ON_EXCEPTION(isolate, result, ExecuteModule(isolate, module), 11711cb0ef41Sopenharmony_ci Object); 11721cb0ef41Sopenharmony_ci } 11731cb0ef41Sopenharmony_ci 11741cb0ef41Sopenharmony_ci CHECK(MaybeTransitionComponent(isolate, module, stack, kEvaluated)); 11751cb0ef41Sopenharmony_ci return result; 11761cb0ef41Sopenharmony_ci} 11771cb0ef41Sopenharmony_ci 11781cb0ef41Sopenharmony_civoid SourceTextModule::Reset(Isolate* isolate, 11791cb0ef41Sopenharmony_ci Handle<SourceTextModule> module) { 11801cb0ef41Sopenharmony_ci Factory* factory = isolate->factory(); 11811cb0ef41Sopenharmony_ci 11821cb0ef41Sopenharmony_ci DCHECK(module->import_meta(kAcquireLoad).IsTheHole(isolate)); 11831cb0ef41Sopenharmony_ci 11841cb0ef41Sopenharmony_ci Handle<FixedArray> regular_exports = 11851cb0ef41Sopenharmony_ci factory->NewFixedArray(module->regular_exports().length()); 11861cb0ef41Sopenharmony_ci Handle<FixedArray> regular_imports = 11871cb0ef41Sopenharmony_ci factory->NewFixedArray(module->regular_imports().length()); 11881cb0ef41Sopenharmony_ci Handle<FixedArray> requested_modules = 11891cb0ef41Sopenharmony_ci factory->NewFixedArray(module->requested_modules().length()); 11901cb0ef41Sopenharmony_ci 11911cb0ef41Sopenharmony_ci if (module->status() == kLinking) { 11921cb0ef41Sopenharmony_ci module->set_code(JSFunction::cast(module->code()).shared()); 11931cb0ef41Sopenharmony_ci } 11941cb0ef41Sopenharmony_ci module->set_regular_exports(*regular_exports); 11951cb0ef41Sopenharmony_ci module->set_regular_imports(*regular_imports); 11961cb0ef41Sopenharmony_ci module->set_requested_modules(*requested_modules); 11971cb0ef41Sopenharmony_ci module->set_dfs_index(-1); 11981cb0ef41Sopenharmony_ci module->set_dfs_ancestor_index(-1); 11991cb0ef41Sopenharmony_ci} 12001cb0ef41Sopenharmony_ci 12011cb0ef41Sopenharmony_ci} // namespace internal 12021cb0ef41Sopenharmony_ci} // namespace v8 1203