diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-05-20 09:47:09 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-06-07 11:15:42 +0000 |
commit | 189d4fd8fad9e3c776873be51938cd31a42b6177 (patch) | |
tree | 6497caeff5e383937996768766ab3bb2081a40b2 /chromium/v8/src/objects/module.cc | |
parent | 8bc75099d364490b22f43a7ce366b366c08f4164 (diff) | |
download | qtwebengine-chromium-189d4fd8fad9e3c776873be51938cd31a42b6177.tar.gz |
BASELINE: Update Chromium to 90.0.4430.221
Change-Id: Iff4d9d18d2fcf1a576f3b1f453010f744a232920
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/v8/src/objects/module.cc')
-rw-r--r-- | chromium/v8/src/objects/module.cc | 88 |
1 files changed, 71 insertions, 17 deletions
diff --git a/chromium/v8/src/objects/module.cc b/chromium/v8/src/objects/module.cc index f4c23ae5c42..eb7887f1394 100644 --- a/chromium/v8/src/objects/module.cc +++ b/chromium/v8/src/objects/module.cc @@ -10,12 +10,14 @@ #include "src/api/api-inl.h" #include "src/ast/modules.h" #include "src/builtins/accessors.h" +#include "src/common/assert-scope.h" #include "src/heap/heap-inl.h" #include "src/objects/cell-inl.h" #include "src/objects/hash-table-inl.h" #include "src/objects/js-generator-inl.h" #include "src/objects/module-inl.h" #include "src/objects/objects-inl.h" +#include "src/objects/source-text-module.h" #include "src/objects/synthetic-module-inl.h" #include "src/utils/ostreams.h" @@ -26,7 +28,7 @@ namespace { #ifdef DEBUG void PrintModuleName(Module module, std::ostream& os) { if (module.IsSourceTextModule()) { - SourceTextModule::cast(module).script().GetNameOrSourceURL().Print(os); + SourceTextModule::cast(module).GetScript().GetNameOrSourceURL().Print(os); } else { SyntheticModule::cast(module).name().Print(os); } @@ -52,7 +54,7 @@ void PrintStatusMessage(Module module, const char* message) { #endif // DEBUG void SetStatusInternal(Module module, Module::Status new_status) { - DisallowHeapAllocation no_alloc; + DisallowGarbageCollection no_gc; #ifdef DEBUG PrintStatusTransition(module, new_status); #endif // DEBUG @@ -62,7 +64,7 @@ void SetStatusInternal(Module module, Module::Status new_status) { } // end namespace void Module::SetStatus(Status new_status) { - DisallowHeapAllocation no_alloc; + DisallowGarbageCollection no_gc; DCHECK_LE(status(), new_status); DCHECK_NE(new_status, Module::kErrored); SetStatusInternal(*this, new_status); @@ -78,11 +80,14 @@ void Module::RecordErrorUsingPendingException(Isolate* isolate, // static void Module::RecordError(Isolate* isolate, Handle<Module> module, Handle<Object> error) { + DisallowGarbageCollection no_gc; DCHECK(module->exception().IsTheHole(isolate)); DCHECK(!error->IsTheHole(isolate)); if (module->IsSourceTextModule()) { - Handle<SourceTextModule> self(SourceTextModule::cast(*module), isolate); - self->set_code(self->info()); + // Revert to minmal SFI in case we have already been instantiating or + // evaluating. + auto self = SourceTextModule::cast(*module); + self.set_code(self.GetSharedFunctionInfo()); } SetStatusInternal(*module, Module::kErrored); if (isolate->is_catchable_by_javascript(*error)) { @@ -144,7 +149,7 @@ void Module::Reset(Isolate* isolate, Handle<Module> module) { } Object Module::GetException() { - DisallowHeapAllocation no_gc; + DisallowGarbageCollection no_gc; DCHECK_EQ(status(), Module::kErrored); DCHECK(!exception().IsTheHole()); return exception(); @@ -169,14 +174,16 @@ MaybeHandle<Cell> Module::ResolveExport(Isolate* isolate, Handle<Module> module, } } -bool Module::Instantiate(Isolate* isolate, Handle<Module> module, - v8::Local<v8::Context> context, - v8::Module::ResolveCallback callback) { +bool Module::Instantiate( + Isolate* isolate, Handle<Module> module, v8::Local<v8::Context> context, + v8::Module::ResolveModuleCallback callback, + DeprecatedResolveCallback callback_without_import_assertions) { #ifdef DEBUG PrintStatusMessage(*module, "Instantiating module "); #endif // DEBUG - if (!PrepareInstantiate(isolate, module, context, callback)) { + if (!PrepareInstantiate(isolate, module, context, callback, + callback_without_import_assertions)) { ResetGraph(isolate, module); DCHECK_EQ(module->status(), kUninstantiated); return false; @@ -195,9 +202,10 @@ bool Module::Instantiate(Isolate* isolate, Handle<Module> module, return true; } -bool Module::PrepareInstantiate(Isolate* isolate, Handle<Module> module, - v8::Local<v8::Context> context, - v8::Module::ResolveCallback callback) { +bool Module::PrepareInstantiate( + Isolate* isolate, Handle<Module> module, v8::Local<v8::Context> context, + v8::Module::ResolveModuleCallback callback, + DeprecatedResolveCallback callback_without_import_assertions) { DCHECK_NE(module->status(), kEvaluating); DCHECK_NE(module->status(), kInstantiating); if (module->status() >= kPreInstantiating) return true; @@ -206,10 +214,11 @@ bool Module::PrepareInstantiate(Isolate* isolate, Handle<Module> module, if (module->IsSourceTextModule()) { return SourceTextModule::PrepareInstantiate( - isolate, Handle<SourceTextModule>::cast(module), context, callback); + isolate, Handle<SourceTextModule>::cast(module), context, callback, + callback_without_import_assertions); } else { return SyntheticModule::PrepareInstantiate( - isolate, Handle<SyntheticModule>::cast(module), context, callback); + isolate, Handle<SyntheticModule>::cast(module), context); } } @@ -236,11 +245,56 @@ MaybeHandle<Object> Module::Evaluate(Isolate* isolate, Handle<Module> module) { PrintStatusMessage(*module, "Evaluating module "); #endif // DEBUG STACK_CHECK(isolate, MaybeHandle<Object>()); - if (FLAG_harmony_top_level_await && module->IsSourceTextModule()) { + if (FLAG_harmony_top_level_await) { + return Module::EvaluateMaybeAsync(isolate, module); + } else { + return Module::InnerEvaluate(isolate, module); + } +} + +MaybeHandle<Object> Module::EvaluateMaybeAsync(Isolate* isolate, + Handle<Module> module) { + // In the event of errored evaluation, return a rejected promise. + if (module->status() == kErrored) { + // If we have a top level capability we assume it has already been + // rejected, and return it here. Otherwise create a new promise and + // reject it with the module's exception. + if (module->top_level_capability().IsJSPromise()) { + Handle<JSPromise> top_level_capability( + JSPromise::cast(module->top_level_capability()), isolate); + DCHECK(top_level_capability->status() == Promise::kRejected && + top_level_capability->result() == module->exception()); + return top_level_capability; + } + Handle<JSPromise> capability = isolate->factory()->NewJSPromise(); + JSPromise::Reject(capability, handle(module->exception(), isolate)); + return capability; + } + + // Start of Evaluate () Concrete Method + // 2. Assert: module.[[Status]] is "linked" or "evaluated". + CHECK(module->status() == kInstantiated || module->status() == kEvaluated); + + // 3. If module.[[Status]] is "evaluated", set module to + // module.[[CycleRoot]]. + // A Synthetic Module has no children so it is its own cycle root. + if (module->status() == kEvaluated && module->IsSourceTextModule()) { + module = Handle<SourceTextModule>::cast(module)->GetCycleRoot(isolate); + } + + // 4. If module.[[TopLevelCapability]] is not undefined, then + // a. Return module.[[TopLevelCapability]].[[Promise]]. + if (module->top_level_capability().IsJSPromise()) { + return handle(JSPromise::cast(module->top_level_capability()), isolate); + } + DCHECK(module->top_level_capability().IsUndefined()); + + if (module->IsSourceTextModule()) { return SourceTextModule::EvaluateMaybeAsync( isolate, Handle<SourceTextModule>::cast(module)); } else { - return Module::InnerEvaluate(isolate, module); + return SyntheticModule::Evaluate(isolate, + Handle<SyntheticModule>::cast(module)); } } |