typenative 0.7.0 → 0.7.1

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.
Files changed (217) hide show
  1. package/bin/node/assert.js +2 -2
  2. package/bin/node/child_process.js +66 -8
  3. package/bin/node/fs.js +1012 -4
  4. package/bin/node/histogram.js +1991 -0
  5. package/bin/node/process.js +14 -2
  6. package/bin/node/sqlite.js +1488 -5
  7. package/bin/node/stream.js +2 -1
  8. package/bin/node/system_extra.js +3 -270
  9. package/bin/node/test.js +39 -1
  10. package/bin/node/test_report.js +47 -1
  11. package/bin/node/test_run.js +57 -2
  12. package/bin/node/util.js +8 -5
  13. package/bin/node/webassembly.js +20 -5
  14. package/bin/node/webview.js +3257 -244
  15. package/bin/node/zlib.js +118 -14
  16. package/bin/node/zlib_iter.js +585 -0
  17. package/bin/transpiler.js +1370 -258
  18. package/bin/version.js +1 -1
  19. package/govendor/software.sslmate.com/src/go-pkcs12/.gitattributes +10 -0
  20. package/govendor/software.sslmate.com/src/go-pkcs12/LICENSE +28 -0
  21. package/govendor/software.sslmate.com/src/go-pkcs12/README.md +31 -0
  22. package/govendor/software.sslmate.com/src/go-pkcs12/bmp-string.go +63 -0
  23. package/govendor/software.sslmate.com/src/go-pkcs12/crypto.go +331 -0
  24. package/govendor/software.sslmate.com/src/go-pkcs12/errors.go +23 -0
  25. package/govendor/software.sslmate.com/src/go-pkcs12/go.mod +3 -0
  26. package/govendor/software.sslmate.com/src/go-pkcs12/internal/rc2/rc2.go +271 -0
  27. package/govendor/software.sslmate.com/src/go-pkcs12/mac.go +202 -0
  28. package/govendor/software.sslmate.com/src/go-pkcs12/pbkdf.go +184 -0
  29. package/govendor/software.sslmate.com/src/go-pkcs12/pkcs12.go +1000 -0
  30. package/govendor/software.sslmate.com/src/go-pkcs12/safebags.go +107 -0
  31. package/package.json +10 -1
  32. package/types/tsconfig.json +17 -0
  33. package/types/typenative-npm.d.ts +492 -12
  34. package/types/typenative.d.ts +88 -2
  35. package/.gitattributes +0 -1
  36. package/.github/workflows/ci.yml +0 -68
  37. package/.github/workflows/npm-publish-github-packages.yml +0 -88
  38. package/CHANGELOG.md +0 -1746
  39. package/CONTRIBUTION.md +0 -133
  40. package/conformance.md +0 -1497
  41. package/examples/README.md +0 -114
  42. package/examples/angular-templates/README.md +0 -141
  43. package/examples/angular-templates/bench.mjs +0 -173
  44. package/examples/angular-templates/dom-type-globals.d.ts +0 -21
  45. package/examples/angular-templates/dom-type-stubs.ts +0 -21
  46. package/examples/angular-templates/main.ts +0 -135
  47. package/examples/angular-templates/parity.mjs +0 -157
  48. package/examples/angular-templates/run-node.mjs +0 -69
  49. package/examples/angular-templates/vendor/angular/compiler/LICENSE +0 -21
  50. package/examples/desktop-notes/README.md +0 -106
  51. package/examples/desktop-notes/bench.mjs +0 -125
  52. package/examples/desktop-notes/main.ts +0 -131
  53. package/examples/desktop-notes/package-lock.json +0 -726
  54. package/examples/desktop-notes/package.json +0 -9
  55. package/examples/desktop-notes/ui.ts +0 -176
  56. package/examples/dupe-finder/README.md +0 -78
  57. package/examples/dupe-finder/bench.mjs +0 -120
  58. package/examples/dupe-finder/main.ts +0 -87
  59. package/examples/fibonacci/README.md +0 -89
  60. package/examples/fibonacci/bench.mjs +0 -87
  61. package/examples/fibonacci/main.ts +0 -21
  62. package/examples/hello-world/README.md +0 -62
  63. package/examples/hello-world/bench.mjs +0 -66
  64. package/examples/hello-world/main.ts +0 -7
  65. package/examples/json-server/README.md +0 -132
  66. package/examples/json-server/bench.mjs +0 -263
  67. package/examples/json-server/main.ts +0 -67
  68. package/examples/mandelbrot-png/README.md +0 -63
  69. package/examples/mandelbrot-png/bench.mjs +0 -95
  70. package/examples/mandelbrot-png/main.ts +0 -98
  71. package/examples/mandelbrot-png/preview.png +0 -0
  72. package/examples/marked-cli/README.md +0 -174
  73. package/examples/marked-cli/bench.mjs +0 -178
  74. package/examples/marked-cli/main.ts +0 -410
  75. package/examples/marked-cli/parity.mjs +0 -185
  76. package/examples/marked-cli/vendor/marked/LICENSE +0 -44
  77. package/examples/marked-cli/vendor/marked/VENDOR.md +0 -26
  78. package/examples/openai-chat/README.md +0 -148
  79. package/examples/openai-chat/bench.mjs +0 -175
  80. package/examples/openai-chat/main.ts +0 -488
  81. package/examples/react-compiler/README.md +0 -185
  82. package/examples/react-compiler/bench.mjs +0 -181
  83. package/examples/react-compiler/main.ts +0 -324
  84. package/examples/react-compiler/parity.mjs +0 -362
  85. package/examples/react-compiler/run-node.mjs +0 -90
  86. package/examples/react-compiler/vendor/babel/LICENSE +0 -22
  87. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +0 -15
  88. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +0 -51
  89. package/examples/react-compiler/vendor/charcodes/package.json +0 -25
  90. package/examples/react-compiler/vendor/invariant/LICENSE +0 -21
  91. package/examples/react-compiler/vendor/invariant/invariant.cjs +0 -51
  92. package/examples/react-compiler/vendor/invariant/invariant.d.cts +0 -11
  93. package/examples/react-compiler/vendor/invariant/types/LICENSE +0 -21
  94. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +0 -19
  95. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +0 -19
  96. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +0 -19
  97. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +0 -19
  98. package/examples/react-compiler/vendor/js-tokens/LICENSE +0 -21
  99. package/examples/react-compiler/vendor/js-tokens/index.cjs +0 -23
  100. package/examples/react-compiler/vendor/js-tokens/index.d.cts +0 -13
  101. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +0 -20
  102. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +0 -337
  103. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +0 -384
  104. package/examples/react-compiler/vendor/jsesc/types/LICENSE +0 -21
  105. package/examples/react-compiler/vendor/picocolors/LICENSE +0 -15
  106. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +0 -75
  107. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +0 -5
  108. package/examples/react-compiler/vendor/picocolors/types.d.ts +0 -51
  109. package/examples/react-compiler/vendor/react-compiler/LICENSE +0 -21
  110. package/examples/react-compiler/vendor/stubs/babel-core.ts +0 -31
  111. package/examples/react-compiler/vendor/stubs/debug.ts +0 -18
  112. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +0 -13
  113. package/examples/react-compiler/vendor/stubs/pretty-format.ts +0 -18
  114. package/examples/react-compiler/vendor/zod/LICENSE +0 -21
  115. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +0 -9
  116. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +0 -5
  117. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +0 -49
  118. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +0 -48
  119. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +0 -50
  120. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +0 -6
  121. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +0 -126
  122. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +0 -39
  123. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +0 -12
  124. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +0 -78
  125. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +0 -2
  126. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +0 -12
  127. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +0 -12
  128. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +0 -131
  129. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +0 -54
  130. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +0 -12
  131. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +0 -40
  132. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +0 -12
  133. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +0 -76
  134. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +0 -76
  135. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +0 -27
  136. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +0 -27
  137. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +0 -13
  138. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +0 -61
  139. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +0 -38
  140. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +0 -20
  141. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +0 -5
  142. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +0 -8
  143. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +0 -11
  144. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +0 -20
  145. package/examples/react-compiler/vendor.mjs +0 -688
  146. package/examples/todo-cli/README.md +0 -69
  147. package/examples/todo-cli/bench.mjs +0 -89
  148. package/examples/todo-cli/main.ts +0 -92
  149. package/examples/yaml-cli/README.md +0 -152
  150. package/examples/yaml-cli/bench.mjs +0 -265
  151. package/examples/yaml-cli/main.ts +0 -251
  152. package/examples/yaml-cli/parity.mjs +0 -156
  153. package/examples/yaml-cli/vendor/yaml/LICENSE +0 -13
  154. package/examples/yaml-cli/vendor/yaml/VENDOR.md +0 -25
  155. package/performance/README.md +0 -248
  156. package/performance/any-dynamic.ts +0 -21
  157. package/performance/any-record-view.ts +0 -20
  158. package/performance/arr-for-of.ts +0 -29
  159. package/performance/arr-hof.ts +0 -21
  160. package/performance/arr-push-index.ts +0 -15
  161. package/performance/arr-push-local.ts +0 -39
  162. package/performance/arr-slice-concat.ts +0 -24
  163. package/performance/arr-sort.ts +0 -21
  164. package/performance/async-await.ts +0 -24
  165. package/performance/async-promise-all.ts +0 -38
  166. package/performance/bigint-arith.ts +0 -36
  167. package/performance/buf-encode.ts +0 -29
  168. package/performance/class-accessors.ts +0 -48
  169. package/performance/class-dispatch.ts +0 -52
  170. package/performance/date-format.ts +0 -18
  171. package/performance/events-emit.ts +0 -27
  172. package/performance/exc-throw-rare.ts +0 -25
  173. package/performance/exc-try-catch.ts +0 -26
  174. package/performance/fn-closures.ts +0 -29
  175. package/performance/fn-recursion-tree.ts +0 -31
  176. package/performance/fn-rest-spread.ts +0 -43
  177. package/performance/gen-for-of.ts +0 -46
  178. package/performance/gen-next.ts +0 -32
  179. package/performance/iter-helpers.ts +0 -38
  180. package/performance/json-any.ts +0 -30
  181. package/performance/json-roundtrip.ts +0 -27
  182. package/performance/map-delete.ts +0 -24
  183. package/performance/map-iterate.ts +0 -26
  184. package/performance/map-number-keys.ts +0 -37
  185. package/performance/map-string-keys.ts +0 -22
  186. package/performance/num-arith-loop.ts +0 -14
  187. package/performance/num-bitwise.ts +0 -21
  188. package/performance/num-hash-imul.ts +0 -36
  189. package/performance/num-mod-int.ts +0 -16
  190. package/performance/num-to-string.ts +0 -16
  191. package/performance/obj-alloc.ts +0 -32
  192. package/performance/obj-keys-entries.ts +0 -44
  193. package/performance/obj-optional-chain.ts +0 -42
  194. package/performance/obj-record-dict.ts +0 -24
  195. package/performance/obj-spread-destructure.ts +0 -40
  196. package/performance/regex-exec.ts +0 -29
  197. package/performance/regex-replace-fn.ts +0 -24
  198. package/performance/regex-site.ts +0 -28
  199. package/performance/set-ops.ts +0 -20
  200. package/performance/str-char-scan.ts +0 -35
  201. package/performance/str-concat-plus.ts +0 -18
  202. package/performance/str-concat.ts +0 -24
  203. package/performance/str-methods.ts +0 -24
  204. package/performance/str-short-scan.ts +0 -26
  205. package/performance/str-split-join.ts +0 -23
  206. package/performance/str-switch-compare.ts +0 -50
  207. package/performance/str-template.ts +0 -16
  208. package/performance/str-unicode.ts +0 -25
  209. package/performance/typed-array.ts +0 -30
  210. package/performance/union-switch.ts +0 -57
  211. package/performance/union-typeof.ts +0 -40
  212. package/performance/wasm-call.ts +0 -63
  213. package/tsparser/check.go +0 -158
  214. package/tsparser/go.mod +0 -14
  215. package/tsparser/go.sum +0 -22
  216. package/tsparser/main.go +0 -363
  217. package/tsparser/tsparser.exe +0 -4
@@ -1014,6 +1014,7 @@ func TnReadableFrom(iterable interface{}, options ...interface{}) *TnStream {
1014
1014
  TnLoopRef()
1015
1015
  go func() {
1016
1016
  for {
1017
+ TnGenWake(iterable)
1017
1018
  v, ok := rv.Recv()
1018
1019
  if !ok {
1019
1020
  break
@@ -1600,7 +1601,7 @@ export function registerStream(r) {
1600
1601
  defineModule(r, mod);
1601
1602
  r.namespaces['stream.promises'] = 'stream/promises';
1602
1603
  r.namespaces['stream.default'] = 'stream.Stream';
1603
- defineHelper(r, 'nodeStream', ['encoding/json', 'math/big', 'os', 'reflect', 'strconv', 'unicode/utf8'], ['nodeEvents', 'buffer', 'stringDecoder', 'eventLoop', 'promise', 'dynamic', 'nodeInvoke', 'stdinReader'], streamHelper);
1604
+ defineHelper(r, 'nodeStream', ['encoding/json', 'math/big', 'os', 'reflect', 'strconv', 'unicode/utf8'], ['nodeEvents', 'buffer', 'stringDecoder', 'eventLoop', 'promise', 'dynamic', 'nodeInvoke', 'stdinReader', 'generatorStep'], streamHelper);
1604
1605
  defineHelper(r, 'stdinReader', ['bufio', 'os'], [], `// One buffered reader shared by process.stdin, readline and question()
1605
1606
  var tnStdinBuffered *bufio.Reader
1606
1607
 
@@ -4,6 +4,7 @@
4
4
  // loadavg / release / version; perf_hooks PerformanceObserver, timerify,
5
5
  // createHistogram, monitorEventLoopDelay, eventLoopUtilization.
6
6
  import { defineClass, defineHelper, setResults } from './registry.js';
7
+ import { registerHistogram } from './histogram.js';
7
8
  const uncaughtHelper = `// process.on('uncaughtException') & co.
8
9
  // set/addUncaughtExceptionCaptureCallback: the set one takes every error; an
9
10
  // added one takes it when it returns true
@@ -432,270 +433,6 @@ func TnPerfTimerify[F any](fn F, name string) F {
432
433
  return wrapped.Interface().(F)
433
434
  }
434
435
 
435
- // Histograms (createHistogram / monitorEventLoopDelay): values in nanoseconds
436
- type TnHistogram struct {
437
- values []float64
438
- exceeds float64
439
- enabled bool
440
- stop chan struct{}
441
- interval float64
442
- last time.Time
443
- }
444
-
445
- func TnCreateHistogram(options ...interface{}) *TnHistogram { return &TnHistogram{} }
446
-
447
- func (h *TnHistogram) record(value interface{}) {
448
- switch v := value.(type) {
449
- case float64:
450
- h.values = append(h.values, v)
451
- case *tnbig.Int:
452
- f, _ := new(tnbig.Float).SetInt(v).Float64()
453
- h.values = append(h.values, f)
454
- }
455
- }
456
-
457
- func (h *TnHistogram) recordDelta() {
458
- now := time.Now()
459
- if !h.last.IsZero() {
460
- h.values = append(h.values, float64(now.Sub(h.last).Nanoseconds()))
461
- }
462
- h.last = now
463
- }
464
-
465
- func (h *TnHistogram) sorted() []float64 {
466
- out := append([]float64{}, h.values...)
467
- sort.Float64s(out)
468
- return out
469
- }
470
-
471
- func (h *TnHistogram) Get_count() float64 { return float64(len(h.values)) }
472
- func (h *TnHistogram) Get_min() float64 {
473
- if len(h.values) == 0 {
474
- return 9223372036854776000
475
- }
476
- return h.sorted()[0]
477
- }
478
- func (h *TnHistogram) Get_max() float64 {
479
- if len(h.values) == 0 {
480
- return 0
481
- }
482
- s := h.sorted()
483
- return s[len(s)-1]
484
- }
485
- func (h *TnHistogram) Get_mean() float64 {
486
- if len(h.values) == 0 {
487
- return math.NaN()
488
- }
489
- sum := 0.0
490
- for _, v := range h.values {
491
- sum += v
492
- }
493
- return sum / float64(len(h.values))
494
- }
495
- func (h *TnHistogram) Get_stddev() float64 {
496
- if len(h.values) == 0 {
497
- return math.NaN()
498
- }
499
- mean := h.Get_mean()
500
- sum := 0.0
501
- for _, v := range h.values {
502
- sum += (v - mean) * (v - mean)
503
- }
504
- return math.Sqrt(sum / float64(len(h.values)))
505
- }
506
- func (h *TnHistogram) Get_exceeds() float64 { return h.exceeds }
507
-
508
- func (h *TnHistogram) percentile(p float64) float64 {
509
- if len(h.values) == 0 {
510
- return 0
511
- }
512
- s := h.sorted()
513
- i := int(math.Ceil(p/100*float64(len(s)))) - 1
514
- if i < 0 {
515
- i = 0
516
- }
517
- if i >= len(s) {
518
- i = len(s) - 1
519
- }
520
- return s[i]
521
- }
522
-
523
- func (h *TnHistogram) Get_percentiles() *TnMap[float64, float64] {
524
- m := TnNewMap[float64, float64]()
525
- for _, p := range []float64{0, 50, 75, 87.5, 93.75, 96.875, 98.4375, 99.21875, 100} {
526
- m.Set(p, h.percentile(p))
527
- }
528
- return m
529
- }
530
-
531
- // Node 26 histogram statistics over the recorded values
532
- func (h *TnHistogram) countAt(v float64) float64 {
533
- n := 0
534
- for _, x := range h.values {
535
- if x == v {
536
- n++
537
- }
538
- }
539
- return float64(n)
540
- }
541
-
542
- // cdf(v): the share of values at or below v; ccdf(v): above it
543
- func (h *TnHistogram) cdf(v float64) float64 {
544
- if len(h.values) == 0 {
545
- return 0
546
- }
547
- n := 0
548
- for _, x := range h.values {
549
- if x <= v {
550
- n++
551
- }
552
- }
553
- return float64(n) / float64(len(h.values))
554
- }
555
-
556
- func (h *TnHistogram) ccdf(v float64) float64 {
557
- if len(h.values) == 0 {
558
- return 0
559
- }
560
- return 1 - h.cdf(v)
561
- }
562
-
563
- // The population's central moments m2, m3, m4
564
- func (h *TnHistogram) moments() (float64, float64, float64) {
565
- n := float64(len(h.values))
566
- if n == 0 {
567
- return 0, 0, 0
568
- }
569
- mean := h.Get_mean()
570
- var m2, m3, m4 float64
571
- for _, x := range h.values {
572
- d := x - mean
573
- m2 += d * d
574
- m3 += d * d * d
575
- m4 += d * d * d * d
576
- }
577
- return m2 / n, m3 / n, m4 / n
578
- }
579
-
580
- func (h *TnHistogram) Get_skewness() float64 {
581
- m2, m3, _ := h.moments()
582
- if m2 == 0 {
583
- return 0
584
- }
585
- return m3 / math.Pow(m2, 1.5)
586
- }
587
-
588
- // kurtosis: the excess kurtosis (a normal distribution's is 0)
589
- func (h *TnHistogram) Get_kurtosis() float64 {
590
- m2, _, m4 := h.moments()
591
- if m2 == 0 {
592
- return 0
593
- }
594
- return m4/(m2*m2) - 3
595
- }
596
-
597
- // recordCorrected(value, expectedInterval): the samples a stalled recorder
598
- // missed are added too (value - interval, value - 2·interval, …)
599
- func (h *TnHistogram) recordCorrected(value interface{}, interval float64) {
600
- h.record(value)
601
- v, ok := value.(float64)
602
- if !ok || interval <= 0 {
603
- return
604
- }
605
- for missing := v - interval; missing >= interval; missing -= interval {
606
- h.values = append(h.values, missing)
607
- }
608
- }
609
-
610
- // add(other) / subtract(other): other's values merged in or taken out
611
- func (h *TnHistogram) add(other *TnHistogram) {
612
- h.values = append(h.values, other.values...)
613
- h.exceeds += other.exceeds
614
- }
615
-
616
- func (h *TnHistogram) subtract(other *TnHistogram) {
617
- for _, v := range other.values {
618
- for i, x := range h.values {
619
- if x == v {
620
- h.values = append(h.values[:i], h.values[i+1:]...)
621
- break
622
- }
623
- }
624
- }
625
- }
626
-
627
- // snapshot(): the statistics as a plain object
628
- func (h *TnHistogram) snapshot() *TnMap[string, interface{}] {
629
- m := TnNewMap[string, interface{}]()
630
- m.Set("count", h.Get_count())
631
- m.Set("min", h.Get_min())
632
- m.Set("max", h.Get_max())
633
- m.Set("mean", h.Get_mean())
634
- m.Set("exceeds", h.Get_exceeds())
635
- m.Set("stddev", h.Get_stddev())
636
- m.Set("skewness", h.Get_skewness())
637
- m.Set("kurtosis", h.Get_kurtosis())
638
- percentiles := TnNewMap[string, interface{}]()
639
- pm := h.Get_percentiles()
640
- for _, k := range pm.Keys() {
641
- percentiles.Set(TnNumStr(k), pm.Get(k))
642
- }
643
- m.Set("percentiles", percentiles)
644
- return m
645
- }
646
-
647
- func (h *TnHistogram) reset() {
648
- h.values = nil
649
- h.exceeds = 0
650
- }
651
-
652
- // monitorEventLoopDelay({ resolution }): samples how late a timer fires on the loop
653
- func TnMonitorEventLoopDelay(options ...interface{}) *TnHistogram {
654
- h := &TnHistogram{interval: 10}
655
- if len(options) > 0 && options[0] != nil {
656
- if n, ok := TnGetValue(options[0], "resolution").(float64); ok && n > 0 {
657
- h.interval = n
658
- }
659
- }
660
- return h
661
- }
662
-
663
- func (h *TnHistogram) enable() bool {
664
- if h.enabled {
665
- return false
666
- }
667
- h.enabled = true
668
- h.stop = make(chan struct{})
669
- stop := h.stop
670
- period := time.Duration(h.interval * float64(time.Millisecond))
671
- go func() {
672
- ticker := time.NewTicker(period)
673
- defer ticker.Stop()
674
- for {
675
- select {
676
- case <-stop:
677
- return
678
- case expected := <-ticker.C:
679
- TnLoopPost(func() {
680
- if h.enabled {
681
- h.values = append(h.values, math.Max(float64(time.Since(expected).Nanoseconds()), 1))
682
- }
683
- })
684
- }
685
- }
686
- }()
687
- return true
688
- }
689
-
690
- func (h *TnHistogram) disable() bool {
691
- if !h.enabled {
692
- return false
693
- }
694
- h.enabled = false
695
- close(h.stop)
696
- return true
697
- }
698
-
699
436
  // eventLoopUtilization(): idle / active time of the loop (approximate: CPU time)
700
437
  type TnLoopUtilization struct {
701
438
  idle float64
@@ -765,7 +502,7 @@ export function registerSystemExtra(r) {
765
502
  defineHelper(r, 'nodeSystemOS@windows', ['syscall', 'unsafe'], [], windowsSystemHelper);
766
503
  defineHelper(r, 'nodeSystemOS@other', [], [], otherSystemHelper);
767
504
  defineHelper(r, 'nodeSystem', ['math', 'os', 'os/exec', 'runtime', 'runtime/metrics', 'strconv', 'strings', 'time'], ['nodeSystemOS@os'], systemHelper);
768
- defineHelper(r, 'nodePerfExtra', ['math', 'math/big', 'reflect', 'sort', 'time'], ['nodePerf', 'nodeSystem', 'eventLoop', 'nodeInvoke', 'dynamic', 'orderedMap'], perfExtraHelper);
505
+ defineHelper(r, 'nodePerfExtra', ['math', 'reflect', 'sort'], ['nodePerf', 'nodeSystem', 'eventLoop', 'nodeInvoke', 'dynamic'], perfExtraHelper);
769
506
  // uncaught exception capture callbacks
770
507
  r.functions['process.setUncaughtExceptionCaptureCallback'] = (c) => {
771
508
  r.helper('nodeUncaught');
@@ -845,12 +582,8 @@ export function registerSystemExtra(r) {
845
582
  return 'TnPerfObservedTypes()';
846
583
  };
847
584
  r.valueTypes['perf_hooks.PerformanceObserver.supportedEntryTypes'] = '[]string';
848
- defineClass(r, 'perf_hooks.Histogram', '*TnHistogram', 'class', 'record=; recordDelta=; recordCorrected=; percentile=float64; reset=; enable=bool; disable=bool; countAt=float64; cdf=float64; ccdf=float64; add=; subtract=; snapshot=*TnMap[string, interface{}]', '', 'count=float64; min=float64; max=float64; mean=float64; stddev=float64; exceeds=float64; percentiles=*TnMap[float64, float64]; skewness=float64; kurtosis=float64', '');
849
- for (const name of ['RecordableHistogram', 'IntervalHistogram'])
850
- r.classes[`perf_hooks.${name}`] = r.classes['perf_hooks.Histogram'];
585
+ registerHistogram(r);
851
586
  defineClass(r, 'perf_hooks.EventLoopUtilization', '*TnLoopUtilization', 'class', '', 'idle=float64; active=float64; utilization=float64', '', '');
852
- fn('perf_hooks.createHistogram', '*TnHistogram', 'nodePerfExtra', (c) => `TnCreateHistogram(${c.args.join(', ')})`);
853
- fn('perf_hooks.monitorEventLoopDelay', '*TnHistogram', 'nodePerfExtra', (c) => `TnMonitorEventLoopDelay(${c.args.join(', ')})`);
854
587
  for (const key of [...perf('performance.timerify'), 'perf_hooks.timerify']) {
855
588
  r.functions[key] = (c) => {
856
589
  r.helper('nodePerfExtra');
package/bin/node/test.js CHANGED
@@ -49,6 +49,7 @@ var tnTestRunning *TnTestNode
49
49
  var tnTestScheduled bool
50
50
  var tnTestStart float64
51
51
  var tnTestCounts = map[string]int{}
52
+ var tnTestInterrupted sync.Once
52
53
 
53
54
  // Hooks of the optional parts: a run() child sends its events to the parent;
54
55
  // coverage and snapshots finish when the run does
@@ -770,12 +771,49 @@ func tnTestNote(nesting int, message string, level string, n *TnTestNode) *TnTes
770
771
  return &TnTestEvent{type_: "test:diagnostic", data: d}
771
772
  }
772
773
 
774
+ func tnFindRunningTests(n *TnTestNode, depth int) []*TnTestEventData {
775
+ var out []*TnTestEventData
776
+ for _, child := range n.children {
777
+ if child.started && child.status == "" {
778
+ sub := tnFindRunningTests(child, depth+1)
779
+ if len(sub) > 0 {
780
+ out = append(out, sub...)
781
+ } else {
782
+ out = append(out, &TnTestEventData{
783
+ name: child.name,
784
+ nesting: float64(depth),
785
+ file: child.file,
786
+ line: child.line,
787
+ column: child.column,
788
+ })
789
+ }
790
+ }
791
+ }
792
+ return out
793
+ }
794
+
773
795
  func tnRunRoot() {
774
796
  tnTestStart = tnTestNow()
775
797
  cfg := tnTestFilters()
776
798
  for _, s := range tnTestSinks {
777
799
  s.write(s.reporter.begin())
778
800
  }
801
+ onInterrupt := func(args ...interface{}) {
802
+ tnTestInterrupted.Do(func() {
803
+ running := tnFindRunningTests(tnTestRoot, 0)
804
+ if len(running) > 0 {
805
+ tnTestEmit(&TnTestEvent{type_: "test:interrupted", data: &TnTestEventData{tests: running}})
806
+ }
807
+ for _, s := range tnTestSinks {
808
+ if s.file {
809
+ s.out.Close()
810
+ }
811
+ }
812
+ os.Exit(1)
813
+ })
814
+ }
815
+ TnProcessOn("SIGINT", onInterrupt, true)
816
+ defer tnProcessEmitter.off("SIGINT", onInterrupt)
779
817
  root := tnTestRoot
780
818
  if cfg.active() {
781
819
  tnTestPrune(root)
@@ -1668,7 +1706,7 @@ function eventFn(nodes) {
1668
1706
  }
1669
1707
  export function registerTest(r) {
1670
1708
  defineModule(r, 'test');
1671
- defineHelper(r, 'nodeTest', ['crypto/rand', 'fmt', 'math', 'os', 'path/filepath', 'reflect', 'regexp', 'strconv', 'strings', 'time'], ['eventLoop', 'promise', 'nodeInvoke', 'dynamic', 'nodeEvents', 'nodeProcess', 'nodeUtil', 'nodeAssert', 'arraySubclass', 'error', 'timerWait', 'clock', 'nodeTestReport', 'nodeTestClock@os'], testHelper);
1709
+ defineHelper(r, 'nodeTest', ['crypto/rand', 'fmt', 'math', 'os', 'path/filepath', 'reflect', 'regexp', 'strconv', 'strings', 'sync', 'time'], ['eventLoop', 'promise', 'nodeInvoke', 'dynamic', 'nodeEvents', 'nodeProcess', 'nodeUtil', 'nodeAssert', 'arraySubclass', 'error', 'timerWait', 'clock', 'nodeTestReport', 'nodeTestClock@os'], testHelper);
1672
1710
  defineHelper(r, 'nodeTestSnapshot', ['fmt', 'os', 'path/filepath', 'sort', 'strconv', 'strings'], ['nodeTest', 'nodeAssert', 'jsonStringify'], snapshotHelper);
1673
1711
  registerTestReporters(r);
1674
1712
  registerTestRun(r);
@@ -31,6 +31,7 @@ type TnTestEventData struct {
31
31
  duration_ms float64
32
32
  success bool
33
33
  summary *TnCoverageSummary
34
+ tests []*TnTestEventData
34
35
  }
35
36
 
36
37
  type TnTestEventDetails struct {
@@ -186,6 +187,24 @@ func tnTestEventOf(v interface{}) *TnTestEvent {
186
187
  if s := TnGet(raw, "summary"); s != nil {
187
188
  d.summary = tnCoverageSummaryOf(s)
188
189
  }
190
+ if tests := tnTestList(TnGet(raw, "tests")); tests != nil {
191
+ for _, item := range tests {
192
+ if item == nil {
193
+ continue
194
+ }
195
+ if typed, ok := item.(*TnTestEventData); ok {
196
+ d.tests = append(d.tests, typed)
197
+ } else {
198
+ d.tests = append(d.tests, &TnTestEventData{
199
+ name: tnTestStr(TnGet(item, "name")),
200
+ nesting: tnTestNum(TnGet(item, "nesting")),
201
+ file: tnTestStr(TnGet(item, "file")),
202
+ line: tnTestNum(TnGet(item, "line")),
203
+ column: tnTestNum(TnGet(item, "column")),
204
+ })
205
+ }
206
+ }
207
+ }
189
208
  return e
190
209
  }
191
210
 
@@ -420,6 +439,14 @@ func (r *tnTapReporter) report(e *TnTestEvent) string {
420
439
  if d.summary != nil {
421
440
  out += tnCoverageReport(indent, d.summary, "# ", "", tnTestPalette{}, true)
422
441
  }
442
+ case "test:interrupted":
443
+ for _, t := range d.tests {
444
+ msg := "Interrupted while running: " + t.name
445
+ if t.file != "" {
446
+ msg += " at " + t.file + ":" + TnNumStr(t.line) + ":" + TnNumStr(t.column)
447
+ }
448
+ out += "# " + tnTapEscape(msg) + "\\n"
449
+ }
423
450
  }
424
451
  return out
425
452
  }
@@ -677,6 +704,25 @@ func (r *tnSpecReporter) report(e *TnTestEvent) string {
677
704
  if d.file == "" {
678
705
  return r.failures()
679
706
  }
707
+ case "test:interrupted":
708
+ if len(d.tests) == 0 {
709
+ return ""
710
+ }
711
+ lines := []string{"\\n" + r.p.yellow() + "Interrupted while running:" + r.p.white() + "\\n"}
712
+ for _, t := range d.tests {
713
+ msg := tnSpecIndent(t.nesting) + "\\u26a0 " + t.name
714
+ if t.file != "" {
715
+ rel := t.file
716
+ if r.cwd != "" {
717
+ if p, err := filepath.Rel(r.cwd, t.file); err == nil {
718
+ rel = p
719
+ }
720
+ }
721
+ msg += " " + r.p.gray() + "(" + rel + ":" + TnNumStr(t.line) + ":" + TnNumStr(t.column) + ")" + r.p.white()
722
+ }
723
+ lines = append(lines, msg)
724
+ }
725
+ return strings.Join(lines, "\\n") + "\\n"
680
726
  }
681
727
  return ""
682
728
  }
@@ -1347,7 +1393,7 @@ func tnTestNow() float64 { return float64(time.Since(tnTestEpoch).Nanoseconds())
1347
1393
  const use = () => r.helper('nodeTestReporters');
1348
1394
  // Event data, for typed reads in run() listeners (stream.on('test:pass', (data) => …))
1349
1395
  defineClass(r, 'test.TestEvent', '*TnTestEvent', 'class', '', 'data=*TnTestEventData', 'type=string', '');
1350
- defineClass(r, 'test.TestEventData', '*TnTestEventData', 'class', '', 'name=string; nesting=float64; testNumber=float64; details=*TnTestEventDetails; skip=interface{}; todo=interface{}; file=string; line=float64; column=float64; count=float64; message=string; level=string; counts=*TnTestCounts; duration_ms=float64; success=bool; summary=*TnCoverageSummary', '', '');
1396
+ defineClass(r, 'test.TestEventData', '*TnTestEventData', 'class', '', 'name=string; nesting=float64; testNumber=float64; details=*TnTestEventDetails; skip=interface{}; todo=interface{}; file=string; line=float64; column=float64; count=float64; message=string; level=string; counts=*TnTestCounts; duration_ms=float64; success=bool; summary=*TnCoverageSummary; tests=[]*TnTestEventData', '', '');
1351
1397
  defineClass(r, 'test.TestEventDetails', '*TnTestEventDetails', 'class', '', 'duration_ms=float64; passed=bool', 'type=string; error=interface{}', '');
1352
1398
  defineClass(r, 'test.TestCounts', '*TnTestCounts', 'class', '', 'tests=float64; failed=float64; passed=float64; cancelled=float64; skipped=float64; todo=float64; topLevel=float64; suites=float64', '', '');
1353
1399
  const counts = 'totalLineCount=float64; totalBranchCount=float64; totalFunctionCount=float64; coveredLineCount=float64; coveredBranchCount=float64; coveredFunctionCount=float64; coveredLinePercent=float64; coveredBranchPercent=float64; coveredFunctionPercent=float64';
@@ -40,8 +40,10 @@ func tnTestWriteFrame(e *TnTestEvent) {
40
40
  }
41
41
 
42
42
  type tnTestRunFile struct {
43
- entry string
44
- path string
43
+ entry string
44
+ path string
45
+ cmd *exec.Cmd
46
+ started bool
45
47
  // events held back while an earlier file is still reporting
46
48
  held []*TnTestEvent
47
49
  finished bool
@@ -64,6 +66,8 @@ type tnTestRun struct {
64
66
  coverage []*TnCoverageSummary
65
67
  start time.Time
66
68
  success bool
69
+ interrupted bool
70
+ onInterrupt interface{}
67
71
  }
68
72
 
69
73
  // run(options): files pairs each entry id with the file's path
@@ -89,6 +93,10 @@ func TnTestRun(options interface{}, files ...[]string) *TnStream {
89
93
  if r.concurrency < 1 {
90
94
  r.concurrency = 1
91
95
  }
96
+ r.onInterrupt = func(args ...interface{}) {
97
+ r.interrupt()
98
+ }
99
+ TnProcessOn("SIGINT", r.onInterrupt, true)
92
100
  TnLoopRef()
93
101
  TnLoopPost(func() {
94
102
  if options != nil {
@@ -102,6 +110,37 @@ func TnTestRun(options interface{}, files ...[]string) *TnStream {
102
110
  return s
103
111
  }
104
112
 
113
+ func (r *tnTestRun) interrupt() {
114
+ if r.interrupted {
115
+ return
116
+ }
117
+ r.interrupted = true
118
+ if r.onInterrupt != nil {
119
+ tnProcessEmitter.off("SIGINT", r.onInterrupt)
120
+ r.onInterrupt = nil
121
+ }
122
+ var running []*TnTestEventData
123
+ for _, f := range r.files {
124
+ if f.started && !f.finished {
125
+ running = append(running, &TnTestEventData{
126
+ name: f.path,
127
+ nesting: 0,
128
+ file: f.path,
129
+ line: 1,
130
+ column: 1,
131
+ })
132
+ if f.cmd != nil && f.cmd.Process != nil {
133
+ f.cmd.Process.Kill()
134
+ }
135
+ }
136
+ }
137
+ if len(running) > 0 {
138
+ r.emit(&TnTestEvent{type_: "test:interrupted", data: &TnTestEventData{tests: running}})
139
+ }
140
+ r.stream.push(nil)
141
+ TnLoopUnref()
142
+ }
143
+
105
144
  func (r *tnTestRun) emit(e *TnTestEvent) {
106
145
  r.stream.push(e)
107
146
  r.stream.emit(e.type_, e.data)
@@ -183,6 +222,9 @@ func (r *tnTestRun) fill() {
183
222
 
184
223
  // Events of the file reporting now are relayed at once; later files' wait
185
224
  func (r *tnTestRun) deliver(f *tnTestRunFile, e *TnTestEvent) {
225
+ if r.interrupted {
226
+ return
227
+ }
186
228
  if r.reporting < len(r.files) && r.files[r.reporting] == f {
187
229
  r.relay(f, e)
188
230
  return
@@ -254,6 +296,8 @@ func (r *tnTestRun) startFile(f *tnTestRunFile) {
254
296
  r.fileDone(f, 1, "")
255
297
  return
256
298
  }
299
+ f.started = true
300
+ f.cmd = cmd
257
301
  r.emit(&TnTestEvent{type_: "test:dequeue", data: &TnTestEventData{name: f.path, file: f.path, line: 1, column: 1}})
258
302
  var timer *time.Timer
259
303
  if r.options != nil {
@@ -315,6 +359,10 @@ func (r *tnTestRun) startFile(f *tnTestRunFile) {
315
359
  // A child exited: its file's summary (or a failure when it crashed), then
316
360
  // the next files' held events
317
361
  func (r *tnTestRun) fileDone(f *tnTestRunFile, code int, signal string) {
362
+ f.cmd = nil
363
+ if r.interrupted {
364
+ return
365
+ }
318
366
  f.exitCode, f.signal = code, signal
319
367
  r.running--
320
368
  r.drain()
@@ -385,6 +433,13 @@ func (r *tnTestRun) closeFile(f *tnTestRunFile) {
385
433
  }
386
434
 
387
435
  func (r *tnTestRun) finish() {
436
+ if r.interrupted {
437
+ return
438
+ }
439
+ if r.onInterrupt != nil {
440
+ tnProcessEmitter.off("SIGINT", r.onInterrupt)
441
+ r.onInterrupt = nil
442
+ }
388
443
  r.emit(&TnTestEvent{type_: "test:plan", data: &TnTestEventData{count: r.topLevel}})
389
444
  c := r.counts
390
445
  duration := math.Round(float64(time.Since(r.start).Nanoseconds())/1e2) / 1e4
package/bin/node/util.js CHANGED
@@ -1340,18 +1340,21 @@ func TnCallbackify(fn interface{}) func(args ...interface{}) {
1340
1340
  v, ok := result.Recv()
1341
1341
  var reason interface{}
1342
1342
  rejected := false
1343
+ var value interface{}
1343
1344
  if !ok {
1344
- reason, rejected = tnRejections.Load(result.Interface())
1345
+ if resolved, hasVal := tnResolved.Load(result.Interface()); hasVal {
1346
+ value = resolved
1347
+ } else {
1348
+ reason, rejected = tnRejections.Load(result.Interface())
1349
+ }
1350
+ } else if v.IsValid() {
1351
+ value = v.Interface()
1345
1352
  }
1346
1353
  TnLoopPost(func() {
1347
1354
  if rejected {
1348
1355
  TnInvoke(cb, reason)
1349
1356
  return
1350
1357
  }
1351
- var value interface{}
1352
- if v.IsValid() {
1353
- value = v.Interface()
1354
- }
1355
1358
  TnInvoke(cb, nil, value)
1356
1359
  })
1357
1360
  }()
@@ -956,7 +956,12 @@ func tnWasmResponseBytes[T any](r *TnResponse, out chan T, deliver func([]byte))
956
956
  failure = rec
957
957
  }
958
958
  }()
959
- data = <-body
959
+ v, reason, rejected := tnSettle(body)
960
+ if rejected {
961
+ failure = reason
962
+ return
963
+ }
964
+ data = v
960
965
  }()
961
966
  TnLoopPost(func() {
962
967
  if failure != nil {
@@ -986,7 +991,12 @@ func tnWasmStreamingValue[T any](v interface{}, out chan T, deliver func([]byte)
986
991
  TnLoopRef()
987
992
  go func() {
988
993
  defer TnLoopUnref()
989
- tnWasmStreamingValue(<-s, out, deliver)
994
+ val, reason, rejected := tnSettle(s)
995
+ if rejected {
996
+ TnReject(out, reason)
997
+ return
998
+ }
999
+ tnWasmStreamingValue(val, out, deliver)
990
1000
  }()
991
1001
  default:
992
1002
  TnReject(out, tnWasmStreamingTypeError(v))
@@ -1005,7 +1015,12 @@ func tnWasmStreamingBytes[T any](src interface{}, out chan T, deliver func([]byt
1005
1015
  TnLoopRef()
1006
1016
  go func() {
1007
1017
  defer TnLoopUnref()
1008
- tnWasmResponseBytes(<-s, out, deliver)
1018
+ val, reason, rejected := tnSettle(s)
1019
+ if rejected {
1020
+ TnReject(out, reason)
1021
+ return
1022
+ }
1023
+ tnWasmResponseBytes(val, out, deliver)
1009
1024
  }()
1010
1025
  case chan interface{}:
1011
1026
  tnWasmStreamingValue(s, out, deliver)
@@ -1017,7 +1032,7 @@ func tnWasmStreamingBytes[T any](src interface{}, out chan T, deliver func([]byt
1017
1032
  func TnWasmCompileStreaming(src interface{}) chan *TnWasmModule {
1018
1033
  ch := make(chan *TnWasmModule, 1)
1019
1034
  tnWasmStreamingBytes(src, ch, func(b []byte) {
1020
- ch <- TnNewWasmModule(b)
1035
+ TnAsyncSend(ch, TnNewWasmModule(b))
1021
1036
  })
1022
1037
  return ch
1023
1038
  }
@@ -1026,7 +1041,7 @@ func TnWasmInstantiateStreaming(src interface{}, importObject ...interface{}) ch
1026
1041
  ch := make(chan *TnWasmInstantiated, 1)
1027
1042
  tnWasmStreamingBytes(src, ch, func(b []byte) {
1028
1043
  m := TnNewWasmModule(b)
1029
- ch <- &TnWasmInstantiated{module: m, instance: TnNewWasmInstance(m, importObject...)}
1044
+ TnAsyncSend(ch, &TnWasmInstantiated{module: m, instance: TnNewWasmInstance(m, importObject...)})
1030
1045
  })
1031
1046
  return ch
1032
1047
  }`;