typenative 0.4.1 → 0.5.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.
Files changed (151) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/README.md +62 -22
  3. package/ROUND2-HANDOFF.md +200 -0
  4. package/bin/cli.js +1 -0
  5. package/bin/index.js +13 -2
  6. package/bin/main.js +1 -0
  7. package/bin/node/assert.js +2 -2
  8. package/bin/node/async_hooks.js +1 -1
  9. package/bin/node/buffer.js +16 -5
  10. package/bin/node/child_process.js +7 -7
  11. package/bin/node/cluster.js +3 -3
  12. package/bin/node/crypto_keys.js +21 -21
  13. package/bin/node/dgram.js +1 -1
  14. package/bin/node/diagnostics_channel.js +3 -3
  15. package/bin/node/dns.js +2 -2
  16. package/bin/node/events.js +3 -3
  17. package/bin/node/fetch.js +2 -2
  18. package/bin/node/fs.js +3 -3
  19. package/bin/node/fs_watch.js +5 -5
  20. package/bin/node/http.js +3 -3
  21. package/bin/node/http2.js +3 -3
  22. package/bin/node/net.js +8 -8
  23. package/bin/node/path.js +17 -3
  24. package/bin/node/process.js +34 -11
  25. package/bin/node/readline.js +1 -1
  26. package/bin/node/registry.js +4 -1
  27. package/bin/node/sqlite.js +6 -6
  28. package/bin/node/stream.js +81 -15
  29. package/bin/node/stream_web.js +10 -10
  30. package/bin/node/system_extra.js +3 -3
  31. package/bin/node/test.js +674 -366
  32. package/bin/node/test_coverage.js +187 -0
  33. package/bin/node/test_report.js +1392 -0
  34. package/bin/node/test_run.js +575 -0
  35. package/bin/node/timers.js +4 -4
  36. package/bin/node/tls.js +5 -5
  37. package/bin/node/util.js +31 -7
  38. package/bin/node/util_extra.js +7 -7
  39. package/bin/node/webview.js +654 -0
  40. package/bin/node/worker_threads.js +1 -1
  41. package/bin/node/zlib.js +3 -3
  42. package/bin/parse-node.js +4 -0
  43. package/bin/transpiler.js +10390 -1178
  44. package/bin/version.js +1 -1
  45. package/conformance.md +468 -340
  46. package/examples/README.md +47 -10
  47. package/examples/desktop-notes/README.md +108 -0
  48. package/examples/desktop-notes/bench.mjs +125 -0
  49. package/examples/desktop-notes/main.ts +131 -0
  50. package/examples/desktop-notes/package-lock.json +726 -0
  51. package/examples/desktop-notes/package.json +9 -0
  52. package/examples/desktop-notes/ui.ts +176 -0
  53. package/examples/dupe-finder/README.md +76 -0
  54. package/examples/dupe-finder/bench.mjs +120 -0
  55. package/examples/dupe-finder/main.ts +87 -0
  56. package/examples/mandelbrot-png/README.md +65 -0
  57. package/examples/mandelbrot-png/bench.mjs +95 -0
  58. package/examples/mandelbrot-png/main.ts +98 -0
  59. package/examples/mandelbrot-png/preview.png +0 -0
  60. package/examples/marked-cli/README.md +159 -0
  61. package/examples/marked-cli/bench.mjs +178 -0
  62. package/examples/marked-cli/main.ts +292 -0
  63. package/examples/marked-cli/parity.mjs +185 -0
  64. package/examples/marked-cli/vendor/marked/LICENSE +44 -0
  65. package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
  66. package/examples/todo-cli/README.md +69 -0
  67. package/examples/todo-cli/bench.mjs +89 -0
  68. package/examples/todo-cli/main.ts +92 -0
  69. package/examples/yaml-cli/README.md +136 -0
  70. package/examples/yaml-cli/bench.mjs +265 -0
  71. package/examples/yaml-cli/main.ts +29 -0
  72. package/examples/yaml-cli/parity.mjs +156 -0
  73. package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
  74. package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
  75. package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
  76. package/govendor/github.com/jchv/go-webview2/README.md +21 -0
  77. package/govendor/github.com/jchv/go-webview2/common.go +84 -0
  78. package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
  79. package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
  80. package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
  81. package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
  82. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
  83. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
  84. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
  85. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
  86. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
  87. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
  88. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
  89. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
  90. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
  91. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
  92. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
  93. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
  94. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
  95. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
  96. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
  97. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
  98. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
  99. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
  100. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
  101. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
  102. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
  103. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
  104. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
  105. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
  106. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
  107. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
  108. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
  109. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
  110. package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
  111. package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
  112. package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
  113. package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
  114. package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
  115. package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
  116. package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
  117. package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
  118. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
  119. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
  120. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
  121. package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
  122. package/govendor/github.com/jchv/go-winloader/README.md +124 -0
  123. package/govendor/github.com/jchv/go-winloader/common.go +11 -0
  124. package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
  125. package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
  126. package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
  127. package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
  128. package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
  129. package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
  130. package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
  131. package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
  132. package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
  133. package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
  134. package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
  135. package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
  136. package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
  137. package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
  138. package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
  139. package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
  140. package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
  141. package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
  142. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
  143. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
  144. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
  145. package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
  146. package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
  147. package/govendor/manifest.txt +3 -1
  148. package/package.json +1 -1
  149. package/tsparser/main.go +4 -0
  150. package/types/typenative-npm.d.ts +190 -2
  151. package/types/typenative.d.ts +98 -31
@@ -425,12 +425,16 @@ func TnBufferWriteFloat(b []byte, value float64, offset float64, size int, littl
425
425
  return float64(o + size)
426
426
  }
427
427
 
428
- func TnBufferToJSON(b []byte) map[string]interface{} {
428
+ // { type: 'Buffer', data: [...] }, in that key order
429
+ func TnBufferToJSON(b []byte) *TnMap[string, interface{}] {
429
430
  data := make([]interface{}, len(b))
430
431
  for i, c := range b {
431
432
  data[i] = float64(c)
432
433
  }
433
- return map[string]interface{}{"type": "Buffer", "data": data}
434
+ m := TnNewMap[string, interface{}]()
435
+ m.Set("type", "Buffer")
436
+ m.Set("data", data)
437
+ return m
434
438
  }
435
439
 
436
440
  // <Buffer 68 69>, as console.log / util.inspect show a Buffer
@@ -513,7 +517,7 @@ func (d *TnTextDecoder) decode(args ...interface{}) string {
513
517
  }
514
518
  stream := false
515
519
  if len(args) > 1 && args[1] != nil {
516
- stream, _ = TnGet(args[1], "stream").(bool)
520
+ stream, _ = TnGetValue(args[1], "stream").(bool)
517
521
  }
518
522
  data := b
519
523
  if len(d.pending) > 0 {
@@ -588,7 +592,7 @@ function boundsArgs(call, from) {
588
592
  }
589
593
  export function registerBuffer(r) {
590
594
  defineModule(r, 'buffer');
591
- defineHelper(r, 'buffer', ['bytes', 'encoding/base64', 'encoding/binary', 'encoding/hex', 'fmt', 'math', 'math/big', 'strconv', 'strings', 'unicode/utf16', 'unicode/utf8'], ['error', 'dynamic'], bufferHelper);
595
+ defineHelper(r, 'buffer', ['bytes', 'encoding/base64', 'encoding/binary', 'encoding/hex', 'fmt', 'math', 'math/big', 'strconv', 'strings', 'unicode/utf16', 'unicode/utf8'], ['error', 'dynamic', 'orderedMap'], bufferHelper);
592
596
  // Uint8Array first: Buffer owns the []byte instance methods
593
597
  defineClass(r, 'globals.Uint8Array', '[]byte', 'Buffer', '', '', '', '');
594
598
  defineClass(r, 'buffer.Buffer', '[]byte', 'Buffer', '', '', '', '');
@@ -646,6 +650,12 @@ export function registerBuffer(r) {
646
650
  };
647
651
  setResults(r, 'buffer.Buffer', 'from=[]byte; alloc=[]byte; allocUnsafe=[]byte; allocUnsafeSlow=[]byte; concat=[]byte; byteLength=float64; isBuffer=bool; isEncoding=bool; compare=float64');
648
652
  r.results['globals.Uint8Array.from'] = '[]byte';
653
+ // Uint8Array.fromBase64(s) / u8.toBase64() (ES2026)
654
+ r.functions['globals.Uint8Array.fromBase64'] = (call) => {
655
+ use();
656
+ return `TnBufferFromString(${call.args[0]}, "base64")`;
657
+ };
658
+ r.results['globals.Uint8Array.fromBase64'] = '[]byte';
649
659
  r.functions['buffer.atob'] = (call) => {
650
660
  use();
651
661
  return `TnAtob(${call.args[0]})`;
@@ -726,7 +736,8 @@ export function registerBuffer(r) {
726
736
  r.results[`buffer.Buffer#${name}`] = result;
727
737
  };
728
738
  method('toString', 'string', (c) => `TnBufferToString(${c.recv}, ${encArg(c, 0)}${boundsArgs(c, 1)})`);
729
- method('toJSON', 'map[string]interface{}', (c) => `TnBufferToJSON(${c.recv})`);
739
+ method('toBase64', 'string', (c) => `TnBufferToString(${c.recv}, "base64")`);
740
+ method('toJSON', '*TnMap[string, interface{}]', (c) => `TnBufferToJSON(${c.recv})`);
730
741
  method('equals', 'bool', (c) => `bytes.Equal(${c.recv}, ${c.args[0]})`);
731
742
  method('compare', 'float64', (c) => `float64(bytes.Compare(${c.recv}, ${c.args[0]}))`);
732
743
  method('subarray', '[]byte', (c) => `TnBufferSlice(${c.recv}${boundsArgs(c, 0)})`);
@@ -49,25 +49,25 @@ func tnSpawnOpts(options []interface{}) tnSpawnOptions {
49
49
  return o
50
50
  }
51
51
  opts := options[0]
52
- if s, ok := TnGet(opts, "cwd").(string); ok {
52
+ if s, ok := TnGetValue(opts, "cwd").(string); ok {
53
53
  o.cwd = s
54
54
  }
55
55
  if env := TnGet(opts, "env"); env != nil {
56
56
  o.env = tnEnvList(env)
57
57
  }
58
- switch sh := TnGet(opts, "shell").(type) {
58
+ switch sh := TnGetValue(opts, "shell").(type) {
59
59
  case bool:
60
60
  o.shell = sh
61
61
  case string:
62
62
  o.shell = sh != ""
63
63
  }
64
- switch in := TnGet(opts, "input").(type) {
64
+ switch in := TnGetValue(opts, "input").(type) {
65
65
  case string:
66
66
  o.input = []byte(in)
67
67
  case []byte:
68
68
  o.input = in
69
69
  }
70
- switch st := TnGet(opts, "stdio").(type) {
70
+ switch st := TnGetValue(opts, "stdio").(type) {
71
71
  case string:
72
72
  o.stdio = st
73
73
  case []interface{}:
@@ -81,10 +81,10 @@ func tnSpawnOpts(options []interface{}) tnSpawnOptions {
81
81
  o.stdio = st[1]
82
82
  }
83
83
  }
84
- if e, ok := TnGet(opts, "encoding").(string); ok {
84
+ if e, ok := TnGetValue(opts, "encoding").(string); ok {
85
85
  o.encoding = e
86
86
  }
87
- if d, ok := TnGet(opts, "detached").(bool); ok {
87
+ if d, ok := TnGetValue(opts, "detached").(bool); ok {
88
88
  o.detached = d
89
89
  }
90
90
  return o
@@ -440,7 +440,7 @@ func tnExecCollect(cp *TnChildProcess, display string, encoding string, cb inter
440
440
 
441
441
  func tnExecEncoding(options []interface{}) string {
442
442
  if len(options) > 0 && options[0] != nil {
443
- if e, ok := TnGet(options[0], "encoding").(string); ok {
443
+ if e, ok := TnGetValue(options[0], "encoding").(string); ok {
444
444
  return e
445
445
  }
446
446
  }
@@ -232,11 +232,11 @@ func tnForkWith(argv []string, opts interface{}, extraEnv []string) *TnChildProc
232
232
  }
233
233
  }
234
234
  stdio := "inherit"
235
- if silent, _ := TnGet(opts, "silent").(bool); silent {
235
+ if silent, _ := TnGetValue(opts, "silent").(bool); silent {
236
236
  stdio = "pipe"
237
237
  }
238
238
  spawnOpts := map[string]interface{}{"env": envMap, "stdio": stdio}
239
- if cwd, ok := TnGet(opts, "cwd").(string); ok && cwd != "" {
239
+ if cwd, ok := TnGetValue(opts, "cwd").(string); ok && cwd != "" {
240
240
  spawnOpts["cwd"] = cwd
241
241
  }
242
242
  cp := TnSpawn(exe, argv, spawnOpts)
@@ -529,7 +529,7 @@ func (c *TnCluster) setupPrimary(settings ...interface{}) {
529
529
  }
530
530
  }
531
531
  }
532
- if b, ok := TnGet(s, "silent").(bool); ok {
532
+ if b, ok := TnGetValue(s, "silent").(bool); ok {
533
533
  c.silent = b
534
534
  }
535
535
  for _, key := range []string{"args", "silent", "exec", "execArgv", "cwd"} {
@@ -272,19 +272,19 @@ func tnReadKeyInput(v interface{}) tnKeyInput {
272
272
  if v == nil || TnIsNil(v) {
273
273
  panic(TnNodeError("TypeError", "ERR_INVALID_ARG_TYPE", "The \\"key\\" argument must be of type string or an instance of ArrayBuffer, Buffer, TypedArray, DataView, KeyObject, or CryptoKey. Received undefined"))
274
274
  }
275
- if f, ok := TnGet(v, "format").(string); ok && f != "" {
275
+ if f, ok := TnGetValue(v, "format").(string); ok && f != "" {
276
276
  in.format = f
277
277
  }
278
- if t, ok := TnGet(v, "type").(string); ok {
278
+ if t, ok := TnGetValue(v, "type").(string); ok {
279
279
  in.typ = t
280
280
  }
281
- switch k := TnGet(v, "key").(type) {
281
+ switch k := TnGetValue(v, "key").(type) {
282
282
  case *TnKeyObject:
283
283
  in.object = k
284
284
  case *TnCryptoKey:
285
285
  in.object = k.key
286
286
  case string:
287
- enc, _ := TnGet(v, "encoding").(string)
287
+ enc, _ := TnGetValue(v, "encoding").(string)
288
288
  if enc != "" && in.format != "pem" {
289
289
  in.data = TnBufferFromString(k, enc)
290
290
  } else {
@@ -577,7 +577,7 @@ func tnJWK(pub tncrypto.PublicKey, priv tncrypto.PrivateKey) map[string]interfac
577
577
  }
578
578
 
579
579
  func tnJWKBytes(jwk interface{}, key string) []byte {
580
- s, _ := TnGet(jwk, key).(string)
580
+ s, _ := TnGetValue(jwk, key).(string)
581
581
  if s == "" {
582
582
  return nil
583
583
  }
@@ -604,7 +604,7 @@ func tnBigFrom(b []byte) *tnbig.Int { return new(tnbig.Int).SetBytes(b) }
604
604
 
605
605
  // Keys from a JWK object (RSA, EC, OKP Ed25519 / X25519)
606
606
  func tnKeyFromJWK(jwk interface{}) (tncrypto.PublicKey, tncrypto.PrivateKey) {
607
- kty, _ := TnGet(jwk, "kty").(string)
607
+ kty, _ := TnGetValue(jwk, "kty").(string)
608
608
  switch kty {
609
609
  case "RSA":
610
610
  pub := &rsa.PublicKey{N: tnBigFrom(tnJWKBytes(jwk, "n")), E: int(tnBigFrom(tnJWKBytes(jwk, "e")).Int64())}
@@ -616,7 +616,7 @@ func tnKeyFromJWK(jwk interface{}) (tncrypto.PublicKey, tncrypto.PrivateKey) {
616
616
  priv.Precompute()
617
617
  return &priv.PublicKey, priv
618
618
  case "EC":
619
- crv, _ := TnGet(jwk, "crv").(string)
619
+ crv, _ := TnGetValue(jwk, "crv").(string)
620
620
  pub := &ecdsa.PublicKey{Curve: tnNamedCurve(crv), X: tnBigFrom(tnJWKBytes(jwk, "x")), Y: tnBigFrom(tnJWKBytes(jwk, "y"))}
621
621
  d := tnJWKBytes(jwk, "d")
622
622
  if d == nil {
@@ -625,7 +625,7 @@ func tnKeyFromJWK(jwk interface{}) (tncrypto.PublicKey, tncrypto.PrivateKey) {
625
625
  priv := &ecdsa.PrivateKey{PublicKey: *pub, D: tnBigFrom(d)}
626
626
  return &priv.PublicKey, priv
627
627
  case "OKP":
628
- crv, _ := TnGet(jwk, "crv").(string)
628
+ crv, _ := TnGetValue(jwk, "crv").(string)
629
629
  x, d := tnJWKBytes(jwk, "x"), tnJWKBytes(jwk, "d")
630
630
  switch crv {
631
631
  case "Ed25519":
@@ -662,8 +662,8 @@ func tnKeyEncodingError(typ string) *TnError {
662
662
  // export({ format: 'pem' | 'der' | 'jwk', type: 'spki' | 'pkcs1' | 'pkcs8' | 'sec1' })
663
663
  func (k *TnKeyObject) export(options ...interface{}) interface{} {
664
664
  opts := tnCryptoArg(options)
665
- format, _ := TnGet(opts, "format").(string)
666
- typ, _ := TnGet(opts, "type").(string)
665
+ format, _ := TnGetValue(opts, "format").(string)
666
+ typ, _ := TnGetValue(opts, "type").(string)
667
667
  switch k.type_ {
668
668
  case "secret":
669
669
  if format == "jwk" {
@@ -756,7 +756,7 @@ func tnGenerateAsymmetric(kind string, options interface{}) tncrypto.PrivateKey
756
756
  }
757
757
  return k
758
758
  case "ec":
759
- name, _ := TnGet(options, "namedCurve").(string)
759
+ name, _ := TnGetValue(options, "namedCurve").(string)
760
760
  k, err := ecdsa.GenerateKey(tnNamedCurve(name), cryptorand.Reader)
761
761
  if err != nil {
762
762
  panic(tnCryptoErr(err))
@@ -937,7 +937,7 @@ func tnReadSignOptions(key interface{}) tnSignOptions {
937
937
  o.saltLength = int(v)
938
938
  o.hasSalt = true
939
939
  }
940
- if s, ok := TnGet(key, "dsaEncoding").(string); ok && s != "" {
940
+ if s, ok := TnGetValue(key, "dsaEncoding").(string); ok && s != "" {
941
941
  o.dsaEncoding = s
942
942
  }
943
943
  return o
@@ -1120,7 +1120,7 @@ func tnRSAPadding(key interface{}, def int) (int, tncrypto.Hash, []byte) {
1120
1120
  if v, ok := tnCryptoNumber(TnGet(key, "padding")); ok {
1121
1121
  padding = int(v)
1122
1122
  }
1123
- if s, ok := TnGet(key, "oaepHash").(string); ok && s != "" {
1123
+ if s, ok := TnGetValue(key, "oaepHash").(string); ok && s != "" {
1124
1124
  h = tnCryptoHash(s)
1125
1125
  }
1126
1126
  if l := TnGet(key, "oaepLabel"); l != nil && !TnIsNil(l) {
@@ -1332,8 +1332,8 @@ func (e *TnECDH) computeSecret(other interface{}, args ...string) interface{} {
1332
1332
 
1333
1333
  // diffieHellman({ privateKey, publicKey }): ec and x25519 KeyObjects
1334
1334
  func TnDiffieHellman(options interface{}) []byte {
1335
- priv, _ := TnGet(options, "privateKey").(*TnKeyObject)
1336
- pub, _ := TnGet(options, "publicKey").(*TnKeyObject)
1335
+ priv, _ := TnGetValue(options, "privateKey").(*TnKeyObject)
1336
+ pub, _ := TnGetValue(options, "publicKey").(*TnKeyObject)
1337
1337
  if priv == nil || pub == nil {
1338
1338
  panic(TnNodeError("TypeError", "ERR_INVALID_ARG_TYPE", "The \\"options.privateKey\\" and \\"options.publicKey\\" properties must be KeyObjects"))
1339
1339
  }
@@ -1507,7 +1507,7 @@ func TnGeneratePrimeBig(size float64, options ...interface{}) *tnbig.Int {
1507
1507
  panic(TnNodeError("RangeError", "ERR_OUT_OF_RANGE", "The value of \\"size\\" is out of range. It must be >= 2."))
1508
1508
  }
1509
1509
  opts := tnCryptoArg(options)
1510
- safe, _ := TnGet(opts, "safe").(bool)
1510
+ safe, _ := TnGetValue(opts, "safe").(bool)
1511
1511
  add := tnPrimeBig(TnGet(opts, "add"))
1512
1512
  rem := tnPrimeBig(TnGet(opts, "rem"))
1513
1513
  if add == nil && !safe {
@@ -1834,7 +1834,7 @@ func tnAlgName(alg interface{}) string {
1834
1834
  if s, ok := alg.(string); ok {
1835
1835
  return s
1836
1836
  }
1837
- n, _ := TnGet(alg, "name").(string)
1837
+ n, _ := TnGetValue(alg, "name").(string)
1838
1838
  return n
1839
1839
  }
1840
1840
 
@@ -1961,7 +1961,7 @@ func tnSubtleGenerate(alg interface{}, extractable bool, usages interface{}) int
1961
1961
  pubUsages, privUsages = tnFilterUsages(us, "verify"), tnFilterUsages(us, "sign")
1962
1962
  }
1963
1963
  case "ECDSA", "ECDH":
1964
- curve, _ := TnGet(alg, "namedCurve").(string)
1964
+ curve, _ := TnGetValue(alg, "namedCurve").(string)
1965
1965
  priv = tnGenerateAsymmetric("ec", map[string]interface{}{"namedCurve": curve})
1966
1966
  algorithm["namedCurve"] = curve
1967
1967
  if name == "ECDSA" {
@@ -2074,7 +2074,7 @@ func tnSubtleImport(format string, data interface{}, alg interface{}, extractabl
2074
2074
  }
2075
2075
  k = tnPrivateKeyObject(priv)
2076
2076
  case "jwk":
2077
- if kty, _ := TnGet(data, "kty").(string); kty == "oct" {
2077
+ if kty, _ := TnGetValue(data, "kty").(string); kty == "oct" {
2078
2078
  k = &TnKeyObject{type_: "secret", secret: tnJWKBytes(data, "k")}
2079
2079
  } else {
2080
2080
  pub, priv := tnKeyFromJWK(data)
@@ -2134,7 +2134,7 @@ func tnSubtleExport(format string, key *TnCryptoKey) interface{} {
2134
2134
  if length, ok := key.algorithm["length"].(float64); ok {
2135
2135
  switch key.algorithm["name"] {
2136
2136
  case "HMAC":
2137
- hash, _ := TnGet(key.algorithm["hash"], "name").(string)
2137
+ hash, _ := TnGetValue(key.algorithm["hash"], "name").(string)
2138
2138
  jwk["alg"] = "HS" + strings.TrimPrefix(hash, "SHA-")
2139
2139
  case "AES-GCM":
2140
2140
  jwk["alg"] = fmt.Sprintf("A%dGCM", int(length))
@@ -2352,7 +2352,7 @@ func tnSubtleDerive(alg interface{}, key *TnCryptoKey, length interface{}) []byt
2352
2352
  }
2353
2353
  return k
2354
2354
  case "ECDH", "X25519":
2355
- pub, _ := TnGet(alg, "public").(*TnCryptoKey)
2355
+ pub, _ := TnGetValue(alg, "public").(*TnCryptoKey)
2356
2356
  if pub == nil {
2357
2357
  panic(tnDOMError("InvalidAccessError", "algorithm.public must be a public CryptoKey"))
2358
2358
  }
package/bin/node/dgram.js CHANGED
@@ -34,7 +34,7 @@ func TnCreateDgramSocket(kind interface{}, listener ...interface{}) *TnDgramSock
34
34
  if t := tnNetString(TnGet(kind, "type")); t == "udp6" {
35
35
  s.network = "udp6"
36
36
  }
37
- s.reuseAddr, _ = TnGet(kind, "reuseAddr").(bool)
37
+ s.reuseAddr, _ = TnGetValue(kind, "reuseAddr").(bool)
38
38
  }
39
39
  }
40
40
  if len(listener) > 0 && tnIsFunc(listener[0]) {
@@ -122,7 +122,7 @@ func TnNewTracingChannel(nameOrChannels interface{}) *TnTracingChannel {
122
122
  for i, event := range tnTracingEvents {
123
123
  if name, ok := nameOrChannels.(string); ok {
124
124
  channels[i] = TnDiagnosticsChannel("tracing:" + name + ":" + event)
125
- } else if c, ok := TnGet(nameOrChannels, event).(*TnChannel); ok {
125
+ } else if c, ok := TnGetValue(nameOrChannels, event).(*TnChannel); ok {
126
126
  channels[i] = c
127
127
  } else {
128
128
  panic(TnNodeError("TypeError", "ERR_INVALID_ARG_TYPE", "The \\"channels."+event+"\\" property must be an instance of Channel"))
@@ -393,10 +393,10 @@ func TnNewConsole(stdout interface{}, rest ...interface{}) *TnConsole {
393
393
  }
394
394
  }
395
395
  } else if stdout != nil {
396
- if s, ok := TnGet(stdout, "stdout").(tnStreamLike); ok {
396
+ if s, ok := TnGetValue(stdout, "stdout").(tnStreamLike); ok {
397
397
  c.stdout = s.tnStream()
398
398
  }
399
- if s, ok := TnGet(stdout, "stderr").(tnStreamLike); ok {
399
+ if s, ok := TnGetValue(stdout, "stderr").(tnStreamLike); ok {
400
400
  c.stderr = s.tnStream()
401
401
  }
402
402
  }
package/bin/node/dns.js CHANGED
@@ -44,14 +44,14 @@ func tnLookupOptions(options interface{}) (float64, bool) {
44
44
  if n, ok := tnNetNumber(TnGet(options, "family")); ok {
45
45
  family = n
46
46
  }
47
- if s, ok := TnGet(options, "family").(string); ok {
47
+ if s, ok := TnGetValue(options, "family").(string); ok {
48
48
  if s == "IPv4" {
49
49
  family = 4
50
50
  } else if s == "IPv6" {
51
51
  family = 6
52
52
  }
53
53
  }
54
- all, _ := TnGet(options, "all").(bool)
54
+ all, _ := TnGetValue(options, "all").(bool)
55
55
  return family, all
56
56
  }
57
57
 
@@ -38,7 +38,7 @@ var TnDefaultMaxListeners = 10.0
38
38
  func TnNewEventEmitter(options ...interface{}) *TnEventEmitter {
39
39
  e := &TnEventEmitter{state: &tnEmitterState{events: map[string][]*tnListener{}, maxListeners: -1, warned: map[string]bool{}, captureRejections: TnCaptureRejections}}
40
40
  if len(options) > 0 && options[0] != nil {
41
- if b, ok := TnGet(options[0], "captureRejections").(bool); ok {
41
+ if b, ok := TnGetValue(options[0], "captureRejections").(bool); ok {
42
42
  e.state.captureRejections = b
43
43
  }
44
44
  }
@@ -380,7 +380,7 @@ type TnEvent struct {
380
380
  func TnNewEvent(eventType string, options ...interface{}) *TnEvent {
381
381
  ev := &TnEvent{eventType: eventType, timeStamp: float64(time.Now().UnixNano()) / 1e6}
382
382
  if len(options) > 0 && options[0] != nil {
383
- if c, ok := TnGet(options[0], "cancelable").(bool); ok {
383
+ if c, ok := TnGetValue(options[0], "cancelable").(bool); ok {
384
384
  ev.cancelable = c
385
385
  }
386
386
  }
@@ -418,7 +418,7 @@ func (t *TnEventTarget) addEventListener(eventType string, fn interface{}, optio
418
418
  }
419
419
  once := false
420
420
  if len(options) > 0 && options[0] != nil {
421
- if o, ok := TnGet(options[0], "once").(bool); ok {
421
+ if o, ok := TnGetValue(options[0], "once").(bool); ok {
422
422
  once = o
423
423
  }
424
424
  }
package/bin/node/fetch.js CHANGED
@@ -381,7 +381,7 @@ func tnResponseInit(r *TnResponse, init []interface{}) {
381
381
  r.status = n
382
382
  r.statusText = ""
383
383
  }
384
- if s, ok := TnGet(init[0], "statusText").(string); ok {
384
+ if s, ok := TnGetValue(init[0], "statusText").(string); ok {
385
385
  r.statusText = s
386
386
  }
387
387
  if h := TnGet(init[0], "headers"); h != nil {
@@ -489,7 +489,7 @@ func TnNewRequest(input interface{}, init ...interface{}) *TnRequest {
489
489
  if rd := tnNetString(TnGet(opts, "redirect")); rd != "" {
490
490
  req.redirect = rd
491
491
  }
492
- if sig, ok := TnGet(opts, "signal").(*TnAbortSignal); ok && sig != nil {
492
+ if sig, ok := TnGetValue(opts, "signal").(*TnAbortSignal); ok && sig != nil {
493
493
  req.signal = sig
494
494
  }
495
495
  if body := TnGet(opts, "body"); body != nil && !TnIsNil(body) {
package/bin/node/fs.js CHANGED
@@ -529,13 +529,13 @@ func TnReadSync(fd float64, buf []byte, args ...interface{}) float64 {
529
529
  if n, ok := a.(float64); ok {
530
530
  nums = append(nums, n)
531
531
  } else if a != nil {
532
- if p, ok := TnGet(a, "position").(float64); ok {
532
+ if p, ok := TnGetValue(a, "position").(float64); ok {
533
533
  position = int64(p)
534
534
  }
535
- if o, ok := TnGet(a, "offset").(float64); ok {
535
+ if o, ok := TnGetValue(a, "offset").(float64); ok {
536
536
  offset = int(o)
537
537
  }
538
- if l, ok := TnGet(a, "length").(float64); ok {
538
+ if l, ok := TnGetValue(a, "length").(float64); ok {
539
539
  length = int(l)
540
540
  }
541
541
  }
@@ -45,10 +45,10 @@ func tnFsWatchStart(path string, options interface{}, events chan *TnFsWatchEven
45
45
  w := &TnFSWatcher{asyncCtx: TnAsyncSnapshot(), root: filepath.Clean(path), events: events}
46
46
  persistent := true
47
47
  if _, isString := options.(string); options != nil && !isString {
48
- if p, ok := TnGet(options, "persistent").(bool); ok {
48
+ if p, ok := TnGetValue(options, "persistent").(bool); ok {
49
49
  persistent = p
50
50
  }
51
- w.recursive, _ = TnGet(options, "recursive").(bool)
51
+ w.recursive, _ = TnGetValue(options, "recursive").(bool)
52
52
  }
53
53
  info, err := os.Stat(path)
54
54
  if err != nil {
@@ -69,7 +69,7 @@ func tnFsWatchStart(path string, options interface{}, events chan *TnFsWatchEven
69
69
  TnLoopRef()
70
70
  }
71
71
  if options != nil {
72
- if signal, ok := TnGet(options, "signal").(*TnAbortSignal); ok && signal != nil {
72
+ if signal, ok := TnGetValue(options, "signal").(*TnAbortSignal); ok && signal != nil {
73
73
  if signal.aborted {
74
74
  TnLoopPost(func() { w.close() })
75
75
  } else {
@@ -267,10 +267,10 @@ func TnWatchFile(path string, rest ...interface{}) *TnStatWatcher {
267
267
  continue
268
268
  }
269
269
  if a != nil {
270
- if n, ok := TnGet(a, "interval").(float64); ok && n > 0 {
270
+ if n, ok := TnGetValue(a, "interval").(float64); ok && n > 0 {
271
271
  interval = n
272
272
  }
273
- if p, ok := TnGet(a, "persistent").(bool); ok {
273
+ if p, ok := TnGetValue(a, "persistent").(bool); ok {
274
274
  persistent = p
275
275
  }
276
276
  }
package/bin/node/http.js CHANGED
@@ -895,7 +895,7 @@ func TnNewHttpAgent(options ...interface{}) *TnHttpAgent {
895
895
  a := &TnHttpAgent{maxSockets: math.Inf(1)}
896
896
  if len(options) > 0 && options[0] != nil {
897
897
  a.options = options[0]
898
- a.keepAlive, _ = TnGet(options[0], "keepAlive").(bool)
898
+ a.keepAlive, _ = TnGetValue(options[0], "keepAlive").(bool)
899
899
  if n, ok := tnNetNumber(TnGet(options[0], "maxSockets")); ok {
900
900
  a.maxSockets = n
901
901
  }
@@ -1409,11 +1409,11 @@ func TnHttpRequest(secure bool, args ...interface{}) *TnClientRequest {
1409
1409
  cr.timeoutMs = n
1410
1410
  }
1411
1411
  cr.store.setAll(TnGet(options, "headers"))
1412
- if b, ok := TnGet(options, "rejectUnauthorized").(bool); ok && !b {
1412
+ if b, ok := TnGetValue(options, "rejectUnauthorized").(bool); ok && !b {
1413
1413
  insecure = true
1414
1414
  }
1415
1415
  ca = tnPemStrings(TnGet(options, "ca"))
1416
- if sig, ok := TnGet(options, "signal").(*TnAbortSignal); ok && sig != nil {
1416
+ if sig, ok := TnGetValue(options, "signal").(*TnAbortSignal); ok && sig != nil {
1417
1417
  cr.signal = sig
1418
1418
  }
1419
1419
  }
package/bin/node/http2.js CHANGED
@@ -331,7 +331,7 @@ func (st *TnHttp2Stream) respond(args ...interface{}) {
331
331
  st.headersSent = true
332
332
  st.sentHeaders = sent
333
333
  if len(args) > 1 && args[1] != nil {
334
- if end, _ := TnGet(args[1], "endStream").(bool); end {
334
+ if end, _ := TnGetValue(args[1], "endStream").(bool); end {
335
335
  st.end()
336
336
  }
337
337
  }
@@ -463,7 +463,7 @@ func TnHttp2CreateServer(secure bool, args ...interface{}) *TnHttpServer {
463
463
  allowHTTP1 := false
464
464
  for _, a := range args {
465
465
  if a != nil && !tnIsFunc(a) {
466
- allowHTTP1, _ = TnGet(a, "allowHTTP1").(bool)
466
+ allowHTTP1, _ = TnGetValue(a, "allowHTTP1").(bool)
467
467
  }
468
468
  }
469
469
  if hs.tlsConfig == nil {
@@ -521,7 +521,7 @@ func (s *TnHttp2Session) request(headers interface{}, options ...interface{}) *T
521
521
  }
522
522
  endStream := false
523
523
  if len(options) > 0 && options[0] != nil {
524
- endStream, _ = TnGet(options[0], "endStream").(bool)
524
+ endStream, _ = TnGetValue(options[0], "endStream").(bool)
525
525
  }
526
526
  // Requests without a body go out right away, as Node sends their headers at once
527
527
  if endStream || st.method == "GET" || st.method == "HEAD" {
package/bin/node/net.js CHANGED
@@ -265,7 +265,7 @@ func TnNewSocket(options ...interface{}) *TnSocket {
265
265
  s.TnStream = *TnNewDuplex()
266
266
  s.tnSelf = s
267
267
  if len(options) > 0 && options[0] != nil {
268
- if b, ok := TnGet(options[0], "allowHalfOpen").(bool); ok {
268
+ if b, ok := TnGetValue(options[0], "allowHalfOpen").(bool); ok {
269
269
  s.allowHalfOpen = b
270
270
  }
271
271
  }
@@ -417,7 +417,7 @@ func (s *TnSocket) connect(args ...interface{}) *TnSocket {
417
417
  if p := tnNetString(TnGet(a, "path")); p != "" {
418
418
  path, network = p, "unix"
419
419
  }
420
- if b, ok := TnGet(a, "allowHalfOpen").(bool); ok {
420
+ if b, ok := TnGetValue(a, "allowHalfOpen").(bool); ok {
421
421
  s.allowHalfOpen = b
422
422
  }
423
423
  if n, ok := tnNetNumber(TnGet(a, "timeout")); ok {
@@ -624,10 +624,10 @@ func TnNewNetServer(args ...interface{}) *TnNetServer {
624
624
  if tnIsFunc(a) {
625
625
  srv.on(srv.connectionEvent, a)
626
626
  } else if a != nil {
627
- if b, ok := TnGet(a, "allowHalfOpen").(bool); ok {
627
+ if b, ok := TnGetValue(a, "allowHalfOpen").(bool); ok {
628
628
  srv.allowHalfOpen = b
629
629
  }
630
- if b, ok := TnGet(a, "pauseOnConnect").(bool); ok {
630
+ if b, ok := TnGetValue(a, "pauseOnConnect").(bool); ok {
631
631
  srv.pauseOnConnect = b
632
632
  }
633
633
  }
@@ -865,7 +865,7 @@ func TnNewSocketAddress(options ...interface{}) *TnSocketAddress {
865
865
  if len(options) > 0 {
866
866
  opts = options[0]
867
867
  }
868
- if f, ok := TnGet(opts, "family").(string); ok {
868
+ if f, ok := TnGetValue(opts, "family").(string); ok {
869
869
  sa.family = strings.ToLower(f)
870
870
  }
871
871
  if sa.family != "ipv4" && sa.family != "ipv6" {
@@ -875,13 +875,13 @@ func TnNewSocketAddress(options ...interface{}) *TnSocketAddress {
875
875
  if sa.family == "ipv6" {
876
876
  sa.address = "::"
877
877
  }
878
- if a, ok := TnGet(opts, "address").(string); ok {
878
+ if a, ok := TnGetValue(opts, "address").(string); ok {
879
879
  sa.address = a
880
880
  }
881
- if p, ok := TnGet(opts, "port").(float64); ok {
881
+ if p, ok := TnGetValue(opts, "port").(float64); ok {
882
882
  sa.port = p
883
883
  }
884
- if fl, ok := TnGet(opts, "flowlabel").(float64); ok {
884
+ if fl, ok := TnGetValue(opts, "flowlabel").(float64); ok {
885
885
  sa.flowlabel = fl
886
886
  }
887
887
  addr, err := netip.ParseAddr(sa.address)
package/bin/node/path.js CHANGED
@@ -3,6 +3,14 @@
3
3
  // the platform's flavour, as in Node.
4
4
  import { defineClass, defineHelper, defineModule, setResults, isObjectLiteral, getOption } from './registry.js';
5
5
  const pathHelper = `// node:path — Node's posix and win32 algorithms (path is the platform's)
6
+ // A path argument held as any: a string, else Node's TypeError
7
+ func TnPathArg(v interface{}) string {
8
+ if s, ok := v.(string); ok {
9
+ return s
10
+ }
11
+ panic(TnNodeError("TypeError", "ERR_INVALID_ARG_TYPE", "The \\"path\\" argument must be of type string. Received "+TnTypeOf(v)))
12
+ }
13
+
6
14
  type tnPathStyle struct {
7
15
  win bool
8
16
  sep string
@@ -99,6 +107,10 @@ func tnGlobRegexp(g string, escapes bool) string {
99
107
  segStart = false
100
108
  switch {
101
109
  case c == '*' && i+1 < len(g) && g[i+1] == '*' && wasStart && (i+2 == len(g) || g[i+2] == '/'):
110
+ // a leading ** also matches an absolute path's root ('**/a.ts' matches '/x/a.ts')
111
+ if i == 0 {
112
+ b.WriteString("/?")
113
+ }
102
114
  if i+2 == len(g) {
103
115
  b.WriteString("(?:[^/.][^/]*(?:/[^/.][^/]*)*)?")
104
116
  i++
@@ -700,7 +712,7 @@ func TnParsedPathOf(v interface{}) *TnParsedPath {
700
712
  return p
701
713
  }
702
714
  str := func(key string) string {
703
- if s, ok := TnGet(v, key).(string); ok {
715
+ if s, ok := TnGetValue(v, key).(string); ok {
704
716
  return s
705
717
  }
706
718
  return ""
@@ -713,14 +725,16 @@ const PATH_STYLES = {
713
725
  'path/win32': 'TnPathWin32'
714
726
  };
715
727
  export function registerPath(r) {
716
- defineHelper(r, 'nodePath', ['os', 'regexp', 'runtime', 'strings'], ['dynamic'], pathHelper);
728
+ defineHelper(r, 'nodePath', ['os', 'regexp', 'runtime', 'strings'], ['dynamic', 'error', 'typeOf'], pathHelper);
717
729
  defineClass(r, 'path.ParsedPath', '*TnParsedPath', 'class', '', 'root=string; dir=string; base=string; ext=string; name=string', '', '');
718
730
  for (const mod of Object.keys(PATH_STYLES)) {
719
731
  const style = PATH_STYLES[mod];
720
732
  defineModule(r, mod);
721
733
  const fn = (name) => (call) => {
722
734
  r.helper('nodePath');
723
- return `${style}.${name}(${call.args.join(', ')})`;
735
+ // (a dynamic argument must hold a string, as Node checks)
736
+ const args = call.args.map((a, i) => (call.types[i] === 'interface{}' ? `TnPathArg(${a})` : a));
737
+ return `${style}.${name}(${args.join(', ')})`;
724
738
  };
725
739
  for (const name of ['join', 'resolve', 'normalize', 'relative', 'dirname', 'basename', 'extname', 'isAbsolute', 'parse', 'toNamespacedPath', 'matchesGlob']) {
726
740
  r.functions[`${mod}.${name}`] = fn(name);