--- node/deps/v8/include/v8.h +++ node/deps/v8/include/v8.h @@ -6065,10 +6065,14 @@ */ static void SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags); + static void EnableCompilationForSourcelessUse(); + static void DisableCompilationForSourcelessUse(); + static void FixSourcelessScript(Isolate* v8_isolate, Local script); + /** Get the version string. */ static const char* GetVersion(); /** Callback function for reporting failed access checks.*/ V8_INLINE static V8_DEPRECATE_SOON( --- node/deps/v8/src/api.cc +++ node/deps/v8/src/api.cc @@ -428,10 +428,46 @@ void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); } +bool save_lazy; +bool save_predictable; +bool save_serialize_toplevel; + + +void V8::EnableCompilationForSourcelessUse() { + save_lazy = i::FLAG_lazy; + i::FLAG_lazy = false; + save_predictable = i::FLAG_predictable; + i::FLAG_predictable = true; + save_serialize_toplevel = i::FLAG_serialize_toplevel; + i::FLAG_serialize_toplevel = true; + i::CpuFeatures::Reinitialize(); + i::CpuFeatures::Probe(true); +} + + +void V8::DisableCompilationForSourcelessUse() { + i::FLAG_lazy = save_lazy; + i::FLAG_predictable = save_predictable; + i::FLAG_serialize_toplevel = save_serialize_toplevel; + i::CpuFeatures::Reinitialize(); + i::CpuFeatures::Probe(false); +} + + +void V8::FixSourcelessScript(Isolate* v8_isolate, Local script) { + auto isolate = reinterpret_cast(v8_isolate); + auto object = i::Handle::cast(Utils::OpenHandle(*script)); + i::Handle function_info( + i::SharedFunctionInfo::cast(*object), object->GetIsolate()); + auto s = reinterpret_cast(function_info->script()); + s->set_source(isolate->heap()->undefined_value()); +} + + RegisteredExtension* RegisteredExtension::first_extension_ = NULL; RegisteredExtension::RegisteredExtension(Extension* extension) : extension_(extension) { } --- node/deps/v8/src/assembler.h +++ node/deps/v8/src/assembler.h @@ -223,10 +223,15 @@ static void PrintFeatures(); // Flush instruction cache. static void FlushICache(void* start, size_t size); + static void Reinitialize() { + supported_ = 0; + initialized_ = false; + } + private: // Platform-dependent implementation. static void ProbeImpl(bool cross_compile); static unsigned supported_; --- node/deps/v8/src/parser.cc +++ node/deps/v8/src/parser.cc @@ -5636,10 +5636,11 @@ return false; } bool Parser::Parse(ParseInfo* info) { + if (info->script()->source()->IsUndefined()) return false; DCHECK(info->function() == NULL); FunctionLiteral* result = NULL; // Ok to use Isolate here; this function is only called in the main thread. DCHECK(parsing_on_main_thread_); Isolate* isolate = info->isolate(); --- node/deps/v8/src/runtime/runtime-classes.cc +++ node/deps/v8/src/runtime/runtime-classes.cc @@ -236,10 +236,14 @@ if (!start_position->IsSmi() || !end_position->IsSmi() || !Handle