goscript 0.2.2 → 0.2.4

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 (160) hide show
  1. package/compiler/gotest/testdata/browserapi/browserapi_test.go +36 -0
  2. package/compiler/lowering.go +279 -16
  3. package/compiler/override-registry_test.go +175 -0
  4. package/compiler/protobuf-ts-binding.go +154 -6
  5. package/compiler/protobuf-ts-binding_test.go +7 -2
  6. package/compiler/runtime-contract.go +2 -0
  7. package/compiler/runtime-contract_test.go +1 -0
  8. package/compiler/semantic-model.go +16 -0
  9. package/compiler/semantic-model_test.go +38 -0
  10. package/compiler/skeleton_test.go +522 -17
  11. package/compiler/typescript-emitter.go +4 -0
  12. package/dist/gs/builtin/builtin.js +7 -9
  13. package/dist/gs/builtin/builtin.js.map +1 -1
  14. package/dist/gs/builtin/defer.js +2 -2
  15. package/dist/gs/builtin/hostio.js +5 -5
  16. package/dist/gs/builtin/hostio.js.map +1 -1
  17. package/dist/gs/builtin/map.js +2 -1
  18. package/dist/gs/builtin/map.js.map +1 -1
  19. package/dist/gs/builtin/slice.d.ts +3 -0
  20. package/dist/gs/builtin/slice.js +39 -0
  21. package/dist/gs/builtin/slice.js.map +1 -1
  22. package/dist/gs/builtin/type.js +49 -0
  23. package/dist/gs/builtin/type.js.map +1 -1
  24. package/dist/gs/compress/gzip/index.d.ts +41 -0
  25. package/dist/gs/compress/gzip/index.js +235 -0
  26. package/dist/gs/compress/gzip/index.js.map +1 -0
  27. package/dist/gs/compress/zlib/index.js +5 -2
  28. package/dist/gs/compress/zlib/index.js.map +1 -1
  29. package/dist/gs/crypto/ecdh/index.js +27 -8
  30. package/dist/gs/crypto/ecdh/index.js.map +1 -1
  31. package/dist/gs/crypto/ed25519/index.js +3 -3
  32. package/dist/gs/crypto/ed25519/index.js.map +1 -1
  33. package/dist/gs/crypto/rand/index.js +6 -3
  34. package/dist/gs/crypto/rand/index.js.map +1 -1
  35. package/dist/gs/embed/index.js +9 -3
  36. package/dist/gs/embed/index.js.map +1 -1
  37. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +1 -0
  38. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +33 -0
  39. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
  40. package/dist/gs/github.com/mr-tron/base58/base58/index.js +4 -1
  41. package/dist/gs/github.com/mr-tron/base58/base58/index.js.map +1 -1
  42. package/dist/gs/golang.org/x/crypto/scrypt/index.d.ts +2 -0
  43. package/dist/gs/golang.org/x/crypto/scrypt/index.js +39 -0
  44. package/dist/gs/golang.org/x/crypto/scrypt/index.js.map +1 -0
  45. package/dist/gs/hash/fnv/index.js +13 -5
  46. package/dist/gs/hash/fnv/index.js.map +1 -1
  47. package/dist/gs/io/fs/glob.d.ts +3 -3
  48. package/dist/gs/io/fs/glob.js +9 -9
  49. package/dist/gs/io/fs/glob.js.map +1 -1
  50. package/dist/gs/io/fs/readdir.d.ts +2 -2
  51. package/dist/gs/io/fs/readdir.js +13 -74
  52. package/dist/gs/io/fs/readdir.js.map +1 -1
  53. package/dist/gs/io/fs/readlink.d.ts +1 -1
  54. package/dist/gs/io/fs/readlink.js +2 -2
  55. package/dist/gs/io/fs/readlink.js.map +1 -1
  56. package/dist/gs/io/fs/stat.d.ts +4 -2
  57. package/dist/gs/io/fs/stat.js +12 -73
  58. package/dist/gs/io/fs/stat.js.map +1 -1
  59. package/dist/gs/io/fs/sub.d.ts +2 -2
  60. package/dist/gs/io/fs/sub.js +11 -11
  61. package/dist/gs/io/fs/sub.js.map +1 -1
  62. package/dist/gs/io/fs/walk.js +2 -2
  63. package/dist/gs/io/fs/walk.js.map +1 -1
  64. package/dist/gs/maps/iter.js.map +1 -1
  65. package/dist/gs/maps/maps.js.map +1 -1
  66. package/dist/gs/mime/index.js +5 -2
  67. package/dist/gs/mime/index.js.map +1 -1
  68. package/dist/gs/net/http/httptest/index.js +6 -3
  69. package/dist/gs/net/http/httptest/index.js.map +1 -1
  70. package/dist/gs/net/http/index.d.ts +34 -18
  71. package/dist/gs/net/http/index.js +280 -63
  72. package/dist/gs/net/http/index.js.map +1 -1
  73. package/dist/gs/net/http/pprof/index.d.ts +5 -5
  74. package/dist/gs/net/http/pprof/index.js +21 -21
  75. package/dist/gs/net/http/pprof/index.js.map +1 -1
  76. package/dist/gs/reflect/iter.js +1 -1
  77. package/dist/gs/reflect/iter.js.map +1 -1
  78. package/dist/gs/reflect/type.d.ts +2 -0
  79. package/dist/gs/reflect/type.js +53 -21
  80. package/dist/gs/reflect/type.js.map +1 -1
  81. package/dist/gs/runtime/pprof/index.js.map +1 -1
  82. package/dist/gs/runtime/runtime.js +2 -2
  83. package/dist/gs/runtime/runtime.js.map +1 -1
  84. package/dist/gs/runtime/trace/index.js.map +1 -1
  85. package/dist/gs/slices/slices.d.ts +1 -1
  86. package/dist/gs/slices/slices.js +37 -4
  87. package/dist/gs/slices/slices.js.map +1 -1
  88. package/gs/builtin/builtin.ts +11 -14
  89. package/gs/builtin/defer.ts +2 -2
  90. package/gs/builtin/hostio.ts +5 -5
  91. package/gs/builtin/map.ts +4 -1
  92. package/gs/builtin/runtime-contract.test.ts +25 -0
  93. package/gs/builtin/slice.test.ts +14 -0
  94. package/gs/builtin/slice.ts +64 -0
  95. package/gs/builtin/type.ts +72 -0
  96. package/gs/bytes/bytes.test.ts +14 -13
  97. package/gs/compress/gzip/index.test.ts +86 -0
  98. package/gs/compress/gzip/index.ts +297 -0
  99. package/gs/compress/gzip/meta.json +6 -0
  100. package/gs/compress/gzip/parity.json +45 -0
  101. package/gs/compress/zlib/index.test.ts +19 -5
  102. package/gs/compress/zlib/index.ts +16 -7
  103. package/gs/context/context.test.ts +3 -1
  104. package/gs/crypto/ecdh/index.test.ts +6 -2
  105. package/gs/crypto/ecdh/index.ts +49 -12
  106. package/gs/crypto/ed25519/index.ts +20 -7
  107. package/gs/crypto/rand/index.ts +6 -3
  108. package/gs/embed/index.test.ts +4 -4
  109. package/gs/embed/index.ts +9 -3
  110. package/gs/fmt/fmt.test.ts +29 -4
  111. package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +126 -0
  112. package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +46 -0
  113. package/gs/github.com/mr-tron/base58/base58/index.ts +9 -3
  114. package/gs/github.com/zeebo/blake3/internal/consts/index.test.ts +2 -8
  115. package/gs/golang.org/x/crypto/scrypt/index.test.ts +81 -0
  116. package/gs/golang.org/x/crypto/scrypt/index.ts +54 -0
  117. package/gs/golang.org/x/crypto/scrypt/meta.json +5 -0
  118. package/gs/hash/fnv/index.test.ts +1 -8
  119. package/gs/hash/fnv/index.ts +27 -10
  120. package/gs/io/fs/glob.ts +14 -11
  121. package/gs/io/fs/meta.json +5 -0
  122. package/gs/io/fs/readdir.test.ts +63 -2
  123. package/gs/io/fs/readdir.ts +33 -30
  124. package/gs/io/fs/readlink.test.ts +2 -2
  125. package/gs/io/fs/readlink.ts +5 -2
  126. package/gs/io/fs/stat.test.ts +79 -0
  127. package/gs/io/fs/stat.ts +24 -10
  128. package/gs/io/fs/sub.test.ts +93 -0
  129. package/gs/io/fs/sub.ts +13 -13
  130. package/gs/io/fs/walk.ts +2 -2
  131. package/gs/maps/iter.ts +9 -9
  132. package/gs/maps/maps.ts +4 -4
  133. package/gs/math/bits/index.test.ts +10 -1
  134. package/gs/mime/index.test.ts +33 -15
  135. package/gs/mime/index.ts +9 -2
  136. package/gs/net/http/httptest/index.test.ts +17 -3
  137. package/gs/net/http/httptest/index.ts +8 -3
  138. package/gs/net/http/index.test.ts +851 -124
  139. package/gs/net/http/index.ts +612 -146
  140. package/gs/net/http/meta.json +3 -1
  141. package/gs/net/http/pprof/index.test.ts +4 -4
  142. package/gs/net/http/pprof/index.ts +43 -22
  143. package/gs/os/file_unix_js.test.ts +22 -0
  144. package/gs/reflect/iter.ts +4 -2
  145. package/gs/reflect/map.test.ts +56 -1
  146. package/gs/reflect/type.ts +76 -37
  147. package/gs/runtime/pprof/index.test.ts +7 -1
  148. package/gs/runtime/pprof/index.ts +5 -1
  149. package/gs/runtime/runtime.test.ts +7 -0
  150. package/gs/runtime/runtime.ts +2 -4
  151. package/gs/runtime/trace/index.test.ts +9 -1
  152. package/gs/runtime/trace/index.ts +5 -1
  153. package/gs/slices/meta.json +3 -0
  154. package/gs/slices/slices.test.ts +59 -21
  155. package/gs/slices/slices.ts +61 -20
  156. package/gs/strconv/complex.test.ts +17 -3
  157. package/gs/sync/atomic/doc_64.test.ts +2 -9
  158. package/gs/sync/sync.test.ts +18 -8
  159. package/gs/syscall/js/index.test.ts +9 -4
  160. package/package.json +5 -4
@@ -397,6 +397,25 @@ export class Value {
397
397
  const cloned = new Value(this._value, this._type, this._parentVarRef, this._parentStruct, this._fieldName);
398
398
  return cloned;
399
399
  }
400
+ currentValue() {
401
+ if (this._parentVarRef) {
402
+ return this._parentVarRef.value;
403
+ }
404
+ if (this._parentStruct && this._fieldName !== undefined) {
405
+ const value = this._parentStruct[this._fieldName];
406
+ return value === undefined ? null : value;
407
+ }
408
+ return this._value;
409
+ }
410
+ storeValue(value) {
411
+ this._value = value;
412
+ if (this._parentVarRef) {
413
+ this._parentVarRef.value = value;
414
+ }
415
+ if (this._parentStruct && this._fieldName !== undefined) {
416
+ this._parentStruct[this._fieldName] = value;
417
+ }
418
+ }
400
419
  // Methods required by godoc.txt and used throughout the codebase
401
420
  Int() {
402
421
  const value = this.numericValue();
@@ -461,6 +480,16 @@ export class Value {
461
480
  if (this.Kind() === Slice || this.Kind() === Array) {
462
481
  return $.len(this._value);
463
482
  }
483
+ if (this.Kind() === Map) {
484
+ const value = this.currentValue();
485
+ if (value instanceof globalThis.Map) {
486
+ return value.size;
487
+ }
488
+ if (value !== null && value !== undefined) {
489
+ throw new ValueError({ Kind: this.Kind(), Method: 'Len' });
490
+ }
491
+ return 0;
492
+ }
464
493
  // Check for slice objects created by $.arrayToSlice
465
494
  if (this._value &&
466
495
  typeof this._value === 'object' &&
@@ -506,7 +535,8 @@ export class Value {
506
535
  return this._type !== invalidTypeInstance;
507
536
  }
508
537
  IsNil() {
509
- return this._value === null || this._value === undefined;
538
+ const value = this.currentValue();
539
+ return value === null || value === undefined;
510
540
  }
511
541
  Index(i) {
512
542
  if (this.Kind() === Slice || this.Kind() === Array) {
@@ -708,15 +738,7 @@ export class Value {
708
738
  if (!xType.AssignableTo(thisType)) {
709
739
  throw new Error('reflect: assign to wrong type');
710
740
  }
711
- this._value = x.value;
712
- // Also update the parent VarRef if we were dereferenced from one
713
- if (this._parentVarRef) {
714
- this._parentVarRef.value = x.value;
715
- }
716
- // Also update the parent struct field if this is a struct field
717
- if (this._parentStruct && this._fieldName) {
718
- this._parentStruct[this._fieldName] = x.value;
719
- }
741
+ this.storeValue(x.value);
720
742
  }
721
743
  // Additional methods from deleted reflect.gs.ts
722
744
  Interface() {
@@ -768,40 +790,43 @@ export class Value {
768
790
  if (this.Kind() !== Map) {
769
791
  throw new ValueError({ Kind: this.Kind(), Method: 'MapRange' });
770
792
  }
771
- if (this._value === null || this._value === undefined) {
793
+ const value = this.currentValue();
794
+ if (value === null || value === undefined) {
772
795
  return new MapIter(new globalThis.Map());
773
796
  }
774
- if (!(this._value instanceof globalThis.Map)) {
797
+ if (!(value instanceof globalThis.Map)) {
775
798
  throw new ValueError({ Kind: this.Kind(), Method: 'MapRange' });
776
799
  }
777
- return new MapIter(this._value);
800
+ return new MapIter(value);
778
801
  }
779
802
  MapIndex(key) {
780
803
  if (this.Kind() !== Map) {
781
804
  throw new ValueError({ Kind: this.Kind(), Method: 'MapIndex' });
782
805
  }
783
- if (!(this._value instanceof globalThis.Map)) {
806
+ const value = this.currentValue();
807
+ if (!(value instanceof globalThis.Map)) {
784
808
  return new Value(null, new BasicType(Invalid, 'invalid'));
785
809
  }
786
810
  const rawKey = key.Interface();
787
- if (!this._value.has(rawKey)) {
811
+ if (!value.has(rawKey)) {
788
812
  return new Value(null, new BasicType(Invalid, 'invalid'));
789
813
  }
790
- return new Value(this._value.get(rawKey), this.Type().Elem());
814
+ return new Value(value.get(rawKey), this.Type().Elem());
791
815
  }
792
816
  MapKeys() {
793
817
  if (this.Kind() !== Map) {
794
818
  throw new ValueError({ Kind: this.Kind(), Method: 'MapKeys' });
795
819
  }
796
- if (this._value === null || this._value === undefined) {
820
+ const value = this.currentValue();
821
+ if (value === null || value === undefined) {
797
822
  return $.makeSlice(0);
798
823
  }
799
- if (!(this._value instanceof globalThis.Map)) {
824
+ if (!(value instanceof globalThis.Map)) {
800
825
  throw new ValueError({ Kind: this.Kind(), Method: 'MapKeys' });
801
826
  }
802
827
  const keyType = this.Type().Key();
803
828
  const keys = [];
804
- for (const key of this._value.keys()) {
829
+ for (const key of value.keys()) {
805
830
  keys.push(new Value(key, keyType));
806
831
  }
807
832
  return $.arrayToSlice(keys);
@@ -970,7 +995,7 @@ export class Value {
970
995
  throw new Error('reflect: call of reflect.Value.SetZero on unaddressable value');
971
996
  }
972
997
  const zeroVal = Zero(this.Type());
973
- this._value = zeroVal.value;
998
+ this.storeValue(zeroVal.value);
974
999
  }
975
1000
  // SetLen sets v's length to n
976
1001
  SetLen(n) {
@@ -994,9 +1019,16 @@ export class Value {
994
1019
  this.Kind() +
995
1020
  ' Value');
996
1021
  }
997
- const mapObj = this._value;
1022
+ const mapObj = this.currentValue();
1023
+ if (!(mapObj instanceof globalThis.Map)) {
1024
+ throw new Error('reflect: assignment to entry in nil map');
1025
+ }
998
1026
  const keyVal = key.value;
999
1027
  const elemVal = elem.value;
1028
+ if (!elem.IsValid()) {
1029
+ mapObj.delete(keyVal);
1030
+ return;
1031
+ }
1000
1032
  mapObj.set(keyVal, elemVal);
1001
1033
  }
1002
1034
  // Grow increases the slice's capacity, if necessary