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) {
} else if (status() == kEvaluating || status() == kEvaluated) {
CHECK(code().IsJSGeneratorObject());
} else {
CHECK((status() == kInstantiated && code().IsJSGeneratorObject()) ||
(status() == kInstantiating && code().IsJSFunction()) ||
(status() == kPreInstantiating && code().IsSharedFunctionInfo()) ||
(status() == kUninstantiated && code().IsSharedFunctionInfo()));
CHECK(top_level_capability().IsUndefined() && !AsyncParentModuleCount() &&
!pending_async_dependencies() && !async_evaluating());
if (status() == kInstantiated) {
CHECK(code().IsJSGeneratorObject());
} else if (status() == kInstantiating) {
CHECK(code().IsJSFunction());
} else if (status() == kPreInstantiating) {
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());
......
......@@ -123,20 +123,21 @@ void Module::ResetGraph(Isolate* isolate, Handle<Module> module) {
void Module::Reset(Isolate* isolate, Handle<Module> module) {
DCHECK(module->status() == kPreInstantiating ||
module->status() == kInstantiating);
DCHECK(module->exception().IsTheHole(isolate));
// The namespace object cannot exist, because it would have been created
// by RunInitializationCode, which is called only after this module's SCC
// succeeds instantiation.
DCHECK(!module->module_namespace().IsJSModuleNamespace());
if (module->IsSourceTextModule()) {
SourceTextModule::Reset(isolate, Handle<SourceTextModule>::cast(module));
}
const int export_count =
module->IsSourceTextModule()
? SourceTextModule::cast(*module).regular_exports().length()
: SyntheticModule::cast(*module).export_names().length();
Handle<ObjectHashTable> exports = ObjectHashTable::New(isolate, export_count);
if (module->IsSourceTextModule()) {
SourceTextModule::Reset(isolate, Handle<SourceTextModule>::cast(module));
}
module->set_exports(*exports);
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