@yao-pkg/pkg-fetch 3.6.0 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,863 @@
1
+ diff --git node/common.gypi node/common.gypi
2
+ index 576d5057d9..34e85ee423 100644
3
+ --- node/common.gypi
4
+ +++ node/common.gypi
5
+ @@ -192,7 +192,7 @@
6
+ ['clang==1', {
7
+ 'lto': ' -flto ', # Clang
8
+ }, {
9
+ - 'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC
10
+ + 'lto': ' -flto=4 -ffat-lto-objects ', # GCC
11
+ }],
12
+ ],
13
+ },
14
+ diff --git node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c
15
+ index 7d3ab39bf8..67a48dee53 100644
16
+ --- node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c
17
+ +++ node/deps/ngtcp2/nghttp3/lib/nghttp3_ringbuf.c
18
+ @@ -34,10 +34,7 @@
19
+ #include "nghttp3_macro.h"
20
+
21
+ static int ispow2(size_t n) {
22
+ -#if defined(_MSC_VER) && !defined(__clang__) && \
23
+ - (defined(_M_ARM) || (defined(_M_ARM64) && _MSC_VER < 1941))
24
+ - return n && !(n & (n - 1));
25
+ -#elif defined(WIN32)
26
+ +#if defined(WIN32)
27
+ return 1 == __popcnt((unsigned int)n);
28
+ #else /* !((defined(_MSC_VER) && !defined(__clang__) && (defined(_M_ARM) || \
29
+ (defined(_M_ARM64) && _MSC_VER < 1941))) || defined(WIN32)) */
30
+ diff --git node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c
31
+ index 353afca4d4..dea944aed5 100644
32
+ --- node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c
33
+ +++ node/deps/ngtcp2/ngtcp2/lib/ngtcp2_ringbuf.c
34
+ @@ -33,10 +33,7 @@
35
+
36
+ #ifndef NDEBUG
37
+ static int ispow2(size_t n) {
38
+ -# if defined(_MSC_VER) && !defined(__clang__) && \
39
+ - (defined(_M_ARM) || (defined(_M_ARM64) && _MSC_VER < 1941))
40
+ - return n && !(n & (n - 1));
41
+ -# elif defined(WIN32)
42
+ +#if defined(WIN32)
43
+ return 1 == __popcnt((unsigned int)n);
44
+ # else /* !((defined(_MSC_VER) && !defined(__clang__) && (defined(_M_ARM) || \
45
+ (defined(_M_ARM64) && _MSC_VER < 1941))) || defined(WIN32)) */
46
+ diff --git node/deps/v8/include/v8-initialization.h node/deps/v8/include/v8-initialization.h
47
+ index 46a21a02cb..fdb0edf42a 100644
48
+ --- node/deps/v8/include/v8-initialization.h
49
+ +++ node/deps/v8/include/v8-initialization.h
50
+ @@ -98,6 +98,10 @@ class V8_EXPORT V8 {
51
+ static void SetFlagsFromCommandLine(int* argc, char** argv,
52
+ bool remove_flags);
53
+
54
+ + static void EnableCompilationForSourcelessUse();
55
+ + static void DisableCompilationForSourcelessUse();
56
+ + static void FixSourcelessScript(Isolate* v8_isolate, Local<UnboundScript> script);
57
+ +
58
+ /** Get the version string. */
59
+ static const char* GetVersion();
60
+
61
+ diff --git node/deps/v8/src/api/api.cc node/deps/v8/src/api/api.cc
62
+ index ef4546de27..60bb6a4edc 100644
63
+ --- node/deps/v8/src/api/api.cc
64
+ +++ node/deps/v8/src/api/api.cc
65
+ @@ -443,6 +443,28 @@ void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
66
+ HelpOptions(HelpOptions::kDontExit));
67
+ }
68
+
69
+ +bool save_lazy;
70
+ +bool save_predictable;
71
+ +
72
+ +void V8::EnableCompilationForSourcelessUse() {
73
+ + save_lazy = i::v8_flags.lazy;
74
+ + i::v8_flags.lazy = false;
75
+ + save_predictable = i::v8_flags.predictable;
76
+ + i::v8_flags.predictable = true;
77
+ +}
78
+ +
79
+ +void V8::DisableCompilationForSourcelessUse() {
80
+ + i::v8_flags.lazy = save_lazy;
81
+ + i::v8_flags.predictable = save_predictable;
82
+ +}
83
+ +
84
+ +void V8::FixSourcelessScript(Isolate* v8_isolate, Local<UnboundScript> unbound_script) {
85
+ + auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
86
+ + auto function_info = i::Cast<i::SharedFunctionInfo>(Utils::OpenHandle(*unbound_script));
87
+ + i::Handle<i::Script> script(i::Cast<i::Script>(function_info->script()), isolate);
88
+ + script->SetSource(isolate, script, isolate->factory()->empty_string());
89
+ +}
90
+ +
91
+ RegisteredExtension* RegisteredExtension::first_extension_ = nullptr;
92
+
93
+ RegisteredExtension::RegisteredExtension(std::unique_ptr<Extension> extension)
94
+ diff --git node/deps/v8/src/codegen/compiler.cc node/deps/v8/src/codegen/compiler.cc
95
+ index e31937f042..fa8c37072f 100644
96
+ --- node/deps/v8/src/codegen/compiler.cc
97
+ +++ node/deps/v8/src/codegen/compiler.cc
98
+ @@ -3945,7 +3945,7 @@ MaybeDirectHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl(
99
+ maybe_script = lookup_result.script();
100
+ maybe_result = lookup_result.toplevel_sfi();
101
+ is_compiled_scope = lookup_result.is_compiled_scope();
102
+ - if (!maybe_result.is_null()) {
103
+ + if (!maybe_result.is_null() && source->length()) {
104
+ compile_timer.set_hit_isolate_cache();
105
+ } else if (can_consume_code_cache) {
106
+ compile_timer.set_consuming_code_cache();
107
+ diff --git node/deps/v8/src/codegen/define-code-stub-assembler-macros.inc node/deps/v8/src/codegen/define-code-stub-assembler-macros.inc
108
+ index fb272f6afd..eb7c237530 100644
109
+ --- node/deps/v8/src/codegen/define-code-stub-assembler-macros.inc
110
+ +++ node/deps/v8/src/codegen/define-code-stub-assembler-macros.inc
111
+ @@ -21,7 +21,7 @@
112
+ // This is a check that always calls into the runtime if it aborts.
113
+ // This also exits silently when --hole-fuzzing is enabled.
114
+ #define CSA_HOLE_SECURITY_CHECK(csa, x) \
115
+ - (csa)->Check([&]() -> TNode<BoolT> { return x; }, #x, __FILE__, __LINE__)
116
+ + (csa)->Check([&]() -> TNode<BoolT> { return x; }, #x, "placeholder", 1)
117
+
118
+ #ifdef DEBUG
119
+ // CSA_DCHECK_ARGS generates an
120
+ diff --git node/deps/v8/src/compiler/wasm-compiler.cc node/deps/v8/src/compiler/wasm-compiler.cc
121
+ index 87a194b5c2..06270d0c6e 100644
122
+ --- node/deps/v8/src/compiler/wasm-compiler.cc
123
+ +++ node/deps/v8/src/compiler/wasm-compiler.cc
124
+ @@ -1096,11 +1096,15 @@ wasm::WasmCompilationResult CompileWasmImportCallWrapper(
125
+ "wasm-to-js-%d-", static_cast<int>(kind));
126
+ PrintSignature(base::VectorOf(func_name, kMaxNameLen) + name_prefix_len, sig,
127
+ '-');
128
+ + wasm::WrapperCompilationInfo info;
129
+ + info.code_kind = CodeKind::WASM_TO_JS_FUNCTION;
130
+ + info.import_kind = kind;
131
+ + info.expected_arity = expected_arity;
132
+ + info.suspend = suspend;
133
+
134
+ auto result = Pipeline::GenerateCodeForWasmNativeStubFromTurboshaft(
135
+ sig,
136
+ - wasm::WrapperCompilationInfo{CodeKind::WASM_TO_JS_FUNCTION, kind,
137
+ - expected_arity, suspend},
138
+ + info,
139
+ func_name, WasmStubAssemblerOptions(), nullptr);
140
+
141
+ if (V8_UNLIKELY(v8_flags.trace_wasm_compilation_times)) {
142
+ diff --git node/deps/v8/src/heap/marking-visitor-inl.h node/deps/v8/src/heap/marking-visitor-inl.h
143
+ index c38e02da07..6d6d7b33ed 100644
144
+ --- node/deps/v8/src/heap/marking-visitor-inl.h
145
+ +++ node/deps/v8/src/heap/marking-visitor-inl.h
146
+ @@ -464,6 +464,13 @@ bool MarkingVisitorBase<ConcreteVisitor>::HasBytecodeArrayForFlushing(
147
+ template <typename ConcreteVisitor>
148
+ bool MarkingVisitorBase<ConcreteVisitor>::ShouldFlushCode(
149
+ Tagged<SharedFunctionInfo> sfi) const {
150
+ + auto script_obj = sfi->script();
151
+ + if (!IsUndefined(script_obj)) {
152
+ + auto script = Cast<Script>(script_obj);
153
+ + if (IsUndefined(script->source())) {
154
+ + return false;
155
+ + }
156
+ + }
157
+ // This method is used both for flushing bytecode and baseline code.
158
+ // During last resort GCs and stress testing we consider all code old.
159
+ return IsOld(sfi) || V8_UNLIKELY(IsForceFlushingEnabled(code_flush_mode_));
160
+ diff --git node/deps/v8/src/objects/js-function.cc node/deps/v8/src/objects/js-function.cc
161
+ index 22df966c8f..8c1835e0b6 100644
162
+ --- node/deps/v8/src/objects/js-function.cc
163
+ +++ node/deps/v8/src/objects/js-function.cc
164
+ @@ -1454,6 +1454,9 @@ DirectHandle<String> JSFunction::ToString(DirectHandle<JSFunction> function) {
165
+ DirectHandle<Object> maybe_class_positions = JSReceiver::GetDataProperty(
166
+ isolate, function, isolate->factory()->class_positions_symbol());
167
+ if (IsClassPositions(*maybe_class_positions)) {
168
+ + if (IsUndefined(Cast<String>(Cast<Script>(shared_info->script())->source()))) {
169
+ + return isolate->factory()->NewStringFromAsciiChecked("class {}");
170
+ + }
171
+ Tagged<ClassPositions> class_positions =
172
+ Cast<ClassPositions>(*maybe_class_positions);
173
+ int start_position = class_positions->start();
174
+ diff --git node/deps/v8/src/objects/objects.cc node/deps/v8/src/objects/objects.cc
175
+ index 14013579bd..1e9bc653e0 100644
176
+ --- node/deps/v8/src/objects/objects.cc
177
+ +++ node/deps/v8/src/objects/objects.cc
178
+ @@ -4347,7 +4347,11 @@ void Script::InitLineEndsInternal(IsolateT* isolate,
179
+
180
+ void Script::SetSource(Isolate* isolate, DirectHandle<Script> script,
181
+ DirectHandle<String> source) {
182
+ - script->set_source(*source);
183
+ + if (source->length() > 0) {
184
+ + script->set_source(*source);
185
+ + } else {
186
+ + script->set_source(*isolate->factory()->undefined_value());
187
+ + }
188
+ if (isolate->NeedsSourcePositions()) {
189
+ InitLineEnds(isolate, script);
190
+ } else if (script->line_ends() ==
191
+ diff --git node/deps/v8/src/parsing/parsing.cc node/deps/v8/src/parsing/parsing.cc
192
+ index 31758fdfed..483192fc35 100644
193
+ --- node/deps/v8/src/parsing/parsing.cc
194
+ +++ node/deps/v8/src/parsing/parsing.cc
195
+ @@ -42,6 +42,7 @@ bool ParseProgram(ParseInfo* info, DirectHandle<Script> script,
196
+ DCHECK(info->flags().is_toplevel());
197
+ DCHECK_NULL(info->literal());
198
+
199
+ + if (IsUndefined(Cast<String>(script->source()))) return false;
200
+ VMState<PARSER> state(isolate);
201
+
202
+ // Create a character stream for the parser.
203
+ @@ -75,6 +76,8 @@ bool ParseFunction(ParseInfo* info,
204
+
205
+ // Create a character stream for the parser.
206
+ DirectHandle<Script> script(Cast<Script>(shared_info->script()), isolate);
207
+ + if (IsUndefined(Cast<String>(script->source()))) return false;
208
+ +
209
+ Handle<String> source(Cast<String>(script->source()), isolate);
210
+ uint32_t start_pos = shared_info->StartPosition();
211
+ uint32_t end_pos = shared_info->EndPosition();
212
+ diff --git node/deps/v8/src/snapshot/code-serializer.cc node/deps/v8/src/snapshot/code-serializer.cc
213
+ index 11ced93c08..1f4b534415 100644
214
+ --- node/deps/v8/src/snapshot/code-serializer.cc
215
+ +++ node/deps/v8/src/snapshot/code-serializer.cc
216
+ @@ -771,10 +771,6 @@ SerializedCodeSanityCheckResult SerializedCodeData::SanityCheck(
217
+
218
+ SerializedCodeSanityCheckResult SerializedCodeData::SanityCheckJustSource(
219
+ uint32_t expected_source_hash) const {
220
+ - uint32_t source_hash = GetHeaderValue(kSourceHashOffset);
221
+ - if (source_hash != expected_source_hash) {
222
+ - return SerializedCodeSanityCheckResult::kSourceMismatch;
223
+ - }
224
+ return SerializedCodeSanityCheckResult::kSuccess;
225
+ }
226
+
227
+ @@ -791,13 +787,12 @@ SerializedCodeSanityCheckResult SerializedCodeData::SanityCheckWithoutSource(
228
+ if (version_hash != Version::Hash()) {
229
+ return SerializedCodeSanityCheckResult::kVersionMismatch;
230
+ }
231
+ - uint32_t flags_hash = GetHeaderValue(kFlagHashOffset);
232
+ - if (flags_hash != FlagList::Hash()) {
233
+ - return SerializedCodeSanityCheckResult::kFlagsMismatch;
234
+ - }
235
+ uint32_t ro_snapshot_checksum =
236
+ GetHeaderValue(kReadOnlySnapshotChecksumOffset);
237
+ if (ro_snapshot_checksum != expected_ro_snapshot_checksum) {
238
+ + // for debugging snapshot checkum issues
239
+ + // PrintF("[pkg] ReadOnlySnapshotChecksum mismatch: code=%08x built=%08x\n",
240
+ + // ro_snapshot_checksum, expected_ro_snapshot_checksum);
241
+ return SerializedCodeSanityCheckResult::kReadOnlySnapshotChecksumMismatch;
242
+ }
243
+ uint32_t payload_length = GetHeaderValue(kPayloadLengthOffset);
244
+ diff --git node/deps/v8/src/snapshot/read-only-serializer.cc node/deps/v8/src/snapshot/read-only-serializer.cc
245
+ index 0178607289..88c8c2b852 100644
246
+ --- node/deps/v8/src/snapshot/read-only-serializer.cc
247
+ +++ node/deps/v8/src/snapshot/read-only-serializer.cc
248
+ @@ -12,6 +12,9 @@
249
+ #include "src/objects/slots.h"
250
+ #include "src/snapshot/read-only-serializer-deserializer.h"
251
+
252
+ +// for debugging readonly heap serialization
253
+ +// #define PKG_TRACE_READONLY_HEAP 1
254
+ +
255
+ namespace v8 {
256
+ namespace internal {
257
+
258
+ @@ -160,6 +163,10 @@ ro::EncodedTagged Encode(Isolate* isolate, Tagged<HeapObject> o) {
259
+ uint32_t offset = static_cast<int>(chunk->Offset(o_address));
260
+ DCHECK(IsAligned(offset, kTaggedSize));
261
+
262
+ + #ifdef PKG_TRACE_READONLY_HEAP
263
+ + PrintF(" [PKGTRACE] encode tagged page_index=%d offset=%u offidx=%u\n",
264
+ + index, offset, offset / kTaggedSize);
265
+ + #endif
266
+ return ro::EncodedTagged(index, offset / kTaggedSize);
267
+ }
268
+
269
+ @@ -247,6 +254,11 @@ class EncodeRelocationsVisitor final : public ObjectVisitor {
270
+
271
+ // Encode:
272
+ ro::EncodedTagged encoded = Encode(isolate_, o.GetHeapObject());
273
+ +
274
+ + #ifndef V8_COMPRESS_POINTERS
275
+ + memset(segment_->contents.get() + slot_offset, 0, kTaggedSize);
276
+ + #endif
277
+ +
278
+ memcpy(segment_->contents.get() + slot_offset, &encoded,
279
+ ro::EncodedTagged::kSize);
280
+
281
+ @@ -279,8 +291,18 @@ void ReadOnlySegmentForSerialization::EncodeTaggedSlots(Isolate* isolate) {
282
+ const Address segment_end = segment_start + segment_size;
283
+ ReadOnlyPageObjectIterator it(page, segment_start,
284
+ SkipFreeSpaceOrFiller::kNo);
285
+ +
286
+ + #ifdef PKG_TRACE_READONLY_HEAP
287
+ + uint32_t counter = 0;
288
+ + #endif
289
+ +
290
+ for (Tagged<HeapObject> o = it.Next(); !o.is_null(); o = it.Next()) {
291
+ if (o.address() >= segment_end) break;
292
+ + #ifdef PKG_TRACE_READONLY_HEAP
293
+ + Tagged<Map> map = o->map(isolate);
294
+ + PrintF(" [PKGTRACE] tag heapobj i=%d so=%zu s=%d t=%d\n",
295
+ + counter++, o.address()-segment_start, o->Size(), map->instance_type());
296
+ + #endif
297
+ VisitObject(isolate, o, &v);
298
+ }
299
+ }
300
+ @@ -307,7 +329,14 @@ class ReadOnlyHeapImageSerializer {
301
+ DCHECK_EQ(sink_->Position(), 0);
302
+
303
+ ReadOnlySpace* ro_space = isolate_->read_only_heap()->read_only_space();
304
+ -
305
+ + #ifdef PKG_TRACE_READONLY_HEAP
306
+ + #ifdef V8_COMPRESS_POINTERS
307
+ + bool pce = true;
308
+ + #else
309
+ + bool pce = false;
310
+ + #endif
311
+ + PrintF("[PKGTRACE] BEGIN SERIALIZE READONLY ro_space=%p pce=%d\n", ro_space, pce);
312
+ + #endif
313
+ // Allocate all pages first s.t. the deserializer can easily handle forward
314
+ // references (e.g.: an object on page i points at an object on page i+1).
315
+ for (const ReadOnlyPageMetadata* page : ro_space->pages()) {
316
+ @@ -321,6 +350,10 @@ class ReadOnlyHeapImageSerializer {
317
+
318
+ EmitReadOnlyRootsTable();
319
+ sink_->Put(Bytecode::kFinalizeReadOnlySpace, "space end");
320
+ +
321
+ + #ifdef PKG_TRACE_READONLY_HEAP
322
+ + PrintF("[PKGTRACE] END SERIALIZE READONLY\n");
323
+ + #endif
324
+ }
325
+
326
+ uint32_t IndexOf(const ReadOnlyPageMetadata* page) {
327
+ @@ -339,6 +372,13 @@ class ReadOnlyHeapImageSerializer {
328
+ sink_->PutUint30(
329
+ static_cast<uint32_t>(page->HighWaterMark() - page->area_start()),
330
+ "area size in bytes");
331
+ + #ifdef PKG_TRACE_READONLY_HEAP
332
+ + PrintF("[PKGTRACE] emit allocate page area_ro_space_off=%zu area_start=%lx idx=%d size=%d \n",
333
+ + ((uint8_t*)(page->area_start()))-((uint8_t*)(isolate_->read_only_heap()->read_only_space())),
334
+ + page->area_start(),
335
+ + IndexOf(page),
336
+ + static_cast<uint32_t>(page->HighWaterMark() - page->area_start()));
337
+ + #endif
338
+ if (V8_STATIC_ROOTS_BOOL) {
339
+ auto page_addr = page->ChunkAddress();
340
+ sink_->PutUint32(V8HeapCompressionScheme::CompressAny(page_addr),
341
+ @@ -350,6 +390,9 @@ class ReadOnlyHeapImageSerializer {
342
+ const std::vector<MemoryRegion>& unmapped_regions) {
343
+ Address pos = page->area_start();
344
+
345
+ + #ifdef PKG_TRACE_READONLY_HEAP
346
+ + PrintF("[PKGTRACE] serialize page addr=%lx\n");
347
+ + #endif
348
+ // If this page contains unmapped regions split it into multiple segments.
349
+ for (auto r = unmapped_regions.begin(); r != unmapped_regions.end(); ++r) {
350
+ // Regions must be sorted and non-overlapping.
351
+ @@ -372,9 +415,17 @@ class ReadOnlyHeapImageSerializer {
352
+ ReadOnlySegmentForSerialization segment(isolate_, page, pos, segment_size,
353
+ &pre_processor_);
354
+ EmitSegment(&segment);
355
+ + #ifdef PKG_TRACE_READONLY_HEAP
356
+ + PrintF("[PKGTRACE] last segment\n");
357
+ + #endif
358
+ }
359
+
360
+ void EmitSegment(const ReadOnlySegmentForSerialization* segment) {
361
+ + #ifdef PKG_TRACE_READONLY_HEAP
362
+ + PrintF(" [PKGTRACE] segment segment_start=%lx page_index=%d offset=%zu size=%zu tagged_slots=%zu\n",
363
+ + segment->segment_start, IndexOf(segment->page), segment->segment_offset,
364
+ + segment->segment_size, segment->tagged_slots.size_in_bytes());
365
+ + #endif
366
+ sink_->Put(Bytecode::kSegment, "segment begin");
367
+ sink_->PutUint30(IndexOf(segment->page), "page index");
368
+ sink_->PutUint30(static_cast<uint32_t>(segment->segment_offset),
369
+ @@ -383,11 +434,29 @@ class ReadOnlyHeapImageSerializer {
370
+ "segment byte size");
371
+ sink_->PutRaw(segment->contents.get(),
372
+ static_cast<int>(segment->segment_size), "page");
373
+ + #ifdef PKG_TRACE_READONLY_HEAP
374
+ + PrintF(" [PKGTRACE] segment_contents: ");
375
+ + const uint8_t* cdata = reinterpret_cast<const uint8_t*>(segment->contents.get());
376
+ + for (size_t i = 0; i < segment->segment_size; i++) {
377
+ + if (i%128==0) {PrintF("\n [PKGTRACE] ");}
378
+ + PrintF("%02x", cdata[i]);
379
+ + }
380
+ + PrintF("\n");
381
+ + #endif
382
+ if (!V8_STATIC_ROOTS_BOOL) {
383
+ sink_->Put(Bytecode::kRelocateSegment, "relocate segment");
384
+ sink_->PutRaw(segment->tagged_slots.data(),
385
+ static_cast<int>(segment->tagged_slots.size_in_bytes()),
386
+ "tagged_slots");
387
+ + #ifdef PKG_TRACE_READONLY_HEAP
388
+ + PrintF(" [PKGTRACE] tagged_slots: ");
389
+ + const uint8_t* tdata = segment->tagged_slots.data();
390
+ + for (size_t i = 0; i < segment->tagged_slots.size_in_bytes(); i++) {
391
+ + if (i%128==0) {PrintF("\n [PKGTRACE] ");}
392
+ + PrintF("%02x", tdata[i]);
393
+ + }
394
+ + PrintF("\n");
395
+ + #endif
396
+ }
397
+ }
398
+
399
+ @@ -395,11 +464,20 @@ class ReadOnlyHeapImageSerializer {
400
+ sink_->Put(Bytecode::kReadOnlyRootsTable, "read only roots table");
401
+ if (!V8_STATIC_ROOTS_BOOL) {
402
+ ReadOnlyRoots roots(isolate_);
403
+ + #ifdef PKG_TRACE_READONLY_HEAP
404
+ + PrintF("[PKGTRACE] readonly roots %lu\n", ReadOnlyRoots::kEntriesCount);
405
+ + #endif
406
+ for (size_t i = 0; i < ReadOnlyRoots::kEntriesCount; i++) {
407
+ RootIndex rudi = static_cast<RootIndex>(i);
408
+ Tagged<HeapObject> rudolf = Cast<HeapObject>(roots.object_at(rudi));
409
+ ro::EncodedTagged encoded = Encode(isolate_, rudolf);
410
+ sink_->PutUint32(encoded.ToUint32(), "read only roots entry");
411
+ + #ifdef PKG_TRACE_READONLY_HEAP
412
+ + Tagged<Map> map = rudolf->map(isolate_);
413
+ + InstanceType instance_type = map->instance_type();
414
+ + PrintF(" [PKGTRACE] readonly root i=%zu e=%x s=%d t=%d\n",
415
+ + i, encoded.ToUint32(), rudolf->Size(), instance_type);
416
+ + #endif
417
+ }
418
+ }
419
+ }
420
+ diff --git node/lib/child_process.js node/lib/child_process.js
421
+ index 17c6b69c11..59f5e241af 100644
422
+ --- node/lib/child_process.js
423
+ +++ node/lib/child_process.js
424
+ @@ -171,7 +171,7 @@ function fork(modulePath, args = [], options) {
425
+ throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
426
+ }
427
+
428
+ - return spawn(options.execPath, args, options);
429
+ + return module.exports.spawn(options.execPath, args, options);
430
+ }
431
+
432
+ function _forkChild(fd, serializationMode) {
433
+ diff --git node/lib/internal/bootstrap/pkg.js node/lib/internal/bootstrap/pkg.js
434
+ new file mode 100644
435
+ index 0000000000..a697294fdf
436
+ --- /dev/null
437
+ +++ node/lib/internal/bootstrap/pkg.js
438
+ @@ -0,0 +1,49 @@
439
+ +'use strict';
440
+ +
441
+ +const {
442
+ + prepareWorkerThreadExecution,
443
+ + prepareMainThreadExecution
444
+ +} = require('internal/process/pre_execution');
445
+ +
446
+ +if (internalBinding('worker').isMainThread) {
447
+ + prepareMainThreadExecution(true);
448
+ +} else {
449
+ + prepareWorkerThreadExecution();
450
+ +}
451
+ +
452
+ +(function () {
453
+ + var __require__ = require;
454
+ + var fs = __require__('fs');
455
+ + var vm = __require__('vm');
456
+ + function readPrelude (fd) {
457
+ + var PAYLOAD_POSITION = '// PAYLOAD_POSITION //' | 0;
458
+ + var PAYLOAD_SIZE = '// PAYLOAD_SIZE //' | 0;
459
+ + var PRELUDE_POSITION = '// PRELUDE_POSITION //' | 0;
460
+ + var PRELUDE_SIZE = '// PRELUDE_SIZE //' | 0;
461
+ + if (!PRELUDE_POSITION) {
462
+ + // no prelude - remove entrypoint from argv[1]
463
+ + process.argv.splice(1, 1);
464
+ + return { undoPatch: true };
465
+ + }
466
+ + var prelude = Buffer.alloc(PRELUDE_SIZE);
467
+ + var read = fs.readSync(fd, prelude, 0, PRELUDE_SIZE, PRELUDE_POSITION);
468
+ + if (read !== PRELUDE_SIZE) {
469
+ + console.error('Pkg: Error reading from file.');
470
+ + process.exit(1);
471
+ + }
472
+ + var s = new vm.Script(prelude, { filename: 'pkg/prelude/bootstrap.js' });
473
+ + var fn = s.runInThisContext();
474
+ + return fn(process, __require__,
475
+ + console, fd, PAYLOAD_POSITION, PAYLOAD_SIZE);
476
+ + }
477
+ + (function () {
478
+ + var fd = fs.openSync(process.execPath, 'r');
479
+ + var result = readPrelude(fd);
480
+ + if (result && result.undoPatch) {
481
+ + var bindingFs = process.binding('fs');
482
+ + fs.internalModuleStat = bindingFs.internalModuleStat;
483
+ + fs.internalModuleReadJSON = bindingFs.internalModuleReadJSON;
484
+ + fs.closeSync(fd);
485
+ + }
486
+ + }());
487
+ +}());
488
+ diff --git node/lib/internal/modules/cjs/loader.js node/lib/internal/modules/cjs/loader.js
489
+ index df656b8601..a49a1025a4 100644
490
+ --- node/lib/internal/modules/cjs/loader.js
491
+ +++ node/lib/internal/modules/cjs/loader.js
492
+ @@ -267,12 +267,15 @@ function stat(filename) {
493
+ // Guard against internal bugs where a non-string filename is passed in by mistake.
494
+ assert(typeof filename === 'string');
495
+
496
+ + const origFilename = filename;
497
+ filename = path.toNamespacedPath(filename);
498
+ if (statCache !== null) {
499
+ const result = statCache.get(filename);
500
+ if (result !== undefined) { return result; }
501
+ }
502
+ - const result = internalFsBinding.internalModuleStat(filename);
503
+ + const fs = require('fs');
504
+ + const result = fs.existsSync(origFilename) ?
505
+ + (fs.statSync(origFilename).isDirectory() ? 1 : 0) : -1;
506
+ if (statCache !== null && result >= 0) {
507
+ // Only set cache when `internalModuleStat(filename)` succeeds.
508
+ statCache.set(filename, result);
509
+ diff --git node/lib/internal/modules/package_json_reader.js node/lib/internal/modules/package_json_reader.js
510
+ index 968c3c5701..1c7b01a3f2 100644
511
+ --- node/lib/internal/modules/package_json_reader.js
512
+ +++ node/lib/internal/modules/package_json_reader.js
513
+ @@ -120,17 +120,20 @@ const requiresJSONParse = (value) => (value !== undefined && (value[0] === '[' |
514
+ * @returns {PackageConfig}
515
+ */
516
+ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) {
517
+ - // This function will be called by both CJS and ESM, so we need to make sure
518
+ - // non-null attributes are converted to strings.
519
+ - const parsed = modulesBinding.readPackageJSON(
520
+ - jsonPath,
521
+ - isESM,
522
+ - base == null ? undefined : `${base}`,
523
+ - specifier == null ? undefined : `${specifier}`,
524
+ - );
525
+ -
526
+ - const result = deserializePackageJSON(jsonPath, parsed);
527
+ -
528
+ + const fs = require('fs');
529
+ + let result;
530
+ + if (fs.existsSync(jsonPath)) {
531
+ + const json = JSONParse(fs.readFileSync(jsonPath, { encoding: "utf8" }).trim());
532
+ + result = deserializePackageJSON(jsonPath, [
533
+ + json['name'],
534
+ + json['main'],
535
+ + json['type'],
536
+ + json['imports'],
537
+ + json['exports'],
538
+ + ]);
539
+ + } else {
540
+ + result = deserializePackageJSON(jsonPath, undefined);
541
+ + }
542
+ return {
543
+ __proto__: null,
544
+ ...result.data,
545
+ diff --git node/lib/internal/process/pre_execution.js node/lib/internal/process/pre_execution.js
546
+ index e9ab2b2a89..6c74e7cc64 100644
547
+ --- node/lib/internal/process/pre_execution.js
548
+ +++ node/lib/internal/process/pre_execution.js
549
+ @@ -42,7 +42,11 @@ const {
550
+ runDeserializeCallbacks,
551
+ } = require('internal/v8/startup_snapshot');
552
+
553
+ +let _alreadyPrepared = false;
554
+ +
555
+ function prepareMainThreadExecution(expandArgv1 = false, initializeModules = true) {
556
+ + if (_alreadyPrepared === true) return;
557
+ + _alreadyPrepared = true;
558
+ return prepareExecution({
559
+ expandArgv1,
560
+ initializeModules,
561
+ @@ -279,7 +283,8 @@ function patchProcessObject(expandArgv1) {
562
+ let mainEntry;
563
+ // If requested, update process.argv[1] to replace whatever the user provided with the resolved absolute file path of
564
+ // the entry point.
565
+ - if (expandArgv1 && process.argv[1] && process.argv[1][0] !== '-') {
566
+ + if (expandArgv1 && process.argv[1] && process.argv[1][0] !== '-' &&
567
+ + process.argv[1] !== 'PKG_DUMMY_ENTRYPOINT') {
568
+ // Expand process.argv[1] into a full path.
569
+ const path = require('path');
570
+ try {
571
+ @@ -703,6 +708,7 @@ function loadPreloadModules() {
572
+ // For user code, we preload modules if `-r` is passed
573
+ const preloadModules = getOptionValue('--require');
574
+ if (preloadModules && preloadModules.length > 0) {
575
+ + assert(false, '--require is not supported');
576
+ const {
577
+ Module: {
578
+ _preloadModules,
579
+ diff --git node/lib/vm.js node/lib/vm.js
580
+ index ae71080620..b05638de75 100644
581
+ --- node/lib/vm.js
582
+ +++ node/lib/vm.js
583
+ @@ -98,6 +98,7 @@ class Script extends ContextifyScript {
584
+ produceCachedData = false,
585
+ importModuleDynamically,
586
+ [kParsingContext]: parsingContext,
587
+ + sourceless = false,
588
+ } = options;
589
+
590
+ validateString(filename, 'options.filename');
591
+ @@ -121,7 +122,8 @@ class Script extends ContextifyScript {
592
+ cachedData,
593
+ produceCachedData,
594
+ parsingContext,
595
+ - hostDefinedOptionId);
596
+ + hostDefinedOptionId,
597
+ + sourceless);
598
+ } catch (e) {
599
+ throw e; /* node-do-not-add-exception-line */
600
+ }
601
+ diff --git node/src/inspector_agent.cc node/src/inspector_agent.cc
602
+ index f62eb36b57..8ccc42dbd4 100644
603
+ --- node/src/inspector_agent.cc
604
+ +++ node/src/inspector_agent.cc
605
+ @@ -833,11 +833,6 @@ bool Agent::Start(const std::string& path,
606
+ StartIoThreadAsyncCallback));
607
+ uv_unref(reinterpret_cast<uv_handle_t*>(&start_io_thread_async));
608
+ start_io_thread_async.data = this;
609
+ - if (parent_env_->should_start_debug_signal_handler()) {
610
+ - // Ignore failure, SIGUSR1 won't work, but that should not block node
611
+ - // start.
612
+ - StartDebugSignalHandler();
613
+ - }
614
+
615
+ parent_env_->AddCleanupHook([](void* data) {
616
+ Environment* env = static_cast<Environment*>(data);
617
+ diff --git node/src/node.cc node/src/node.cc
618
+ index 0bc086ccd1..9a76ce03cc 100644
619
+ --- node/src/node.cc
620
+ +++ node/src/node.cc
621
+ @@ -351,6 +351,8 @@ MaybeLocal<Value> StartExecution(Environment* env,
622
+ return env->RunSnapshotDeserializeMain();
623
+ }
624
+
625
+ + StartExecution(env, "internal/bootstrap/pkg");
626
+ +
627
+ if (env->worker_context() != nullptr) {
628
+ return StartExecution(env, "internal/main/worker_thread");
629
+ }
630
+ @@ -575,14 +577,6 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
631
+ }
632
+
633
+ if (!(flags & ProcessInitializationFlags::kNoDefaultSignalHandling)) {
634
+ -#if HAVE_INSPECTOR
635
+ - sigset_t sigmask;
636
+ - sigemptyset(&sigmask);
637
+ - sigaddset(&sigmask, SIGUSR1);
638
+ - const int err = pthread_sigmask(SIG_SETMASK, &sigmask, nullptr);
639
+ - CHECK_EQ(err, 0);
640
+ -#endif // HAVE_INSPECTOR
641
+ -
642
+ ResetSignalHandlers();
643
+ }
644
+
645
+ diff --git node/src/node_contextify.cc node/src/node_contextify.cc
646
+ index d3568da72a..e01d00067a 100644
647
+ --- node/src/node_contextify.cc
648
+ +++ node/src/node_contextify.cc
649
+ @@ -87,6 +87,7 @@ using v8::String;
650
+ using v8::Symbol;
651
+ using v8::UnboundScript;
652
+ using v8::Value;
653
+ +using v8::V8;
654
+
655
+ // The vm module executes code in a sandboxed environment with a different
656
+ // global object than the rest of the code. This is achieved by applying
657
+ @@ -970,13 +971,13 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
658
+ Local<ArrayBufferView> cached_data_buf;
659
+ bool produce_cached_data = false;
660
+ Local<Context> parsing_context = context;
661
+ -
662
+ + bool sourceless = false;
663
+ Local<Symbol> id_symbol;
664
+ if (argc > 2) {
665
+ // new ContextifyScript(code, filename, lineOffset, columnOffset,
666
+ // cachedData, produceCachedData, parsingContext,
667
+ - // hostDefinedOptionId)
668
+ - CHECK_EQ(argc, 8);
669
+ + // hostDefinedOptionId, sourceless)
670
+ + CHECK_GE(argc, 8);
671
+ CHECK(args[2]->IsNumber());
672
+ line_offset = args[2].As<Int32>()->Value();
673
+ CHECK(args[3]->IsNumber());
674
+ @@ -997,6 +998,11 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
675
+ }
676
+ CHECK(args[7]->IsSymbol());
677
+ id_symbol = args[7].As<Symbol>();
678
+ +
679
+ + if (argc > 8) {
680
+ + CHECK(args[8]->IsBoolean());
681
+ + sourceless = args[8]->IsTrue();
682
+ + }
683
+ }
684
+
685
+ ContextifyScript* contextify_script = New(env, args.This());
686
+ @@ -1043,6 +1049,10 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
687
+ ShouldNotAbortOnUncaughtScope no_abort_scope(env);
688
+ Context::Scope scope(parsing_context);
689
+
690
+ + if (sourceless && produce_cached_data) {
691
+ + V8::EnableCompilationForSourcelessUse();
692
+ + }
693
+ +
694
+ MaybeLocal<UnboundScript> maybe_v8_script =
695
+ ScriptCompiler::CompileUnboundScript(isolate, &source, compile_options);
696
+
697
+ @@ -1057,6 +1067,12 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
698
+ return;
699
+ }
700
+
701
+ + if (sourceless && compile_options == ScriptCompiler::kConsumeCodeCache) {
702
+ + if (!source.GetCachedData()->rejected) {
703
+ + V8::FixSourcelessScript(env->isolate(), v8_script);
704
+ + }
705
+ + }
706
+ +
707
+ contextify_script->set_unbound_script(v8_script);
708
+
709
+ std::unique_ptr<ScriptCompiler::CachedData> new_cached_data;
710
+ @@ -1069,7 +1085,7 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
711
+ if (contextify_script->object()
712
+ ->SetPrivate(context, env->host_defined_option_symbol(), id_symbol)
713
+ .IsNothing()) {
714
+ - return;
715
+ +return;
716
+ }
717
+ if (StoreCodeCacheResult(env,
718
+ self,
719
+ @@ -1080,6 +1096,9 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
720
+ .IsNothing()) {
721
+ return;
722
+ }
723
+ + if (sourceless && produce_cached_data) {
724
+ + V8::DisableCompilationForSourcelessUse();
725
+ + }
726
+ if (self->Set(env->context(),
727
+ env->source_url_string(),
728
+ v8_script->GetSourceURL())
729
+ diff --git node/src/node_main.cc node/src/node_main.cc
730
+ index 3295121b87..bfe838b8c1 100644
731
+ --- node/src/node_main.cc
732
+ +++ node/src/node_main.cc
733
+ @@ -22,6 +22,8 @@
734
+ #include "node.h"
735
+ #include <cstdio>
736
+
737
+ +int reorder(int argc, char** argv);
738
+ +
739
+ #ifdef _WIN32
740
+ #include <windows.h>
741
+ #include <VersionHelpers.h>
742
+ @@ -88,12 +90,95 @@ int wmain(int argc, wchar_t* wargv[]) {
743
+ }
744
+ argv[argc] = nullptr;
745
+ // Now that conversion is done, we can finally start.
746
+ - return node::Start(argc, argv);
747
+ + return reorder(argc, argv);
748
+ }
749
+ #else
750
+ // UNIX
751
+
752
+ int main(int argc, char* argv[]) {
753
+ + return reorder(argc, argv);
754
+ +}
755
+ +#endif
756
+ +
757
+ +#include <string.h>
758
+ +
759
+ +int strlen2 (char* s) {
760
+ + int len = 0;
761
+ + while (*s) {
762
+ + len += 1;
763
+ + s += 1;
764
+ + }
765
+ + return len;
766
+ +}
767
+ +
768
+ +bool should_set_dummy() {
769
+ +#ifdef _WIN32
770
+ + #define MAX_ENV_LENGTH 32767
771
+ + wchar_t execpath_env[MAX_ENV_LENGTH];
772
+ + DWORD result = GetEnvironmentVariableW(L"PKG_EXECPATH", execpath_env, MAX_ENV_LENGTH);
773
+ + if (result == 0 && GetLastError() != ERROR_SUCCESS) return true;
774
+ + return wcscmp(execpath_env, L"PKG_INVOKE_NODEJS") != 0;
775
+ +#else
776
+ + const char* execpath_env = getenv("PKG_EXECPATH");
777
+ + if (!execpath_env) return true;
778
+ + return strcmp(execpath_env, "PKG_INVOKE_NODEJS") != 0;
779
+ +#endif
780
+ +}
781
+ +
782
+ +// for uv_setup_args
783
+ +int adjacent(int argc, char** argv) {
784
+ + size_t size = 0;
785
+ + for (int i = 0; i < argc; i++) {
786
+ + size += strlen(argv[i]) + 1;
787
+ + }
788
+ + char* args = new char[size];
789
+ + size_t pos = 0;
790
+ + for (int i = 0; i < argc; i++) {
791
+ + memcpy(&args[pos], argv[i], strlen(argv[i]) + 1);
792
+ + argv[i] = &args[pos];
793
+ + pos += strlen(argv[i]) + 1;
794
+ + }
795
+ return node::Start(argc, argv);
796
+ }
797
+ +
798
+ +volatile char* BAKERY = (volatile char*) "\0// BAKERY // BAKERY " \
799
+ + "// BAKERY // BAKERY // BAKERY // BAKERY // BAKERY // BAKERY " \
800
+ + "// BAKERY // BAKERY // BAKERY // BAKERY // BAKERY // BAKERY " \
801
+ + "// BAKERY // BAKERY // BAKERY // BAKERY // BAKERY // BAKERY ";
802
+ +
803
+ +#ifdef __clang__
804
+ +__attribute__((optnone))
805
+ +#elif defined(__GNUC__)
806
+ +__attribute__((optimize(0)))
807
+ #endif
808
+ +
809
+ +int load_baked(char** nargv) {
810
+ + int c = 1;
811
+ +
812
+ + char* bakery = (char*) BAKERY;
813
+ + while (true) {
814
+ + size_t width = strlen2(bakery);
815
+ + if (width == 0) break;
816
+ + nargv[c++] = bakery;
817
+ + bakery += width + 1;
818
+ + }
819
+ +
820
+ + return c;
821
+ +}
822
+ +
823
+ +int reorder(int argc, char** argv) {
824
+ + char** nargv = new char*[argc + 64];
825
+ +
826
+ + nargv[0] = argv[0];
827
+ + int c = load_baked(nargv);
828
+ +
829
+ + if (should_set_dummy()) {
830
+ + nargv[c++] = (char*) "PKG_DUMMY_ENTRYPOINT";
831
+ + }
832
+ +
833
+ + for (int i = 1; i < argc; i++) {
834
+ + nargv[c++] = argv[i];
835
+ + }
836
+ +
837
+ + return adjacent(c, nargv);
838
+ +}
839
+ diff --git node/src/node_options.cc node/src/node_options.cc
840
+ index 79d7c8cac0..11e2a8a746 100644
841
+ --- node/src/node_options.cc
842
+ +++ node/src/node_options.cc
843
+ @@ -430,6 +430,7 @@ void Parse(
844
+ // TODO(addaleax): Make that unnecessary.
845
+
846
+ DebugOptionsParser::DebugOptionsParser() {
847
+ + return;
848
+ AddOption("--inspect-port",
849
+ "set host:port for inspector",
850
+ &DebugOptions::host_port,
851
+ diff --git node/tools/icu/icu-generic.gyp node/tools/icu/icu-generic.gyp
852
+ index f007c65232..002a00a6ae 100644
853
+ --- node/tools/icu/icu-generic.gyp
854
+ +++ node/tools/icu/icu-generic.gyp
855
+ @@ -52,7 +52,7 @@
856
+ 'conditions': [
857
+ [ 'os_posix == 1 and OS != "mac" and OS != "ios"', {
858
+ 'cflags': [ '-Wno-deprecated-declarations', '-Wno-strict-aliasing' ],
859
+ - 'cflags_cc': [ '-frtti' ],
860
+ + 'cflags_cc': [ '-frtti', '-fno-lto' ],
861
+ 'cflags_cc!': [ '-fno-rtti' ],
862
+ }],
863
+ [ 'OS == "mac" or OS == "ios"', {