Skip to content
Prev Previous commit
Next Next commit
vm: report cache rejection in vm.compileFunction
Add functionality in vm.compileFunction/CompileFunction to report if
cache data was provided yet rejected by v8.
  • Loading branch information
ryzokuken committed Oct 24, 2018
commit 19262a0d4ac39dacc96af990b4642c69a49c39a9
11 changes: 11 additions & 0 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1099,12 +1099,23 @@ void ContextifyContext::CompileFunction(
env->cached_data_string(),
buf.ToLocalChecked()).IsNothing()) return;
}

// Report if cache was produced.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into the implementation a bit, and I wonder if we can just wrap ScriptCompiler::CreateCodeCacheForFunction in another binding that takes a function as argument? That way we can just manipulate the return values in the JS land, and also enable the code cache generator to use the exact function compiled to generate the cache if we simply return fn in NativeModule.prototype.compile - also, we don't actually need that argument handling complexity in the compileFunction C++ binding, vm.compileFunction can handle produce_cached_data in JS land and NativeModule.prototype.compile doesn't even need it at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I just noticed that the docs of vm.compileFunction did not mention its return value. Is that intentional?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and the returned values are not tested either?)

if (fun->Set(
parsing_context,
env->cached_data_produced_string(),
Boolean::New(isolate, cached_data_produced)).IsNothing()) return;
}

// Report if cache was rejected.
if (options == ScriptCompiler::kConsumeCodeCache) {
if (fun->Set(parsing_context,
env->cached_data_rejected_string(),
Boolean::New(isolate, source.GetCachedData()->rejected))
.IsNothing())
return;
}
Comment thread
ryzokuken marked this conversation as resolved.

args.GetReturnValue().Set(fun);
}

Expand Down