@@ -103,7 +103,8 @@ void NativeModuleLoader::CompileCodeCache(
103103
104104 // TODO(joyeecheung): allow compiling cache for bootstrapper by
105105 // switching on id
106- MaybeLocal<Value> result = CompileAsModule (env, *id, true );
106+ MaybeLocal<Value> result =
107+ CompileAsModule (env, *id, CompilationResultType::kCodeCache );
107108 if (!result.IsEmpty ()) {
108109 args.GetReturnValue ().Set (result.ToLocalChecked ());
109110 }
@@ -115,7 +116,8 @@ void NativeModuleLoader::CompileFunction(
115116 CHECK (args[0 ]->IsString ());
116117 node::Utf8Value id (env->isolate (), args[0 ].As <String>());
117118
118- MaybeLocal<Value> result = CompileAsModule (env, *id, false );
119+ MaybeLocal<Value> result =
120+ CompileAsModule (env, *id, CompilationResultType::kFunction );
119121 if (!result.IsEmpty ()) {
120122 args.GetReturnValue ().Set (result.ToLocalChecked ());
121123 }
@@ -131,7 +133,7 @@ MaybeLocal<Value> NativeModuleLoader::CompileAndCall(
131133 Environment* optional_env) {
132134 Isolate* isolate = context->GetIsolate ();
133135 MaybeLocal<Value> compiled = per_process_loader.LookupAndCompile (
134- context, id, parameters, false , nullptr );
136+ context, id, parameters, CompilationResultType:: kFunction , nullptr );
135137 if (compiled.IsEmpty ()) {
136138 return compiled;
137139 }
@@ -140,16 +142,15 @@ MaybeLocal<Value> NativeModuleLoader::CompileAndCall(
140142 context, v8::Null (isolate), arguments->size (), arguments->data ());
141143}
142144
143- MaybeLocal<Value> NativeModuleLoader::CompileAsModule (Environment* env,
144- const char * id,
145- bool return_code_cache) {
145+ MaybeLocal<Value> NativeModuleLoader::CompileAsModule (
146+ Environment* env, const char * id, CompilationResultType result) {
146147 std::vector<Local<String>> parameters = {env->exports_string (),
147148 env->require_string (),
148149 env->module_string (),
149150 env->process_string (),
150151 env->internal_binding_string ()};
151152 return per_process_loader.LookupAndCompile (
152- env->context (), id, ¶meters, return_code_cache , env);
153+ env->context (), id, ¶meters, result , env);
153154}
154155
155156// Currently V8 only checks that the length of the source code is the
@@ -214,7 +215,7 @@ MaybeLocal<Value> NativeModuleLoader::LookupAndCompile(
214215 Local<Context> context,
215216 const char * id,
216217 std::vector<Local<String>>* parameters,
217- bool return_code_cache ,
218+ CompilationResultType result_type ,
218219 Environment* optional_env) {
219220 Isolate* isolate = context->GetIsolate ();
220221 EscapableHandleScope scope (isolate);
@@ -236,7 +237,7 @@ MaybeLocal<Value> NativeModuleLoader::LookupAndCompile(
236237 // built with them.
237238 // 2. If we are generating code cache for tools/general_code_cache.js, we
238239 // are not going to use any cache ourselves.
239- if (has_code_cache_ && !return_code_cache ) {
240+ if (has_code_cache_ && result_type == CompilationResultType:: kFunction ) {
240241 cached_data = GetCachedData (id);
241242 if (cached_data != nullptr ) {
242243 use_cache = true ;
@@ -246,7 +247,7 @@ MaybeLocal<Value> NativeModuleLoader::LookupAndCompile(
246247 ScriptCompiler::Source script_source (source, origin, cached_data);
247248
248249 ScriptCompiler::CompileOptions options;
249- if (return_code_cache ) {
250+ if (result_type == CompilationResultType:: kCodeCache ) {
250251 options = ScriptCompiler::kEagerCompile ;
251252 } else if (use_cache) {
252253 options = ScriptCompiler::kConsumeCodeCache ;
@@ -269,7 +270,7 @@ MaybeLocal<Value> NativeModuleLoader::LookupAndCompile(
269270 // In the case of early errors, v8 is already capable of
270271 // decorating the stack for us - note that we use CompileFunctionInContext
271272 // so there is no need to worry about wrappers.
272- return scope. EscapeMaybe ( MaybeLocal<Value>() );
273+ return MaybeLocal<Value>();
273274 }
274275
275276 Local<Function> fun = maybe_fun.ToLocalChecked ();
@@ -289,7 +290,7 @@ MaybeLocal<Value> NativeModuleLoader::LookupAndCompile(
289290 }
290291 }
291292
292- if (return_code_cache ) {
293+ if (result_type == CompilationResultType:: kCodeCache ) {
293294 std::unique_ptr<ScriptCompiler::CachedData> cached_data (
294295 ScriptCompiler::CreateCodeCacheForFunction (fun));
295296 CHECK_NE (cached_data, nullptr );
@@ -311,7 +312,7 @@ MaybeLocal<Value> NativeModuleLoader::LookupAndCompile(
311312 ret = fun;
312313 }
313314
314- return scope.EscapeMaybe (MaybeLocal<Value>( ret) );
315+ return scope.Escape ( ret);
315316}
316317
317318void NativeModuleLoader::Initialize (Local<Object> target,
0 commit comments