pkg-fetch/patches/node.v18.20.8.cpp.patch
github-actions[bot] e9701b48d5
feat: add v18.20.8 patch (#76)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-03-28 08:37:51 +01:00

730 lines
26 KiB
Diff

diff --git node/common.gypi node/common.gypi
index 1b45f13453..a5ad9e716c 100644
--- node/common.gypi
+++ node/common.gypi
@@ -174,7 +174,7 @@
'MSVC_runtimeType': 2 # MultiThreadedDLL (/MD)
}],
['llvm_version=="0.0"', {
- 'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC
+ 'lto': ' -flto=4 -ffat-lto-objects ', # GCC
}, {
'lto': ' -flto ', # Clang
}],
diff --git node/configure.py node/configure.py
index 4a1359d79c..ce04b2912f 100755
--- node/configure.py
+++ node/configure.py
@@ -1288,9 +1288,7 @@ def configure_node(o):
o['variables']['want_separate_host_toolset'] = int(cross_compiling)
- # Enable branch protection for arm64
if target_arch == 'arm64':
- o['cflags']+=['-msign-return-address=all']
o['variables']['arm_fpu'] = options.arm_fpu or 'neon'
if options.node_snapshot_main is not None:
diff --git node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c
index 61a7d06cad..eeebf67796 100644
--- node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c
+++ node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c
@@ -33,17 +33,6 @@
#include "nghttp3_macro.h"
-#if defined(_MSC_VER) && !defined(__clang__) && \
- (defined(_M_ARM) || defined(_M_ARM64))
-unsigned int __popcnt(unsigned int x) {
- unsigned int c = 0;
- for (; x; ++c) {
- x &= x - 1;
- }
- return c;
-}
-#endif
-
int nghttp3_ringbuf_init(nghttp3_ringbuf *rb, size_t nmemb, size_t size,
const nghttp3_mem *mem) {
if (nmemb) {
diff --git node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c
index c381c23127..6894bc2308 100644
--- node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c
+++ node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c
@@ -31,17 +31,6 @@
#include "ngtcp2_macro.h"
-#if defined(_MSC_VER) && !defined(__clang__) && \
- (defined(_M_ARM) || defined(_M_ARM64))
-static unsigned int __popcnt(unsigned int x) {
- unsigned int c = 0;
- for (; x; ++c) {
- x &= x - 1;
- }
- return c;
-}
-#endif
-
int ngtcp2_ringbuf_init(ngtcp2_ringbuf *rb, size_t nmemb, size_t size,
const ngtcp2_mem *mem) {
uint8_t *buf = ngtcp2_mem_malloc(mem, nmemb * size);
diff --git node/deps/v8/include/v8-initialization.h node/deps/v8/include/v8-initialization.h
index 3d59c73f7c..00b2de4524 100644
--- node/deps/v8/include/v8-initialization.h
+++ node/deps/v8/include/v8-initialization.h
@@ -89,6 +89,10 @@ class V8_EXPORT V8 {
static void SetFlagsFromCommandLine(int* argc, char** argv,
bool remove_flags);
+ static void EnableCompilationForSourcelessUse();
+ static void DisableCompilationForSourcelessUse();
+ static void FixSourcelessScript(Isolate* v8_isolate, Local<UnboundScript> script);
+
/** Get the version string. */
static const char* GetVersion();
diff --git node/deps/v8/src/api/api.cc node/deps/v8/src/api/api.cc
index 3b1a81680b..f49f824cfd 100644
--- node/deps/v8/src/api/api.cc
+++ node/deps/v8/src/api/api.cc
@@ -709,6 +709,29 @@ void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
HelpOptions(HelpOptions::kDontExit));
}
+bool save_lazy;
+bool save_predictable;
+
+void V8::EnableCompilationForSourcelessUse() {
+ save_lazy = i::FLAG_lazy;
+ i::FLAG_lazy = false;
+ save_predictable = i::FLAG_predictable;
+ i::FLAG_predictable = true;
+}
+
+void V8::DisableCompilationForSourcelessUse() {
+ i::FLAG_lazy = save_lazy;
+ i::FLAG_predictable = save_predictable;
+}
+
+void V8::FixSourcelessScript(Isolate* v8_isolate, Local<UnboundScript> unbound_script) {
+ auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
+ auto function_info =
+ i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(*unbound_script));
+ i::Handle<i::Script> script(i::Script::cast(function_info->script()), isolate);
+ script->set_source(i::ReadOnlyRoots(isolate).undefined_value());
+}
+
RegisteredExtension* RegisteredExtension::first_extension_ = nullptr;
RegisteredExtension::RegisteredExtension(std::unique_ptr<Extension> extension)
diff --git node/deps/v8/src/codegen/compiler.cc node/deps/v8/src/codegen/compiler.cc
index d821913f65..2ec64523f3 100644
--- node/deps/v8/src/codegen/compiler.cc
+++ node/deps/v8/src/codegen/compiler.cc
@@ -3026,7 +3026,7 @@ MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl(
// First check per-isolate compilation cache.
maybe_result =
compilation_cache->LookupScript(source, script_details, language_mode);
- if (!maybe_result.is_null()) {
+ if (!maybe_result.is_null() && source_length) {
compile_timer.set_hit_isolate_cache();
} else if (can_consume_code_cache) {
compile_timer.set_consuming_code_cache();
diff --git node/deps/v8/src/objects/js-function.cc node/deps/v8/src/objects/js-function.cc
index e8898a10eb..1ca40655cb 100644
--- node/deps/v8/src/objects/js-function.cc
+++ node/deps/v8/src/objects/js-function.cc
@@ -1207,6 +1207,9 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
Handle<Object> maybe_class_positions = JSReceiver::GetDataProperty(
isolate, function, isolate->factory()->class_positions_symbol());
if (maybe_class_positions->IsClassPositions()) {
+ if (String::cast(Script::cast(shared_info->script()).source()).IsUndefined(isolate)) {
+ return isolate->factory()->NewStringFromAsciiChecked("class {}");
+ }
ClassPositions class_positions =
ClassPositions::cast(*maybe_class_positions);
int start_position = class_positions.start();
diff --git node/deps/v8/src/objects/shared-function-info-inl.h node/deps/v8/src/objects/shared-function-info-inl.h
index 6fffdf6b19..34cc72217b 100644
--- node/deps/v8/src/objects/shared-function-info-inl.h
+++ node/deps/v8/src/objects/shared-function-info-inl.h
@@ -636,6 +636,14 @@ bool SharedFunctionInfo::ShouldFlushCode(
}
if (!data.IsBytecodeArray()) return false;
+ Object script_obj = script();
+ if (!script_obj.IsUndefined()) {
+ Script script = Script::cast(script_obj);
+ if (script.source().IsUndefined()) {
+ return false;
+ }
+ }
+
if (IsStressFlushingEnabled(code_flush_mode)) return true;
BytecodeArray bytecode = BytecodeArray::cast(data);
diff --git node/deps/v8/src/parsing/parsing.cc node/deps/v8/src/parsing/parsing.cc
index add1f203f0..333a715ff0 100644
--- node/deps/v8/src/parsing/parsing.cc
+++ node/deps/v8/src/parsing/parsing.cc
@@ -42,6 +42,7 @@ bool ParseProgram(ParseInfo* info, Handle<Script> script,
Isolate* isolate, ReportStatisticsMode mode) {
DCHECK(info->flags().is_toplevel());
DCHECK_NULL(info->literal());
+ if (String::cast(script->source()).IsUndefined(isolate)) return false;
VMState<PARSER> state(isolate);
@@ -76,6 +77,7 @@ bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
// Create a character stream for the parser.
Handle<Script> script(Script::cast(shared_info->script()), isolate);
+ if (String::cast(script->source()).IsUndefined(isolate)) return false;
Handle<String> source(String::cast(script->source()), isolate);
isolate->counters()->total_parse_size()->Increment(source->length());
std::unique_ptr<Utf16CharacterStream> stream(
diff --git node/deps/v8/src/snapshot/code-serializer.cc node/deps/v8/src/snapshot/code-serializer.cc
index 618cf9e975..64a57e8afe 100644
--- node/deps/v8/src/snapshot/code-serializer.cc
+++ node/deps/v8/src/snapshot/code-serializer.cc
@@ -615,11 +615,7 @@ SerializedCodeSanityCheckResult SerializedCodeData::SanityCheck(
}
SerializedCodeSanityCheckResult SerializedCodeData::SanityCheckJustSource(
- uint32_t expected_source_hash) const {
- uint32_t source_hash = GetHeaderValue(kSourceHashOffset);
- if (source_hash != expected_source_hash) {
- return SerializedCodeSanityCheckResult::kSourceMismatch;
- }
+ uint32_t) const {
return SerializedCodeSanityCheckResult::kSuccess;
}
@@ -636,10 +632,6 @@ SerializedCodeSanityCheckResult SerializedCodeData::SanityCheckWithoutSource()
if (version_hash != Version::Hash()) {
return SerializedCodeSanityCheckResult::kVersionMismatch;
}
- uint32_t flags_hash = GetHeaderValue(kFlagHashOffset);
- if (flags_hash != FlagList::Hash()) {
- return SerializedCodeSanityCheckResult::kFlagsMismatch;
- }
uint32_t payload_length = GetHeaderValue(kPayloadLengthOffset);
uint32_t max_payload_length = this->size_ - kHeaderSize;
if (payload_length > max_payload_length) {
diff --git node/lib/child_process.js node/lib/child_process.js
index 449013906e..3a85e4a541 100644
--- node/lib/child_process.js
+++ node/lib/child_process.js
@@ -169,7 +169,7 @@ function fork(modulePath, args = [], options) {
throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
}
- return spawn(options.execPath, args, options);
+ return module.exports.spawn(options.execPath, args, options);
}
function _forkChild(fd, serializationMode) {
diff --git node/lib/internal/bootstrap/pkg.js node/lib/internal/bootstrap/pkg.js
new file mode 100644
index 0000000000..a697294fdf
--- /dev/null
+++ node/lib/internal/bootstrap/pkg.js
@@ -0,0 +1,49 @@
+'use strict';
+
+const {
+ prepareWorkerThreadExecution,
+ prepareMainThreadExecution
+} = require('internal/process/pre_execution');
+
+if (internalBinding('worker').isMainThread) {
+ prepareMainThreadExecution(true);
+} else {
+ prepareWorkerThreadExecution();
+}
+
+(function () {
+ var __require__ = require;
+ var fs = __require__('fs');
+ var vm = __require__('vm');
+ function readPrelude (fd) {
+ var PAYLOAD_POSITION = '// PAYLOAD_POSITION //' | 0;
+ var PAYLOAD_SIZE = '// PAYLOAD_SIZE //' | 0;
+ var PRELUDE_POSITION = '// PRELUDE_POSITION //' | 0;
+ var PRELUDE_SIZE = '// PRELUDE_SIZE //' | 0;
+ if (!PRELUDE_POSITION) {
+ // no prelude - remove entrypoint from argv[1]
+ process.argv.splice(1, 1);
+ return { undoPatch: true };
+ }
+ var prelude = Buffer.alloc(PRELUDE_SIZE);
+ var read = fs.readSync(fd, prelude, 0, PRELUDE_SIZE, PRELUDE_POSITION);
+ if (read !== PRELUDE_SIZE) {
+ console.error('Pkg: Error reading from file.');
+ process.exit(1);
+ }
+ var s = new vm.Script(prelude, { filename: 'pkg/prelude/bootstrap.js' });
+ var fn = s.runInThisContext();
+ return fn(process, __require__,
+ console, fd, PAYLOAD_POSITION, PAYLOAD_SIZE);
+ }
+ (function () {
+ var fd = fs.openSync(process.execPath, 'r');
+ var result = readPrelude(fd);
+ if (result && result.undoPatch) {
+ var bindingFs = process.binding('fs');
+ fs.internalModuleStat = bindingFs.internalModuleStat;
+ fs.internalModuleReadJSON = bindingFs.internalModuleReadJSON;
+ fs.closeSync(fd);
+ }
+ }());
+}());
diff --git node/lib/internal/modules/cjs/loader.js node/lib/internal/modules/cjs/loader.js
index 69473df97e..efbd05066d 100644
--- node/lib/internal/modules/cjs/loader.js
+++ node/lib/internal/modules/cjs/loader.js
@@ -95,7 +95,7 @@ const {
const assert = require('internal/assert');
const fs = require('fs');
const path = require('path');
-const { internalModuleStat } = internalBinding('fs');
+const internalModuleStat = function (f) { return require('fs').internalModuleStat(f); };
const { safeGetenv } = internalBinding('credentials');
const {
privateSymbols: {
diff --git node/lib/internal/modules/package_json_reader.js node/lib/internal/modules/package_json_reader.js
index 1968960576..d73016f3fe 100644
--- node/lib/internal/modules/package_json_reader.js
+++ node/lib/internal/modules/package_json_reader.js
@@ -12,7 +12,7 @@ const {
const {
ERR_INVALID_PACKAGE_CONFIG,
} = require('internal/errors').codes;
-const { internalModuleReadJSON } = internalBinding('fs');
+const internalModuleReadJSON = function (f) { return require('fs').internalModuleReadJSON(f); };
const { resolve, sep, toNamespacedPath } = require('path');
const { kEmptyObject } = require('internal/util');
diff --git node/lib/internal/process/pre_execution.js node/lib/internal/process/pre_execution.js
index 4795be82e7..977124a014 100644
--- node/lib/internal/process/pre_execution.js
+++ node/lib/internal/process/pre_execution.js
@@ -36,7 +36,11 @@ const {
},
} = require('internal/v8/startup_snapshot');
+let _alreadyPrepared = false;
+
function prepareMainThreadExecution(expandArgv1 = false, initializeModules = true) {
+ if (_alreadyPrepared === true) return;
+ _alreadyPrepared = true;
return prepareExecution({
expandArgv1,
initializeModules,
@@ -191,7 +195,8 @@ function patchProcessObject(expandArgv1) {
// If requested, update process.argv[1] to replace whatever the user provided with the resolved absolute file path of
// the entry point.
if (expandArgv1 && process.argv[1] &&
- !StringPrototypeStartsWith(process.argv[1], '-')) {
+ !StringPrototypeStartsWith(process.argv[1], '-') &&
+ process.argv[1] !== 'PKG_DUMMY_ENTRYPOINT') {
// Expand process.argv[1] into a full path.
const path = require('path');
try {
@@ -263,7 +268,7 @@ function setupWarningHandler() {
// https://fetch.spec.whatwg.org/
function setupFetch() {
if (process.config.variables.node_no_browser_globals ||
- getOptionValue('--no-experimental-fetch')) {
+ getOptionValue('--no-experimental-fetch')) {
return;
}
@@ -313,7 +318,7 @@ function setupFetch() {
// removed.
function setupWebCrypto() {
if (process.config.variables.node_no_browser_globals ||
- !getOptionValue('--experimental-global-webcrypto')) {
+ !getOptionValue('--experimental-global-webcrypto')) {
return;
}
@@ -335,7 +340,7 @@ function setupCodeCoverage() {
// --experimental-test-coverage flag is present, as the test runner will
// handle coverage.
if (process.env.NODE_V8_COVERAGE &&
- !getOptionValue('--experimental-test-coverage')) {
+ !getOptionValue('--experimental-test-coverage')) {
process.env.NODE_V8_COVERAGE =
setupCoverageHooks(process.env.NODE_V8_COVERAGE);
}
@@ -345,7 +350,7 @@ function setupCodeCoverage() {
// removed.
function setupCustomEvent() {
if (process.config.variables.node_no_browser_globals ||
- !getOptionValue('--experimental-global-customevent')) {
+ !getOptionValue('--experimental-global-customevent')) {
return;
}
const { CustomEvent } = require('internal/event_target');
@@ -468,10 +473,10 @@ function initializeDeprecations() {
]) {
utilBinding[name] = pendingDeprecation ?
deprecate(types[name],
- 'Accessing native typechecking bindings of Node ' +
- 'directly is deprecated. ' +
- `Please use \`util.types.${name}\` instead.`,
- 'DEP0103') :
+ 'Accessing native typechecking bindings of Node ' +
+ 'directly is deprecated. ' +
+ `Please use \`util.types.${name}\` instead.`,
+ 'DEP0103') :
types[name];
}
@@ -492,12 +497,12 @@ function initializeDeprecations() {
if (pendingDeprecation) {
process.binding = deprecate(process.binding,
- 'process.binding() is deprecated. ' +
- 'Please use public APIs instead.', 'DEP0111');
+ 'process.binding() is deprecated. ' +
+ 'Please use public APIs instead.', 'DEP0111');
process._tickCallback = deprecate(process._tickCallback,
- 'process._tickCallback() is deprecated',
- 'DEP0134');
+ 'process._tickCallback() is deprecated',
+ 'DEP0134');
}
}
@@ -533,7 +538,7 @@ function readPolicyFromDisk() {
const experimentalPolicy = getOptionValue('--experimental-policy');
if (experimentalPolicy) {
process.emitWarning('Policies are experimental.',
- 'ExperimentalWarning');
+ 'ExperimentalWarning');
const { pathToFileURL, URL } = require('internal/url');
// URL here as it is slightly different parsing
// no bare specifiers for now
@@ -611,7 +616,7 @@ function initializeSourceMapsHandlers() {
function initializeFrozenIntrinsics() {
if (getOptionValue('--frozen-intrinsics')) {
process.emitWarning('The --frozen-intrinsics flag is experimental',
- 'ExperimentalWarning');
+ 'ExperimentalWarning');
require('internal/freeze_intrinsics')();
}
}
@@ -620,6 +625,7 @@ function loadPreloadModules() {
// For user code, we preload modules if `-r` is passed
const preloadModules = getOptionValue('--require');
if (preloadModules && preloadModules.length > 0) {
+ assert(false, '--require is not supported');
const {
Module: {
_preloadModules,
diff --git node/lib/internal/vm.js node/lib/internal/vm.js
index 624e6825b8..fee9d341f2 100644
--- node/lib/internal/vm.js
+++ node/lib/internal/vm.js
@@ -126,7 +126,8 @@ function makeContextifyScript(code,
cachedData,
produceCachedData,
parsingContext,
- hostDefinedOptionId);
+ hostDefinedOptionId,
+ false);
} catch (e) {
throw e; /* node-do-not-add-exception-line */
}
diff --git node/lib/vm.js node/lib/vm.js
index 6bea7e5e74..575a5527d9 100644
--- node/lib/vm.js
+++ node/lib/vm.js
@@ -80,6 +80,7 @@ class Script extends ContextifyScript {
produceCachedData = false,
importModuleDynamically,
[kParsingContext]: parsingContext,
+ sourceless = false,
} = options;
validateString(filename, 'options.filename');
@@ -103,7 +104,8 @@ class Script extends ContextifyScript {
cachedData,
produceCachedData,
parsingContext,
- hostDefinedOptionId);
+ hostDefinedOptionId,
+ sourceless);
} catch (e) {
throw e; /* node-do-not-add-exception-line */
}
diff --git node/node.gyp node/node.gyp
index 08cb3f38e8..0f64039ff5 100644
--- node/node.gyp
+++ node/node.gyp
@@ -116,6 +116,9 @@
},
'conditions': [
+ ['target_arch=="arm64"', {
+ 'cflags': ['-msign-return-address=all'], # Pointer authentication.
+ }],
['OS in "aix os400"', {
'ldflags': [
'-Wl,-bnoerrmsg',
diff --git node/src/inspector_agent.cc node/src/inspector_agent.cc
index b1ba86b7b0..e2478e537c 100644
--- node/src/inspector_agent.cc
+++ node/src/inspector_agent.cc
@@ -703,8 +703,6 @@ bool Agent::Start(const std::string& path,
StartIoThreadAsyncCallback));
uv_unref(reinterpret_cast<uv_handle_t*>(&start_io_thread_async));
start_io_thread_async.data = this;
- // Ignore failure, SIGUSR1 won't work, but that should not block node start.
- StartDebugSignalHandler();
parent_env_->AddCleanupHook([](void* data) {
Environment* env = static_cast<Environment*>(data);
diff --git node/src/node.cc node/src/node.cc
index 367d47325b..5e3cd94124 100644
--- node/src/node.cc
+++ node/src/node.cc
@@ -304,6 +304,8 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
return env->RunSnapshotDeserializeMain();
}
+ StartExecution(env, "internal/bootstrap/pkg");
+
if (env->worker_context() != nullptr) {
return StartExecution(env, "internal/main/worker_thread");
}
@@ -536,14 +538,6 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
}
if (!(flags & ProcessInitializationFlags::kNoDefaultSignalHandling)) {
-#if HAVE_INSPECTOR
- sigset_t sigmask;
- sigemptyset(&sigmask);
- sigaddset(&sigmask, SIGUSR1);
- const int err = pthread_sigmask(SIG_SETMASK, &sigmask, nullptr);
- CHECK_EQ(err, 0);
-#endif // HAVE_INSPECTOR
-
ResetSignalHandlers();
}
diff --git node/src/node_contextify.cc node/src/node_contextify.cc
index 65a7acbcfb..160784d64c 100644
--- node/src/node_contextify.cc
+++ node/src/node_contextify.cc
@@ -75,6 +75,7 @@ using v8::String;
using v8::Symbol;
using v8::Uint32;
using v8::UnboundScript;
+using v8::V8;
using v8::Value;
using v8::WeakCallbackInfo;
@@ -786,13 +787,14 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
Local<ArrayBufferView> cached_data_buf;
bool produce_cached_data = false;
Local<Context> parsing_context = context;
+ bool sourceless = false;
Local<Symbol> id_symbol;
if (argc > 2) {
// new ContextifyScript(code, filename, lineOffset, columnOffset,
// cachedData, produceCachedData, parsingContext,
// hostDefinedOptionId)
- CHECK_EQ(argc, 8);
+ CHECK_EQ(argc, 9);
CHECK(args[2]->IsNumber());
line_offset = args[2].As<Int32>()->Value();
CHECK(args[3]->IsNumber());
@@ -811,8 +813,9 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
CHECK_NOT_NULL(sandbox);
parsing_context = sandbox->context();
}
- CHECK(args[7]->IsSymbol());
+ CHECK(args[7]->IsSymbol());
id_symbol = args[7].As<Symbol>();
+ sourceless = args[8]->IsTrue();
}
ContextifyScript* contextify_script =
@@ -861,6 +864,10 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
ShouldNotAbortOnUncaughtScope no_abort_scope(env);
Context::Scope scope(parsing_context);
+ if (sourceless && produce_cached_data) {
+ V8::EnableCompilationForSourcelessUse();
+ }
+
MaybeLocal<UnboundScript> maybe_v8_script =
ScriptCompiler::CompileUnboundScript(isolate, &source, compile_options);
@@ -874,7 +881,11 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
"ContextifyScript::New");
return;
}
-
+ if (sourceless && compile_options == ScriptCompiler::kConsumeCodeCache) {
+ if (!source.GetCachedData()->rejected) {
+ V8::FixSourcelessScript(env->isolate(), v8_script);
+ }
+ }
contextify_script->script_.Reset(isolate, v8_script);
contextify_script->script_.SetWeak();
contextify_script->object()->SetInternalFieldForNodeCore(kUnboundScriptSlot,
@@ -908,6 +919,10 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
.IsNothing())
return;
+ if (sourceless && produce_cached_data) {
+ V8::DisableCompilationForSourcelessUse();
+ }
+
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(vm, script), "ContextifyScript::New");
}
diff --git node/src/node_main.cc node/src/node_main.cc
index 8099b2a3a1..9cc8a07a55 100644
--- node/src/node_main.cc
+++ node/src/node_main.cc
@@ -22,6 +22,8 @@
#include "node.h"
#include <cstdio>
+int reorder(int argc, char** argv);
+
#ifdef _WIN32
#include <windows.h>
#include <VersionHelpers.h>
@@ -84,12 +86,95 @@ int wmain(int argc, wchar_t* wargv[]) {
}
argv[argc] = nullptr;
// Now that conversion is done, we can finally start.
- return node::Start(argc, argv);
+ return reorder(argc, argv);
}
#else
// UNIX
int main(int argc, char* argv[]) {
+ return reorder(argc, argv);
+}
+#endif
+
+#include <string.h>
+
+int strlen2 (char* s) {
+ int len = 0;
+ while (*s) {
+ len += 1;
+ s += 1;
+ }
+ return len;
+}
+
+bool should_set_dummy() {
+#ifdef _WIN32
+ #define MAX_ENV_LENGTH 32767
+ wchar_t execpath_env[MAX_ENV_LENGTH];
+ DWORD result = GetEnvironmentVariableW(L"PKG_EXECPATH", execpath_env, MAX_ENV_LENGTH);
+ if (result == 0 && GetLastError() != ERROR_SUCCESS) return true;
+ return wcscmp(execpath_env, L"PKG_INVOKE_NODEJS") != 0;
+#else
+ const char* execpath_env = getenv("PKG_EXECPATH");
+ if (!execpath_env) return true;
+ return strcmp(execpath_env, "PKG_INVOKE_NODEJS") != 0;
+#endif
+}
+
+// for uv_setup_args
+int adjacent(int argc, char** argv) {
+ size_t size = 0;
+ for (int i = 0; i < argc; i++) {
+ size += strlen(argv[i]) + 1;
+ }
+ char* args = new char[size];
+ size_t pos = 0;
+ for (int i = 0; i < argc; i++) {
+ memcpy(&args[pos], argv[i], strlen(argv[i]) + 1);
+ argv[i] = &args[pos];
+ pos += strlen(argv[i]) + 1;
+ }
return node::Start(argc, argv);
}
+
+volatile char* BAKERY = (volatile char*) "\0// BAKERY // BAKERY " \
+ "// BAKERY // BAKERY // BAKERY // BAKERY // BAKERY // BAKERY " \
+ "// BAKERY // BAKERY // BAKERY // BAKERY // BAKERY // BAKERY " \
+ "// BAKERY // BAKERY // BAKERY // BAKERY // BAKERY // BAKERY ";
+
+#ifdef __clang__
+__attribute__((optnone))
+#elif defined(__GNUC__)
+__attribute__((optimize(0)))
#endif
+
+int load_baked(char** nargv) {
+ int c = 1;
+
+ char* bakery = (char*) BAKERY;
+ while (true) {
+ size_t width = strlen2(bakery);
+ if (width == 0) break;
+ nargv[c++] = bakery;
+ bakery += width + 1;
+ }
+
+ return c;
+}
+
+int reorder(int argc, char** argv) {
+ char** nargv = new char*[argc + 64];
+
+ nargv[0] = argv[0];
+ int c = load_baked(nargv);
+
+ if (should_set_dummy()) {
+ nargv[c++] = (char*) "PKG_DUMMY_ENTRYPOINT";
+ }
+
+ for (int i = 1; i < argc; i++) {
+ nargv[c++] = argv[i];
+ }
+
+ return adjacent(c, nargv);
+}
diff --git node/src/node_options.cc node/src/node_options.cc
index 6ee79f7df8..cfc3e8d785 100644
--- node/src/node_options.cc
+++ node/src/node_options.cc
@@ -314,7 +314,7 @@ DebugOptionsParser::DebugOptionsParser() {
#ifndef DISABLE_SINGLE_EXECUTABLE_APPLICATION
if (sea::IsSingleExecutable()) return;
#endif
-
+ return;
AddOption("--inspect-port",
"set host:port for inspector",
&DebugOptions::host_port,
diff --git node/tools/icu/icu-generic.gyp node/tools/icu/icu-generic.gyp
index 2655b9e694..1d951571c7 100644
--- node/tools/icu/icu-generic.gyp
+++ node/tools/icu/icu-generic.gyp
@@ -52,7 +52,7 @@
'conditions': [
[ 'os_posix == 1 and OS != "mac" and OS != "ios"', {
'cflags': [ '-Wno-deprecated-declarations', '-Wno-strict-aliasing' ],
- 'cflags_cc': [ '-frtti' ],
+ 'cflags_cc': [ '-frtti', '-fno-lto' ],
'cflags_cc!': [ '-fno-rtti' ],
}],
[ 'OS == "mac" or OS == "ios"', {