Commit 61e2b67e authored by Daniel Clark's avatar Daniel Clark Committed by Commit Bot

Move potentially reentrant allocation out of the middle of Module::Reset

During Module::Reset(), the module is in an unstable state between the
change to SourceTextModule::code and Module::status.  Any reentrancy
between these points is problematic because the normal invariants about
the value of SourceTextModule::code in relation to Module::status do not
hold.

An allocation of the exports hash table in the middle of Module::Reset()
was causing reentrancy during this problematic time.  This change fixes
the issue by moving the allocation earlier in Reset() before any fields
are modified.

Bug: v8:9522
Change-Id: Ia941af60a0b31f05a6d8da610b9a270e7f79dac2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1712449Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Dan Clark <daniec@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#62902}
parent 7cb9984e
......@@ -107,21 +107,18 @@ void Module::Reset(Isolate* isolate, Handle<Module> module) {
module->PrintStatusTransition(kUninstantiated);
#endif // DEBUG
int export_count;
const int export_count =
module->IsSourceTextModule()
? Handle<SourceTextModule>::cast(module)->regular_exports().length()
: Handle<SyntheticModule>::cast(module)->export_names().length();
Handle<ObjectHashTable> exports = ObjectHashTable::New(isolate, export_count);
if (module->IsSourceTextModule()) {
Handle<SourceTextModule> source_text_module =
Handle<SourceTextModule>::cast(module);
export_count = source_text_module->regular_exports().length();
SourceTextModule::Reset(isolate, source_text_module);
SourceTextModule::Reset(isolate, Handle<SourceTextModule>::cast(module));
} else {
export_count =
Handle<SyntheticModule>::cast(module)->export_names().length();
// Nothing to do here.
}
Handle<ObjectHashTable> exports = ObjectHashTable::New(isolate, export_count);
module->set_exports(*exports);
module->set_status(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