@types/node 24.7.1 → 24.8.0
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.
- node/README.md +1 -1
- node/assert.d.ts +1 -1
- node/child_process.d.ts +15 -9
- node/cluster.d.ts +3 -4
- node/crypto.d.ts +391 -60
- node/diagnostics_channel.d.ts +0 -2
- node/dns.d.ts +1 -1
- node/events.d.ts +1 -1
- node/fs.d.ts +11 -11
- node/http.d.ts +3 -4
- node/http2.d.ts +148 -29
- node/https.d.ts +9 -12
- node/net.d.ts +5 -5
- node/os.d.ts +13 -3
- node/package.json +2 -2
- node/perf_hooks.d.ts +6 -8
- node/process.d.ts +7 -19
- node/readline/promises.d.ts +1 -1
- node/sea.d.ts +9 -0
- node/stream.d.ts +38 -23
- node/tls.d.ts +2 -2
- node/v8.d.ts +18 -2
- node/vm.d.ts +146 -86
- node/worker_threads.d.ts +39 -1
node/vm.d.ts
CHANGED
|
@@ -99,28 +99,22 @@ declare module "vm" {
|
|
|
99
99
|
*/
|
|
100
100
|
breakOnSigint?: boolean | undefined;
|
|
101
101
|
}
|
|
102
|
-
interface RunningScriptInNewContextOptions
|
|
102
|
+
interface RunningScriptInNewContextOptions
|
|
103
|
+
extends RunningScriptOptions, Pick<CreateContextOptions, "microtaskMode">
|
|
104
|
+
{
|
|
103
105
|
/**
|
|
104
106
|
* Human-readable name of the newly created context.
|
|
105
107
|
*/
|
|
106
|
-
contextName?: CreateContextOptions["name"];
|
|
108
|
+
contextName?: CreateContextOptions["name"] | undefined;
|
|
107
109
|
/**
|
|
108
110
|
* Origin corresponding to the newly created context for display purposes. The origin should be formatted like a URL,
|
|
109
111
|
* but with only the scheme, host, and port (if necessary), like the value of the `url.origin` property of a `URL` object.
|
|
110
112
|
* Most notably, this string should omit the trailing slash, as that denotes a path.
|
|
111
113
|
*/
|
|
112
|
-
contextOrigin?: CreateContextOptions["origin"];
|
|
113
|
-
contextCodeGeneration?: CreateContextOptions["codeGeneration"];
|
|
114
|
-
/**
|
|
115
|
-
* If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
|
|
116
|
-
*/
|
|
117
|
-
microtaskMode?: CreateContextOptions["microtaskMode"];
|
|
114
|
+
contextOrigin?: CreateContextOptions["origin"] | undefined;
|
|
115
|
+
contextCodeGeneration?: CreateContextOptions["codeGeneration"] | undefined;
|
|
118
116
|
}
|
|
119
|
-
interface RunningCodeOptions extends RunningScriptOptions {
|
|
120
|
-
/**
|
|
121
|
-
* Provides an optional data with V8's code cache data for the supplied source.
|
|
122
|
-
*/
|
|
123
|
-
cachedData?: ScriptOptions["cachedData"] | undefined;
|
|
117
|
+
interface RunningCodeOptions extends RunningScriptOptions, Pick<ScriptOptions, "cachedData"> {
|
|
124
118
|
/**
|
|
125
119
|
* Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
|
|
126
120
|
* part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
|
|
@@ -132,11 +126,9 @@ declare module "vm" {
|
|
|
132
126
|
| typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
|
|
133
127
|
| undefined;
|
|
134
128
|
}
|
|
135
|
-
interface RunningCodeInNewContextOptions
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
*/
|
|
139
|
-
cachedData?: ScriptOptions["cachedData"] | undefined;
|
|
129
|
+
interface RunningCodeInNewContextOptions
|
|
130
|
+
extends RunningScriptInNewContextOptions, Pick<ScriptOptions, "cachedData">
|
|
131
|
+
{
|
|
140
132
|
/**
|
|
141
133
|
* Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is
|
|
142
134
|
* part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see
|
|
@@ -148,16 +140,7 @@ declare module "vm" {
|
|
|
148
140
|
| typeof constants.USE_MAIN_CONTEXT_DEFAULT_LOADER
|
|
149
141
|
| undefined;
|
|
150
142
|
}
|
|
151
|
-
interface CompileFunctionOptions extends BaseOptions {
|
|
152
|
-
/**
|
|
153
|
-
* Provides an optional data with V8's code cache data for the supplied source.
|
|
154
|
-
*/
|
|
155
|
-
cachedData?: ScriptOptions["cachedData"] | undefined;
|
|
156
|
-
/**
|
|
157
|
-
* Specifies whether to produce new cache data.
|
|
158
|
-
* @default false
|
|
159
|
-
*/
|
|
160
|
-
produceCachedData?: boolean | undefined;
|
|
143
|
+
interface CompileFunctionOptions extends BaseOptions, Pick<ScriptOptions, "cachedData" | "produceCachedData"> {
|
|
161
144
|
/**
|
|
162
145
|
* The sandbox/context in which the said function should be compiled in.
|
|
163
146
|
*/
|
|
@@ -386,15 +369,15 @@ declare module "vm" {
|
|
|
386
369
|
*/
|
|
387
370
|
createCachedData(): Buffer;
|
|
388
371
|
/** @deprecated in favor of `script.createCachedData()` */
|
|
389
|
-
cachedDataProduced?: boolean
|
|
372
|
+
cachedDataProduced?: boolean;
|
|
390
373
|
/**
|
|
391
374
|
* When `cachedData` is supplied to create the `vm.Script`, this value will be set
|
|
392
375
|
* to either `true` or `false` depending on acceptance of the data by V8.
|
|
393
376
|
* Otherwise the value is `undefined`.
|
|
394
377
|
* @since v5.7.0
|
|
395
378
|
*/
|
|
396
|
-
cachedDataRejected?: boolean
|
|
397
|
-
cachedData?: Buffer
|
|
379
|
+
cachedDataRejected?: boolean;
|
|
380
|
+
cachedData?: Buffer;
|
|
398
381
|
/**
|
|
399
382
|
* When the script is compiled from a source that contains a source map magic
|
|
400
383
|
* comment, this property will be set to the URL of the source map.
|
|
@@ -412,7 +395,7 @@ declare module "vm" {
|
|
|
412
395
|
* ```
|
|
413
396
|
* @since v19.1.0, v18.13.0
|
|
414
397
|
*/
|
|
415
|
-
sourceMapURL
|
|
398
|
+
sourceMapURL: string | undefined;
|
|
416
399
|
}
|
|
417
400
|
/**
|
|
418
401
|
* If the given `contextObject` is an object, the `vm.createContext()` method will
|
|
@@ -622,11 +605,7 @@ declare module "vm" {
|
|
|
622
605
|
code: string,
|
|
623
606
|
params?: readonly string[],
|
|
624
607
|
options?: CompileFunctionOptions,
|
|
625
|
-
): Function &
|
|
626
|
-
cachedData?: Script["cachedData"] | undefined;
|
|
627
|
-
cachedDataProduced?: Script["cachedDataProduced"] | undefined;
|
|
628
|
-
cachedDataRejected?: Script["cachedDataRejected"] | undefined;
|
|
629
|
-
};
|
|
608
|
+
): Function & Pick<Script, "cachedData" | "cachedDataProduced" | "cachedDataRejected">;
|
|
630
609
|
/**
|
|
631
610
|
* Measure the memory known to V8 and used by all contexts known to the
|
|
632
611
|
* current V8 isolate, or the main context.
|
|
@@ -683,10 +662,7 @@ declare module "vm" {
|
|
|
683
662
|
* @experimental
|
|
684
663
|
*/
|
|
685
664
|
function measureMemory(options?: MeasureMemoryOptions): Promise<MemoryMeasurement>;
|
|
686
|
-
interface ModuleEvaluateOptions {
|
|
687
|
-
timeout?: RunningScriptOptions["timeout"] | undefined;
|
|
688
|
-
breakOnSigint?: RunningScriptOptions["breakOnSigint"] | undefined;
|
|
689
|
-
}
|
|
665
|
+
interface ModuleEvaluateOptions extends Pick<RunningScriptOptions, "breakOnSigint" | "timeout"> {}
|
|
690
666
|
type ModuleLinker = (
|
|
691
667
|
specifier: string,
|
|
692
668
|
referencingModule: Module,
|
|
@@ -700,14 +676,12 @@ declare module "vm" {
|
|
|
700
676
|
* flag enabled.
|
|
701
677
|
*
|
|
702
678
|
* The `vm.Module` class provides a low-level interface for using
|
|
703
|
-
* ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script`
|
|
704
|
-
* defined in the ECMAScript
|
|
679
|
+
* ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script`
|
|
680
|
+
* class that closely mirrors [Module Record](https://tc39.es/ecma262/#sec-abstract-module-records)s as defined in the ECMAScript
|
|
705
681
|
* specification.
|
|
706
682
|
*
|
|
707
683
|
* Unlike `vm.Script` however, every `vm.Module` object is bound to a context from
|
|
708
|
-
* its creation.
|
|
709
|
-
* in contrast with the synchronous nature of `vm.Script` objects. The use of
|
|
710
|
-
* 'async' functions can help with manipulating `vm.Module` objects.
|
|
684
|
+
* its creation.
|
|
711
685
|
*
|
|
712
686
|
* Using a `vm.Module` object requires three distinct steps: creation/parsing,
|
|
713
687
|
* linking, and evaluation. These three steps are illustrated in the following
|
|
@@ -735,7 +709,7 @@ declare module "vm" {
|
|
|
735
709
|
* // Here, we attempt to obtain the default export from the module "foo", and
|
|
736
710
|
* // put it into local binding "secret".
|
|
737
711
|
*
|
|
738
|
-
* const
|
|
712
|
+
* const rootModule = new vm.SourceTextModule(`
|
|
739
713
|
* import s from 'foo';
|
|
740
714
|
* s;
|
|
741
715
|
* print(s);
|
|
@@ -745,39 +719,48 @@ declare module "vm" {
|
|
|
745
719
|
* //
|
|
746
720
|
* // "Link" the imported dependencies of this Module to it.
|
|
747
721
|
* //
|
|
748
|
-
* //
|
|
749
|
-
* //
|
|
750
|
-
* // the imported module. The callback is expected to return a Module that
|
|
751
|
-
* // corresponds to the provided specifier, with certain requirements documented
|
|
752
|
-
* // in `module.link()`.
|
|
753
|
-
* //
|
|
754
|
-
* // If linking has not started for the returned Module, the same linker
|
|
755
|
-
* // callback will be called on the returned Module.
|
|
722
|
+
* // Obtain the requested dependencies of a SourceTextModule by
|
|
723
|
+
* // `sourceTextModule.moduleRequests` and resolve them.
|
|
756
724
|
* //
|
|
757
725
|
* // Even top-level Modules without dependencies must be explicitly linked. The
|
|
758
|
-
* //
|
|
726
|
+
* // array passed to `sourceTextModule.linkRequests(modules)` can be
|
|
727
|
+
* // empty, however.
|
|
759
728
|
* //
|
|
760
|
-
* //
|
|
761
|
-
* //
|
|
762
|
-
* //
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
*
|
|
729
|
+
* // Note: This is a contrived example in that the resolveAndLinkDependencies
|
|
730
|
+
* // creates a new "foo" module every time it is called. In a full-fledged
|
|
731
|
+
* // module system, a cache would probably be used to avoid duplicated modules.
|
|
732
|
+
*
|
|
733
|
+
* const moduleMap = new Map([
|
|
734
|
+
* ['root', rootModule],
|
|
735
|
+
* ]);
|
|
736
|
+
*
|
|
737
|
+
* function resolveAndLinkDependencies(module) {
|
|
738
|
+
* const requestedModules = module.moduleRequests.map((request) => {
|
|
739
|
+
* // In a full-fledged module system, the resolveAndLinkDependencies would
|
|
740
|
+
* // resolve the module with the module cache key `[specifier, attributes]`.
|
|
741
|
+
* // In this example, we just use the specifier as the key.
|
|
742
|
+
* const specifier = request.specifier;
|
|
766
743
|
*
|
|
767
|
-
*
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
*
|
|
744
|
+
* let requestedModule = moduleMap.get(specifier);
|
|
745
|
+
* if (requestedModule === undefined) {
|
|
746
|
+
* requestedModule = new vm.SourceTextModule(`
|
|
747
|
+
* // The "secret" variable refers to the global variable we added to
|
|
748
|
+
* // "contextifiedObject" when creating the context.
|
|
749
|
+
* export default secret;
|
|
750
|
+
* `, { context: referencingModule.context });
|
|
751
|
+
* moduleMap.set(specifier, linkedModule);
|
|
752
|
+
* // Resolve the dependencies of the new module as well.
|
|
753
|
+
* resolveAndLinkDependencies(requestedModule);
|
|
754
|
+
* }
|
|
774
755
|
*
|
|
775
|
-
*
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
*
|
|
756
|
+
* return requestedModule;
|
|
757
|
+
* });
|
|
758
|
+
*
|
|
759
|
+
* module.linkRequests(requestedModules);
|
|
779
760
|
* }
|
|
780
|
-
*
|
|
761
|
+
*
|
|
762
|
+
* resolveAndLinkDependencies(rootModule);
|
|
763
|
+
* rootModule.instantiate();
|
|
781
764
|
*
|
|
782
765
|
* // Step 3
|
|
783
766
|
* //
|
|
@@ -785,7 +768,7 @@ declare module "vm" {
|
|
|
785
768
|
* // resolve after the module has finished evaluating.
|
|
786
769
|
*
|
|
787
770
|
* // Prints 42.
|
|
788
|
-
* await
|
|
771
|
+
* await rootModule.evaluate();
|
|
789
772
|
* ```
|
|
790
773
|
* @since v13.0.0, v12.16.0
|
|
791
774
|
* @experimental
|
|
@@ -855,6 +838,10 @@ declare module "vm" {
|
|
|
855
838
|
* Link module dependencies. This method must be called before evaluation, and
|
|
856
839
|
* can only be called once per module.
|
|
857
840
|
*
|
|
841
|
+
* Use `sourceTextModule.linkRequests(modules)` and
|
|
842
|
+
* `sourceTextModule.instantiate()` to link modules either synchronously or
|
|
843
|
+
* asynchronously.
|
|
844
|
+
*
|
|
858
845
|
* The function is expected to return a `Module` object or a `Promise` that
|
|
859
846
|
* eventually resolves to a `Module` object. The returned `Module` must satisfy the
|
|
860
847
|
* following two invariants:
|
|
@@ -885,19 +872,13 @@ declare module "vm" {
|
|
|
885
872
|
*/
|
|
886
873
|
link(linker: ModuleLinker): Promise<void>;
|
|
887
874
|
}
|
|
888
|
-
interface SourceTextModuleOptions {
|
|
875
|
+
interface SourceTextModuleOptions extends Pick<ScriptOptions, "cachedData" | "columnOffset" | "lineOffset"> {
|
|
889
876
|
/**
|
|
890
877
|
* String used in stack traces.
|
|
891
878
|
* @default 'vm:module(i)' where i is a context-specific ascending index.
|
|
892
879
|
*/
|
|
893
880
|
identifier?: string | undefined;
|
|
894
|
-
/**
|
|
895
|
-
* Provides an optional data with V8's code cache data for the supplied source.
|
|
896
|
-
*/
|
|
897
|
-
cachedData?: ScriptOptions["cachedData"] | undefined;
|
|
898
881
|
context?: Context | undefined;
|
|
899
|
-
lineOffset?: BaseOptions["lineOffset"] | undefined;
|
|
900
|
-
columnOffset?: BaseOptions["columnOffset"] | undefined;
|
|
901
882
|
/**
|
|
902
883
|
* Called during evaluation of this module to initialize the `import.meta`.
|
|
903
884
|
*/
|
|
@@ -941,6 +922,39 @@ declare module "vm" {
|
|
|
941
922
|
class SourceTextModule extends Module {
|
|
942
923
|
/**
|
|
943
924
|
* Creates a new `SourceTextModule` instance.
|
|
925
|
+
*
|
|
926
|
+
* Properties assigned to the `import.meta` object that are objects may
|
|
927
|
+
* allow the module to access information outside the specified `context`. Use
|
|
928
|
+
* `vm.runInContext()` to create objects in a specific context.
|
|
929
|
+
*
|
|
930
|
+
* ```js
|
|
931
|
+
* import vm from 'node:vm';
|
|
932
|
+
*
|
|
933
|
+
* const contextifiedObject = vm.createContext({ secret: 42 });
|
|
934
|
+
*
|
|
935
|
+
* const module = new vm.SourceTextModule(
|
|
936
|
+
* 'Object.getPrototypeOf(import.meta.prop).secret = secret;',
|
|
937
|
+
* {
|
|
938
|
+
* initializeImportMeta(meta) {
|
|
939
|
+
* // Note: this object is created in the top context. As such,
|
|
940
|
+
* // Object.getPrototypeOf(import.meta.prop) points to the
|
|
941
|
+
* // Object.prototype in the top context rather than that in
|
|
942
|
+
* // the contextified object.
|
|
943
|
+
* meta.prop = {};
|
|
944
|
+
* },
|
|
945
|
+
* });
|
|
946
|
+
* // The module has an empty `moduleRequests` array.
|
|
947
|
+
* module.linkRequests([]);
|
|
948
|
+
* module.instantiate();
|
|
949
|
+
* await module.evaluate();
|
|
950
|
+
*
|
|
951
|
+
* // Now, Object.prototype.secret will be equal to 42.
|
|
952
|
+
* //
|
|
953
|
+
* // To fix this problem, replace
|
|
954
|
+
* // meta.prop = {};
|
|
955
|
+
* // above with
|
|
956
|
+
* // meta.prop = vm.runInContext('{}', contextifiedObject);
|
|
957
|
+
* ```
|
|
944
958
|
* @param code JavaScript Module code to parse
|
|
945
959
|
*/
|
|
946
960
|
constructor(code: string, options?: SourceTextModuleOptions);
|
|
@@ -948,6 +962,55 @@ declare module "vm" {
|
|
|
948
962
|
* @deprecated Use `sourceTextModule.moduleRequests` instead.
|
|
949
963
|
*/
|
|
950
964
|
readonly dependencySpecifiers: readonly string[];
|
|
965
|
+
/**
|
|
966
|
+
* Instantiate the module with the linked requested modules.
|
|
967
|
+
*
|
|
968
|
+
* This resolves the imported bindings of the module, including re-exported
|
|
969
|
+
* binding names. When there are any bindings that cannot be resolved,
|
|
970
|
+
* an error would be thrown synchronously.
|
|
971
|
+
*
|
|
972
|
+
* If the requested modules include cyclic dependencies, the
|
|
973
|
+
* `sourceTextModule.linkRequests(modules)` method must be called on all
|
|
974
|
+
* modules in the cycle before calling this method.
|
|
975
|
+
* @since v24.8.0
|
|
976
|
+
*/
|
|
977
|
+
instantiate(): void;
|
|
978
|
+
/**
|
|
979
|
+
* Link module dependencies. This method must be called before evaluation, and
|
|
980
|
+
* can only be called once per module.
|
|
981
|
+
*
|
|
982
|
+
* The order of the module instances in the `modules` array should correspond to the order of
|
|
983
|
+
* `sourceTextModule.moduleRequests` being resolved. If two module requests have the same
|
|
984
|
+
* specifier and import attributes, they must be resolved with the same module instance or an
|
|
985
|
+
* `ERR_MODULE_LINK_MISMATCH` would be thrown. For example, when linking requests for this
|
|
986
|
+
* module:
|
|
987
|
+
*
|
|
988
|
+
* ```js
|
|
989
|
+
* import foo from 'foo';
|
|
990
|
+
* import source Foo from 'foo';
|
|
991
|
+
* ```
|
|
992
|
+
*
|
|
993
|
+
* The `modules` array must contain two references to the same instance, because the two
|
|
994
|
+
* module requests are identical but in two phases.
|
|
995
|
+
*
|
|
996
|
+
* If the module has no dependencies, the `modules` array can be empty.
|
|
997
|
+
*
|
|
998
|
+
* Users can use `sourceTextModule.moduleRequests` to implement the host-defined
|
|
999
|
+
* [HostLoadImportedModule](https://tc39.es/ecma262/#sec-HostLoadImportedModule) abstract operation in the ECMAScript specification,
|
|
1000
|
+
* and using `sourceTextModule.linkRequests()` to invoke specification defined
|
|
1001
|
+
* [FinishLoadingImportedModule](https://tc39.es/ecma262/#sec-FinishLoadingImportedModule), on the module with all dependencies in a batch.
|
|
1002
|
+
*
|
|
1003
|
+
* It's up to the creator of the `SourceTextModule` to determine if the resolution
|
|
1004
|
+
* of the dependencies is synchronous or asynchronous.
|
|
1005
|
+
*
|
|
1006
|
+
* After each module in the `modules` array is linked, call
|
|
1007
|
+
* `sourceTextModule.instantiate()`.
|
|
1008
|
+
* @since v24.8.0
|
|
1009
|
+
* @param modules Array of `vm.Module` objects that this module depends on.
|
|
1010
|
+
* The order of the modules in the array is the order of
|
|
1011
|
+
* `sourceTextModule.moduleRequests`.
|
|
1012
|
+
*/
|
|
1013
|
+
linkRequests(modules: readonly Module[]): void;
|
|
951
1014
|
/**
|
|
952
1015
|
* The requested import dependencies of this module. The returned array is frozen
|
|
953
1016
|
* to disallow any changes to it.
|
|
@@ -1043,9 +1106,7 @@ declare module "vm" {
|
|
|
1043
1106
|
options?: SyntheticModuleOptions,
|
|
1044
1107
|
);
|
|
1045
1108
|
/**
|
|
1046
|
-
* This method
|
|
1047
|
-
* it is called before the module is linked, an `ERR_VM_MODULE_STATUS` error
|
|
1048
|
-
* will be thrown.
|
|
1109
|
+
* This method sets the module export binding slots with the given value.
|
|
1049
1110
|
*
|
|
1050
1111
|
* ```js
|
|
1051
1112
|
* import vm from 'node:vm';
|
|
@@ -1054,7 +1115,6 @@ declare module "vm" {
|
|
|
1054
1115
|
* m.setExport('x', 1);
|
|
1055
1116
|
* });
|
|
1056
1117
|
*
|
|
1057
|
-
* await m.link(() => {});
|
|
1058
1118
|
* await m.evaluate();
|
|
1059
1119
|
*
|
|
1060
1120
|
* assert.strictEqual(m.namespace.x, 1);
|
node/worker_threads.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ declare module "worker_threads" {
|
|
|
62
62
|
import { Readable, Writable } from "node:stream";
|
|
63
63
|
import { ReadableStream, TransformStream, WritableStream } from "node:stream/web";
|
|
64
64
|
import { URL } from "node:url";
|
|
65
|
-
import { HeapInfo } from "node:v8";
|
|
65
|
+
import { CPUProfileHandle, HeapInfo } from "node:v8";
|
|
66
66
|
import { MessageEvent } from "undici-types";
|
|
67
67
|
const isInternalThread: boolean;
|
|
68
68
|
const isMainThread: boolean;
|
|
@@ -469,6 +469,44 @@ declare module "worker_threads" {
|
|
|
469
469
|
* @since v24.0.0
|
|
470
470
|
*/
|
|
471
471
|
getHeapStatistics(): Promise<HeapInfo>;
|
|
472
|
+
/**
|
|
473
|
+
* Starting a CPU profile then return a Promise that fulfills with an error
|
|
474
|
+
* or an `CPUProfileHandle` object. This API supports `await using` syntax.
|
|
475
|
+
*
|
|
476
|
+
* ```js
|
|
477
|
+
* const { Worker } = require('node:worker_threads');
|
|
478
|
+
*
|
|
479
|
+
* const worker = new Worker(`
|
|
480
|
+
* const { parentPort } = require('worker_threads');
|
|
481
|
+
* parentPort.on('message', () => {});
|
|
482
|
+
* `, { eval: true });
|
|
483
|
+
*
|
|
484
|
+
* worker.on('online', async () => {
|
|
485
|
+
* const handle = await worker.startCpuProfile();
|
|
486
|
+
* const profile = await handle.stop();
|
|
487
|
+
* console.log(profile);
|
|
488
|
+
* worker.terminate();
|
|
489
|
+
* });
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* `await using` example.
|
|
493
|
+
*
|
|
494
|
+
* ```js
|
|
495
|
+
* const { Worker } = require('node::worker_threads');
|
|
496
|
+
*
|
|
497
|
+
* const w = new Worker(`
|
|
498
|
+
* const { parentPort } = require('worker_threads');
|
|
499
|
+
* parentPort.on('message', () => {});
|
|
500
|
+
* `, { eval: true });
|
|
501
|
+
*
|
|
502
|
+
* w.on('online', async () => {
|
|
503
|
+
* // Stop profile automatically when return and profile will be discarded
|
|
504
|
+
* await using handle = await w.startCpuProfile();
|
|
505
|
+
* });
|
|
506
|
+
* ```
|
|
507
|
+
* @since v24.8.0
|
|
508
|
+
*/
|
|
509
|
+
startCpuProfile(): Promise<CPUProfileHandle>;
|
|
472
510
|
/**
|
|
473
511
|
* Calls `worker.terminate()` when the dispose scope is exited.
|
|
474
512
|
*
|