Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(934)

Unified Diff: src/objects.cc

Issue 2407183002: [modules] Don't unnecessarily keep function alive after evaluation. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index a025251f81033b287d80c24f0aa791aa1e252bce..c15892f7037b4cadd3e97aac1553518700c5b0fb 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -19853,8 +19853,7 @@ MaybeHandle<Cell> Module::ResolveExportUsingStarExports(
bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context,
v8::Module::ResolveCallback callback,
v8::Local<v8::Value> callback_data) {
- // Already instantiated.
- if (module->code()->IsJSFunction()) return true;
+ if (module->instantiated()) return true;
Isolate* isolate = module->GetIsolate();
Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(module->code()),
@@ -19864,6 +19863,7 @@ bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context,
shared,
handle(Utils::OpenHandle(*context)->native_context(), isolate));
module->set_code(*function);
+ DCHECK(module->instantiated());
Handle<ModuleInfo> module_info(shared->scope_info()->ModuleDescriptorInfo(),
isolate);
@@ -19945,16 +19945,15 @@ bool Module::Instantiate(Handle<Module> module, v8::Local<v8::Context> context,
}
MaybeHandle<Object> Module::Evaluate(Handle<Module> module) {
- DCHECK(module->code()->IsJSFunction()); // Instantiated.
-
- Isolate* isolate = module->GetIsolate();
+ DCHECK(module->instantiated());
// Each module can only be evaluated once.
+ Isolate* isolate = module->GetIsolate();
if (module->evaluated()) return isolate->factory()->undefined_value();
- module->set_evaluated(true);
+ Handle<JSFunction> function(JSFunction::cast(module->code()), isolate);
+ module->set_evaluated();
// Initialization.
- Handle<JSFunction> function(JSFunction::cast(module->code()), isolate);
DCHECK_EQ(MODULE_SCOPE, function->shared()->scope_info()->scope_type());
Handle<Object> receiver = isolate->factory()->undefined_value();
Handle<Object> argv[] = {module};
@@ -19981,7 +19980,7 @@ namespace {
void FetchStarExports(Handle<Module> module, Zone* zone,
UnorderedModuleSet* visited) {
- DCHECK(module->code()->IsJSFunction()); // Instantiated.
+ DCHECK(module->instantiated());
bool cycle = !visited->insert(module).second;
if (cycle) return;

Powered by Google App Engine
This is Rietveld 408576698