@@ -771,10 +771,12 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
771771 bool produce_cached_data = false ;
772772 Local<Context> parsing_context = context;
773773
774+ bool needs_custom_host_defined_options = false ;
774775 if (argc > 2 ) {
775776 // new ContextifyScript(code, filename, lineOffset, columnOffset,
776- // cachedData, produceCachedData, parsingContext)
777- CHECK_EQ (argc, 7 );
777+ // cachedData, produceCachedData, parsingContext,
778+ // needsCustomHostDefinedOptions)
779+ CHECK_EQ (argc, 8 );
778780 CHECK (args[2 ]->IsNumber ());
779781 line_offset = args[2 ].As <Int32>()->Value ();
780782 CHECK (args[3 ]->IsNumber ());
@@ -793,6 +795,9 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
793795 CHECK_NOT_NULL (sandbox);
794796 parsing_context = sandbox->context ();
795797 }
798+ if (args[7 ]->IsTrue ()) {
799+ needs_custom_host_defined_options = true ;
800+ }
796801 }
797802
798803 ContextifyScript* contextify_script =
@@ -816,7 +821,12 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
816821
817822 Local<PrimitiveArray> host_defined_options =
818823 PrimitiveArray::New (isolate, loader::HostDefinedOptions::kLength );
819- Local<Symbol> id_symbol = Symbol::New (isolate, filename);
824+ // We need a default host defined options that's the same for all scripts
825+ // not needing custom module callbacks for so that the isolate compilation
826+ // cache can be hit.
827+ Local<Symbol> id_symbol = needs_custom_host_defined_options
828+ ? Symbol::New (isolate, filename)
829+ : env->default_host_defined_options ();
820830 host_defined_options->Set (
821831 isolate, loader::HostDefinedOptions::kID , id_symbol);
822832
0 commit comments