Commit 7be8692e authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[runtime][module] Change Module::Reset order

Allocating in the right spot leaves the Module in an invalid state.
Do allocations before resetting a module.

Drive-by-fix: make module verification check failures easier to debug.

Bug: v8:10985
Change-Id: I6fc32c96441958755bfb32b3004e1bb616dc7d98
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2452533Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70369}
parent 2547edd6
...@@ -1410,12 +1410,19 @@ void SourceTextModule::SourceTextModuleVerify(Isolate* isolate) { ...@@ -1410,12 +1410,19 @@ void SourceTextModule::SourceTextModuleVerify(Isolate* isolate) {
} else if (status() == kEvaluating || status() == kEvaluated) { } else if (status() == kEvaluating || status() == kEvaluated) {
CHECK(code().IsJSGeneratorObject()); CHECK(code().IsJSGeneratorObject());
} else { } else {
CHECK((status() == kInstantiated && code().IsJSGeneratorObject()) || if (status() == kInstantiated) {
(status() == kInstantiating && code().IsJSFunction()) || CHECK(code().IsJSGeneratorObject());
(status() == kPreInstantiating && code().IsSharedFunctionInfo()) || } else if (status() == kInstantiating) {
(status() == kUninstantiated && code().IsSharedFunctionInfo())); CHECK(code().IsJSFunction());
CHECK(top_level_capability().IsUndefined() && !AsyncParentModuleCount() && } else if (status() == kPreInstantiating) {
!pending_async_dependencies() && !async_evaluating()); CHECK(code().IsSharedFunctionInfo());
} else if (status() == kUninstantiated) {
CHECK(code().IsSharedFunctionInfo());
}
CHECK(top_level_capability().IsUndefined());
CHECK(!AsyncParentModuleCount());
CHECK(!pending_async_dependencies());
CHECK(!async_evaluating());
} }
CHECK_EQ(requested_modules().length(), info().module_requests().length()); CHECK_EQ(requested_modules().length(), info().module_requests().length());
......
...@@ -123,20 +123,21 @@ void Module::ResetGraph(Isolate* isolate, Handle<Module> module) { ...@@ -123,20 +123,21 @@ void Module::ResetGraph(Isolate* isolate, Handle<Module> module) {
void Module::Reset(Isolate* isolate, Handle<Module> module) { void Module::Reset(Isolate* isolate, Handle<Module> module) {
DCHECK(module->status() == kPreInstantiating || DCHECK(module->status() == kPreInstantiating ||
module->status() == kInstantiating); module->status() == kInstantiating);
DCHECK(module->exception().IsTheHole(isolate));
// The namespace object cannot exist, because it would have been created // The namespace object cannot exist, because it would have been created
// by RunInitializationCode, which is called only after this module's SCC // by RunInitializationCode, which is called only after this module's SCC
// succeeds instantiation. // succeeds instantiation.
DCHECK(!module->module_namespace().IsJSModuleNamespace()); DCHECK(!module->module_namespace().IsJSModuleNamespace());
if (module->IsSourceTextModule()) {
SourceTextModule::Reset(isolate, Handle<SourceTextModule>::cast(module));
}
const int export_count = const int export_count =
module->IsSourceTextModule() module->IsSourceTextModule()
? SourceTextModule::cast(*module).regular_exports().length() ? SourceTextModule::cast(*module).regular_exports().length()
: SyntheticModule::cast(*module).export_names().length(); : SyntheticModule::cast(*module).export_names().length();
Handle<ObjectHashTable> exports = ObjectHashTable::New(isolate, export_count); Handle<ObjectHashTable> exports = ObjectHashTable::New(isolate, export_count);
if (module->IsSourceTextModule()) {
SourceTextModule::Reset(isolate, Handle<SourceTextModule>::cast(module));
}
module->set_exports(*exports); module->set_exports(*exports);
SetStatusInternal(*module, kUninstantiated); SetStatusInternal(*module, kUninstantiated);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment