-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinspect.js
8351 lines (7439 loc) · 247 KB
/
inspect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
primordials = {};
'use strict';
/* eslint-disable no-restricted-globals */
// This file subclasses and stores the JS builtins that come from the VM
// so that Node.js's builtin modules do not need to later look these up from
// the global proxy, which can be mutated by users.
// TODO(joyeecheung): we can restrict access to these globals in builtin
// modules through the JS linter, for example: ban access such as `Object`
// (which falls back to a lookup in the global proxy) in favor of
// `primordials.Object` where `primordials` is a lexical variable passed
// by the native module compiler.
const ReflectApply = Reflect.apply;
// This function is borrowed from the function with the same name on V8 Extras'
// `utils` object. V8 implements Reflect.apply very efficiently in conjunction
// with the spread syntax, such that no additional special case is needed for
// function calls w/o arguments.
// Refs: https://github.com/v8/v8/blob/d6ead37d265d7215cf9c5f768f279e21bd170212/src/js/prologue.js#L152-L156
function uncurryThis(func) {
return (thisArg, ...args) => ReflectApply(func, thisArg, args);
}
primordials.uncurryThis = uncurryThis;
function copyProps(src, dest) {
for (const key of Reflect.ownKeys(src)) {
if (!Reflect.getOwnPropertyDescriptor(dest, key)) {
Reflect.defineProperty(
dest,
key,
Reflect.getOwnPropertyDescriptor(src, key));
}
}
}
function copyPropsRenamed(src, dest, prefix) {
for (const key of Reflect.ownKeys(src)) {
if (typeof key === 'string') {
Reflect.defineProperty(
dest,
`${prefix}${key[0].toUpperCase()}${key.slice(1)}`,
Reflect.getOwnPropertyDescriptor(src, key));
}
}
}
function copyPropsRenamedBound(src, dest, prefix) {
for (const key of Reflect.ownKeys(src)) {
if (typeof key === 'string') {
const desc = Reflect.getOwnPropertyDescriptor(src, key);
if (typeof desc.value === 'function') {
desc.value = desc.value.bind(src);
}
Reflect.defineProperty(
dest,
`${prefix}${key[0].toUpperCase()}${key.slice(1)}`,
desc
);
}
}
}
function copyPrototype(src, dest, prefix) {
for (const key of Reflect.ownKeys(src)) {
if (typeof key === 'string') {
const desc = Reflect.getOwnPropertyDescriptor(src, key);
if (typeof desc.value === 'function') {
desc.value = uncurryThis(desc.value);
}
Reflect.defineProperty(
dest,
`${prefix}${key[0].toUpperCase()}${key.slice(1)}`,
desc);
}
}
}
function makeSafe(unsafe, safe) {
copyProps(unsafe.prototype, safe.prototype);
copyProps(unsafe, safe);
Object.setPrototypeOf(safe.prototype, null);
Object.freeze(safe.prototype);
Object.freeze(safe);
return safe;
}
// Subclass the constructors because we need to use their prototype
// methods later.
primordials.SafeMap = makeSafe(
Map,
class SafeMap extends Map {}
);
primordials.SafeWeakMap = makeSafe(
WeakMap,
class SafeWeakMap extends WeakMap {}
);
primordials.SafeSet = makeSafe(
Set,
class SafeSet extends Set {}
);
primordials.SafePromise = makeSafe(
Promise,
class SafePromise extends Promise {}
);
// Create copies of the namespace objects
[
'JSON',
'Math',
'Reflect'
].forEach((name) => {
copyPropsRenamed(global[name], primordials, name);
});
// Create copies of intrinsic objects
[
'Array',
'ArrayBuffer',
'BigInt',
'BigInt64Array',
'BigUint64Array',
'Boolean',
'Date',
'Error',
'Float32Array',
'Float64Array',
'Function',
'Int16Array',
'Int32Array',
'Int8Array',
'Map',
'Number',
'Object',
'RegExp',
'Set',
'String',
'Symbol',
'Uint16Array',
'Uint32Array',
'Uint8Array',
'Uint8ClampedArray',
'WeakMap',
'WeakSet',
].forEach((name) => {
const original = global[name];
primordials[name] = original;
copyPropsRenamed(original, primordials, name);
copyPrototype(original.prototype, primordials, `${name}Prototype`);
});
// Create copies of intrinsic objects that require a valid `this` to call
// static methods.
// Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all
[
'Promise',
].forEach((name) => {
const original = global[name];
primordials[name] = original;
copyPropsRenamedBound(original, primordials, name);
copyPrototype(original.prototype, primordials, `${name}Prototype`);
});
Object.setPrototypeOf(primordials, null);
Object.freeze(primordials);
;
// eslint-disable-next-line no-unused-vars
function internalBinding(name) {
function objectToString(o) {
return Object.prototype.toString.call(o);
}
const isExternal = function isExternal() {};
const isDate = function isDate(d) {
return objectToString(d) === '[object Date]' && d instanceof Date;
};
const isArgumentsObject = function isArgumentsObject(a) {
return objectToString(a) === '[object Arguments]';
};
const isBooleanObject = function isBooleanObject(b) {
return objectToString(b) === '[object Boolean]' && b instanceof Boolean;
};
const isNumberObject = function isNumberObject(n) {
return objectToString(n) === '[object Number]' && n instanceof Number;
};
const isStringObject = function isStringObject(s) {
return objectToString(s) === '[object String]' && s instanceof String;
};
const isSymbolObject = function isSymbolObject(s) {
return objectToString(s) === '[object Symbol]' && s instanceof Symbol;
};
const isNativeError = function isNativeError(e) {
return objectToString(e) === '[object Error]' && e instanceof Error;
};
const isRegExp = function isRegExp(r) {
return objectToString(r) === '[object RegExp]' && r instanceof RegExp;
};
const isAsyncFunction = function isAsyncFunction(a) {
return objectToString(a) === '[object AsyncFunction]';
};
const isGeneratorFunction = function isGeneratorFunction(g) {
return objectToString(g) === '[object GeneratorFunction]';
};
const isGeneratorObject = function isGeneratorObject(g) {
return objectToString(g) === '[object Generator]';
};
const isPromise = function isPromise(p) {
return objectToString(p) === '[object Promise]';
};
const isMap = function isMap(m) {
return objectToString(m) === '[object Map]' && m instanceof Map;
};
const isSet = function isSet(s) {
return objectToString(s) === '[object Set]' && s instanceof Set;
};
const isMapIterator = function isMapIterator(m) {
return objectToString(m) === '[object Map Iterator]';
};
const isSetIterator = function isSetIterator(s) {
return objectToString(s) === '[object Set Iterator]';
};
const isWeakMap = function isWeakMap(w) {
return objectToString(w) === '[object WeakMap]';
};
const isWeakSet = function isWeakSet(w) {
return objectToString(w) === '[object WeakSet]';
};
const isArrayBuffer = function isArrayBuffer(a) {
return objectToString(a) === '[object ArrayBuffer]' && a instanceof ArrayBuffer;
};
const isDataView = function isDataView(d) {
return objectToString(d) === '[object DataView]' && d instanceof DataView;
};
const isSharedArrayBuffer = function isSharedArrayBuffer(s) {
return objectToString(s) === '[object SharedArrayBuffer]' && s instanceof SharedArrayBuffer;
};
// Without hooking in v8 anymore we can't tell proxies from plain
// objects, and it is by spec.
// Some browsers allow `x instanceof Proxy` to work
// but different engines behaves unpredictably: some would throw an
// error some just always return `false`.
const isProxy = function isProxy() { return false; };
const isWebAssemblyCompiledModule = function isWebAssemblyCompiledModule(w) {
return objectToString(w) === '[object WebAssembly.Module]';
};
const isModuleNamespaceObject = function isModuleNamespaceObject() {};
const isAnyArrayBuffer = function isAnyArrayBuffer() {};
// dataView, int32Array, uint8Array, buffer,
// stealthyDataView, stealthyInt32Array, stealthyUint8Array
const isArrayBufferView = function isArrayBufferView() {};
// int32Array, uint8Array, buffer, stealthyInt32Array, stealthyUint8Array
// see https://github.com/lodash/lodash/blob/master/isTypedArray.js
const isTypedArray = function isTypedArray(t) {
const tags = /^\[object (?:Float(?:32|64)Array|(?:Int|Uint)(?:8|16|32)Array|Uint8ClampedArray)\]$/;
return tags.test(objectToString(t));
};
const isUint8Array = function isUint8Array(u) {
return objectToString(u) === '[object Uint8Array]' && u instanceof Uint8Array;
};
const isUint8ClampedArray = function isUint8ClampedArray(u) {
return objectToString(u) === '[object Uint8ClampedArray]' && u instanceof Uint8ClampedArray;
};
const isUint16Array = function isUint16Array(u) {
return objectToString(u) === '[object Uint16Array]' && u instanceof Uint16Array;
};
const isUint32Array = function isUint32Array(u) {
return objectToString(u) === '[object Uint32Array]' && u instanceof Uint32Array;
};
const isInt8Array = function isInt8Array(i) {
return objectToString(i) === '[object Int8Array]' && i instanceof Int8Array;
};
const isInt16Array = function isInt16Array(i) {
return objectToString(i) === '[object Int16Array]' && i instanceof Int16Array;
};
const isInt32Array = function isInt32Array(i) {
return objectToString(i) === '[object Int32Array]' && i instanceof Int32Array;
};
const isFloat32Array = function isFloat32Array(i) {
return objectToString(i) === '[object Float32Array]' && i instanceof Float32Array;
};
const isFloat64Array = function isFloat64Array(i) {
return objectToString(i) === '[object Float64Array]' && i instanceof Float64Array;
};
const isBigInt64Array = function isBigInt64Array(i) {
return objectToString(i) === '[object Float64Array]' && i instanceof Float64Array;
};
const isBigIntObject = function isBigIntObject(i) {
// note: this was experimental since recently
// eslint-disable-next-line node/no-unsupported-features/es-builtins
if (typeof BigInt === 'function') {
// eslint-disable-next-line node/no-unsupported-features/es-builtins
return objectToString(i) === '[object BigInt]' && i instanceof BigInt;
}
};
const isBigUint64Array = function isBigUint64Array(i) {
// note: this was experimental since recently
// eslint-disable-next-line node/no-unsupported-features/es-builtins
if (typeof BigUint64Array === 'function') {
// eslint-disable-next-line node/no-unsupported-features/es-builtins
return objectToString(i) === '[object BigUint64Array]' && i instanceof BigUint64Array;
}
return false;
};
// TODO: support isBoxedPrimitive
const isBoxedPrimitive = function isBoxedPrimitive() {
return false;
};
if (name === 'buffer') {
return require('buffer');
}
if (name === 'util') {
const kPending = 0;
const kRejected = 1;
const getPromiseDetails = () => {
return [kPending, undefined];
};
const ALL_PROPERTIES = 0;
const ONLY_ENUMERABLE = 1;
const IS_NUMERIC_RE = /^\d$/;
const getOwnNonIndexProperties = (array, filter) => {
const keys = filter === ALL_PROPERTIES ?
Object.getOwnPropertyNames(array) :
Object.keys(array);
return keys.filter((k) => !k.match(IS_NUMERIC_RE));
};
return {
propertyFilter: {
ALL_PROPERTIES,
ONLY_ENUMERABLE
},
getOwnNonIndexProperties,
kPending,
kRejected,
getPromiseDetails,
// since we can't reliably detect a Proxy
// in the browser we just ignore them
getProxyDetails: () => undefined,
// This is only used in case max depth
// has been reached.
//
// In such case we fallback to Object
getConstructorName: () => 'Object',
// TODO ?
previewEntries: () => []
};
}
if (name === 'constants') {
return {
os: {
signals: {},
},
};
}
if (name === 'types') {
return {
isExternal,
isDate,
isArgumentsObject,
isBooleanObject,
isNumberObject,
isStringObject,
isSymbolObject,
isNativeError,
isRegExp,
isAsyncFunction,
isGeneratorFunction,
isGeneratorObject,
isPromise,
isMap,
isSet,
isMapIterator,
isSetIterator,
isWeakMap,
isWeakSet,
isArrayBuffer,
isDataView,
isSharedArrayBuffer,
isProxy,
isWebAssemblyCompiledModule,
isModuleNamespaceObject,
isAnyArrayBuffer,
isArrayBufferView,
isTypedArray,
isUint8Array,
isUint8ClampedArray,
isUint16Array,
isUint32Array,
isInt8Array,
isInt16Array,
isInt32Array,
isFloat32Array,
isFloat64Array,
isBigInt64Array,
isBigUint64Array,
isBoxedPrimitive,
isBigIntObject
};
}
if (name === 'config') {
return {
hasIntl: false,
};
}
if (name === 'native_module') {
return {
moduleIds: []
};
}
throw new Error('binding not found: ' + name);
}
// eslint-disable-next-line no-undef
getInternalBinding = internalBinding;
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.browserifiedUtilInspect = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';
let error;
function lazyError() {
if (!error) {
error = require('internal/errors').codes.ERR_INTERNAL_ASSERTION;
}
return error;
}
function assert(value, message) {
if (!value) {
const ERR_INTERNAL_ASSERTION = lazyError();
throw new ERR_INTERNAL_ASSERTION(message);
}
}
function fail(message) {
const ERR_INTERNAL_ASSERTION = lazyError();
throw new ERR_INTERNAL_ASSERTION(message);
}
assert.fail = fail;
module.exports = assert;
},{"internal/errors":3}],2:[function(require,module,exports){
(function (process){
// This file creates the internal module & binding loaders used by built-in
// modules. In contrast, user land modules are loaded using
// lib/internal/modules/cjs/loader.js (CommonJS Modules) or
// lib/internal/modules/esm/* (ES Modules).
//
// This file is compiled and run by node.cc before bootstrap/node.js
// was called, therefore the loaders are bootstraped before we start to
// actually bootstrap Node.js. It creates the following objects:
//
// C++ binding loaders:
// - process.binding(): the legacy C++ binding loader, accessible from user land
// because it is an object attached to the global process object.
// These C++ bindings are created using NODE_BUILTIN_MODULE_CONTEXT_AWARE()
// and have their nm_flags set to NM_F_BUILTIN. We do not make any guarantees
// about the stability of these bindings, but still have to take care of
// compatibility issues caused by them from time to time.
// - process._linkedBinding(): intended to be used by embedders to add
// additional C++ bindings in their applications. These C++ bindings
// can be created using NODE_MODULE_CONTEXT_AWARE_CPP() with the flag
// NM_F_LINKED.
// - internalBinding(): the private internal C++ binding loader, inaccessible
// from user land unless through `require('internal/test/binding')`.
// These C++ bindings are created using NODE_MODULE_CONTEXT_AWARE_INTERNAL()
// and have their nm_flags set to NM_F_INTERNAL.
//
// Internal JavaScript module loader:
// - NativeModule: a minimal module system used to load the JavaScript core
// modules found in lib/**/*.js and deps/**/*.js. All core modules are
// compiled into the node binary via node_javascript.cc generated by js2c.py,
// so they can be loaded faster without the cost of I/O. This class makes the
// lib/internal/*, deps/internal/* modules and internalBinding() available by
// default to core modules, and lets the core modules require itself via
// require('internal/bootstrap/loaders') even when this file is not written in
// CommonJS style.
//
// Other objects:
// - process.moduleLoadList: an array recording the bindings and the modules
// loaded in the process and the order in which they are loaded.
'use strict';
// This file is compiled as if it's wrapped in a function with arguments
// passed by node::RunBootstrapping()
/* global process, getLinkedBinding, getInternalBinding, primordials */
const {
Error,
Map,
ObjectCreate,
ObjectDefineProperty,
ObjectKeys,
ObjectPrototypeHasOwnProperty,
ReflectGet,
SafeSet,
} = primordials;
// Set up process.moduleLoadList.
const moduleLoadList = [];
ObjectDefineProperty(process, 'moduleLoadList', {
value: moduleLoadList,
configurable: true,
enumerable: true,
writable: false
});
// internalBindingWhitelist contains the name of internalBinding modules
// that are whitelisted for access via process.binding()... This is used
// to provide a transition path for modules that are being moved over to
// internalBinding.
const internalBindingWhitelist = new SafeSet([
'async_wrap',
'buffer',
'cares_wrap',
'config',
'constants',
'contextify',
'crypto',
'fs',
'fs_event_wrap',
'http_parser',
'http_parser_llhttp',
'icu',
'inspector',
'js_stream',
'natives',
'os',
'pipe_wrap',
'process_wrap',
'signal_wrap',
'spawn_sync',
'stream_wrap',
'tcp_wrap',
'tls_wrap',
'tty_wrap',
'udp_wrap',
'url',
'util',
'uv',
'v8',
'zlib'
]);
// Set up process.binding() and process._linkedBinding().
{
const bindingObj = ObjectCreate(null);
process.binding = function binding(module) {
module = String(module);
// Deprecated specific process.binding() modules, but not all, allow
// selective fallback to internalBinding for the deprecated ones.
if (internalBindingWhitelist.has(module)) {
return internalBinding(module);
}
// eslint-disable-next-line no-restricted-syntax
throw new Error(`No such module: ${module}`);
};
process._linkedBinding = function _linkedBinding(module) {
module = String(module);
let mod = bindingObj[module];
if (typeof mod !== 'object')
mod = bindingObj[module] = getLinkedBinding(module);
return mod;
};
}
// Set up internalBinding() in the closure.
let internalBinding;
{
const bindingObj = ObjectCreate(null);
// eslint-disable-next-line no-global-assign
internalBinding = function internalBinding(module) {
let mod = bindingObj[module];
if (typeof mod !== 'object') {
mod = bindingObj[module] = getInternalBinding(module);
moduleLoadList.push(`Internal Binding ${module}`);
}
return mod;
};
}
const loaderId = 'internal/bootstrap/loaders';
const {
moduleIds,
compileFunction
} = internalBinding('native_module');
const getOwn = (target, property, receiver) => {
return ObjectPrototypeHasOwnProperty(target, property) ?
ReflectGet(target, property, receiver) :
undefined;
};
/**
* An internal abstraction for the built-in JavaScript modules of Node.js.
* Be careful not to expose this to user land unless --expose-internals is
* used, in which case there is no compatibility guarantee about this class.
*/
class NativeModule {
/**
* A map from the module IDs to the module instances.
* @type {Map<string, NativeModule>}
*/
static map = new Map(moduleIds.map((id) => [id, new NativeModule(id)]));
constructor(id) {
this.filename = `${id}.js`;
this.id = id;
this.canBeRequiredByUsers = !id.startsWith('internal/');
// The CJS exports object of the module.
this.exports = {};
// States used to work around circular dependencies.
this.loaded = false;
this.loading = false;
// The following properties are used by the ESM implementation and only
// initialized when the native module is loaded by users.
/**
* The C++ ModuleWrap binding used to interface with the ESM implementation.
* @type {ModuleWrap|undefined}
*/
this.module = undefined;
/**
* Exported names for the ESM imports.
* @type {string[]|undefined}
*/
this.exportKeys = undefined;
}
// To be called during pre-execution when --expose-internals is on.
// Enables the user-land module loader to access internal modules.
static exposeInternals() {
for (const [id, mod] of NativeModule.map) {
// Do not expose this to user land even with --expose-internals.
if (id !== loaderId) {
mod.canBeRequiredByUsers = true;
}
}
}
static exists(id) {
return NativeModule.map.has(id);
}
static canBeRequiredByUsers(id) {
const mod = NativeModule.map.get(id);
return mod && mod.canBeRequiredByUsers;
}
// Used by user-land module loaders to compile and load builtins.
compileForPublicLoader(needToSyncExports) {
if (!this.canBeRequiredByUsers) {
// No code because this is an assertion against bugs
// eslint-disable-next-line no-restricted-syntax
throw new Error(`Should not compile ${this.id} for public use`);
}
this.compileForInternalLoader();
if (needToSyncExports) {
if (!this.exportKeys) {
// When using --expose-internals, we do not want to reflect the named
// exports from core modules as this can trigger unnecessary getters.
const internal = this.id.startsWith('internal/');
this.exportKeys = internal ? [] : ObjectKeys(this.exports);
}
this.getESMFacade();
this.syncExports();
}
return this.exports;
}
getESMFacade() {
if (this.module) return this.module;
const { ModuleWrap } = internalBinding('module_wrap');
const url = `node:${this.id}`;
const nativeModule = this;
this.module = new ModuleWrap(
url, undefined, [...this.exportKeys, 'default'],
function() {
nativeModule.syncExports();
this.setExport('default', nativeModule.exports);
});
// Ensure immediate sync execution to capture exports now
this.module.instantiate();
this.module.evaluate(-1, false);
return this.module;
}
// Provide named exports for all builtin libraries so that the libraries
// may be imported in a nicer way for ESM users. The default export is left
// as the entire namespace (module.exports) and updates when this function is
// called so that APMs and other behavior are supported.
syncExports() {
const names = this.exportKeys;
if (this.module) {
for (let i = 0; i < names.length; i++) {
const exportName = names[i];
if (exportName === 'default') continue;
this.module.setExport(exportName,
getOwn(this.exports, exportName, this.exports));
}
}
}
compileForInternalLoader() {
if (this.loaded || this.loading) {
return this.exports;
}
const id = this.id;
this.loading = true;
try {
const requireFn = this.id.startsWith('internal/deps/') ?
requireWithFallbackInDeps : nativeModuleRequire;
const fn = compileFunction(id);
fn(this.exports, requireFn, this, process, internalBinding, primordials);
this.loaded = true;
} finally {
this.loading = false;
}
moduleLoadList.push(`NativeModule ${id}`);
return this.exports;
}
}
// Think of this as module.exports in this file even though it is not
// written in CommonJS style.
const loaderExports = {
internalBinding,
NativeModule,
require: nativeModuleRequire
};
function nativeModuleRequire(id) {
if (id === loaderId) {
return loaderExports;
}
const mod = NativeModule.map.get(id);
// Can't load the internal errors module from here, have to use a raw error.
// eslint-disable-next-line no-restricted-syntax
if (!mod) throw new TypeError(`Missing internal module '${id}'`);
return mod.compileForInternalLoader();
}
// Allow internal modules from dependencies to require
// other modules from dependencies by providing fallbacks.
function requireWithFallbackInDeps(request) {
if (!NativeModule.map.has(request)) {
request = `internal/deps/${request}`;
}
return nativeModuleRequire(request);
}
// Pass the exports back to C++ land for C++ internals to use.
return loaderExports;
}).call(this,require('_process'))
},{"_process":14}],3:[function(require,module,exports){
/* eslint node-core/documented-errors: "error" */
/* eslint node-core/alphabetize-errors: "error" */
/* eslint node-core/prefer-util-format-errors: "error" */
'use strict';
// The whole point behind this internal module is to allow Node.js to no
// longer be forced to treat every error message change as a semver-major
// change. The NodeError classes here all expose a `code` property whose
// value statically and permanently identifies the error. While the error
// message may change, the code should not.
const {
ArrayIsArray,
Error,
Map,
MathAbs,
NumberIsInteger,
ObjectDefineProperty,
ObjectKeys,
Symbol,
SymbolFor,
WeakMap,
} = primordials;
const messages = new Map();
const codes = {};
const classRegExp = /^([A-Z][a-z0-9]*)+$/;
// Sorted by a rough estimate on most frequently used entries.
const kTypes = [
'string',
'function',
'number',
'object',
// Accept 'Function' and 'Object' as alternative to the lower cased version.
'Function',
'Object',
'boolean',
'bigint',
'symbol'
];
const { kMaxLength } = internalBinding('buffer');
const MainContextError = Error;
const ErrorToString = Error.prototype.toString;
const overrideStackTrace = new WeakMap();
const kNoOverride = Symbol('kNoOverride');
const prepareStackTrace = (globalThis, error, trace) => {
// API for node internals to override error stack formatting
// without interfering with userland code.
if (overrideStackTrace.has(error)) {
const f = overrideStackTrace.get(error);
overrideStackTrace.delete(error);
return f(error, trace);
}
const globalOverride =
maybeOverridePrepareStackTrace(globalThis, error, trace);
if (globalOverride !== kNoOverride) return globalOverride;
// Normal error formatting:
//
// Error: Message
// at function (file)
// at file
const errorString = ErrorToString.call(error);
if (trace.length === 0) {
return errorString;
}
return `${errorString}\n at ${trace.join('\n at ')}`;
};
const maybeOverridePrepareStackTrace = (globalThis, error, trace) => {
// Polyfill of V8's Error.prepareStackTrace API.
// https://crbug.com/v8/7848
// `globalThis` is the global that contains the constructor which
// created `error`.
if (typeof globalThis.Error.prepareStackTrace === 'function') {
return globalThis.Error.prepareStackTrace(error, trace);
}
// We still have legacy usage that depends on the main context's `Error`
// being used, even when the error is from a different context.
// TODO(devsnek): evaluate if this can be eventually deprecated/removed.
if (typeof MainContextError.prepareStackTrace === 'function') {
return MainContextError.prepareStackTrace(error, trace);
}
return kNoOverride;
};
let excludedStackFn;
// Lazily loaded
let util;
let assert;
let internalUtil = null;
function lazyInternalUtil() {
if (!internalUtil) {
internalUtil = require('internal/util');
}
return internalUtil;
}
let internalUtilInspect = null;
function lazyInternalUtilInspect() {
if (!internalUtilInspect) {
internalUtilInspect = require('internal/util/inspect');
}
return internalUtilInspect;
}
let buffer;
function lazyBuffer() {
if (buffer === undefined)
buffer = require('buffer').Buffer;
return buffer;
}
// A specialized Error that includes an additional info property with
// additional information about the error condition.
// It has the properties present in a UVException but with a custom error
// message followed by the uv error code and uv error message.
// It also has its own error code with the original uv error context put into
// `err.info`.
// The context passed into this error must have .code, .syscall and .message,
// and may have .path and .dest.
class SystemError extends Error {
constructor(key, context) {
if (excludedStackFn === undefined) {
super();
} else {
const limit = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
super();
// Reset the limit and setting the name property.
Error.stackTraceLimit = limit;
}
const prefix = getMessage(key, [], this);
let message = `${prefix}: ${context.syscall} returned ` +
`${context.code} (${context.message})`;
if (context.path !== undefined)
message += ` ${context.path}`;
if (context.dest !== undefined)
message += ` => ${context.dest}`;
ObjectDefineProperty(this, 'message', {
value: message,
enumerable: false,
writable: true,
configurable: true
});
addCodeToName(this, 'SystemError', key);
this.code = key;
ObjectDefineProperty(this, 'info', {
value: context,
enumerable: true,
configurable: true,
writable: false
});
ObjectDefineProperty(this, 'errno', {
get() {
return context.errno;
},
set: (value) => {
context.errno = value;
},