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.
- package/compiler/gotest/testdata/browserapi/browserapi_test.go +36 -0
- package/compiler/lowering.go +279 -16
- package/compiler/override-registry_test.go +175 -0
- package/compiler/protobuf-ts-binding.go +154 -6
- package/compiler/protobuf-ts-binding_test.go +7 -2
- package/compiler/runtime-contract.go +2 -0
- package/compiler/runtime-contract_test.go +1 -0
- package/compiler/semantic-model.go +16 -0
- package/compiler/semantic-model_test.go +38 -0
- package/compiler/skeleton_test.go +522 -17
- package/compiler/typescript-emitter.go +4 -0
- package/dist/gs/builtin/builtin.js +7 -9
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/defer.js +2 -2
- package/dist/gs/builtin/hostio.js +5 -5
- package/dist/gs/builtin/hostio.js.map +1 -1
- package/dist/gs/builtin/map.js +2 -1
- package/dist/gs/builtin/map.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +3 -0
- package/dist/gs/builtin/slice.js +39 -0
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.js +49 -0
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/compress/gzip/index.d.ts +41 -0
- package/dist/gs/compress/gzip/index.js +235 -0
- package/dist/gs/compress/gzip/index.js.map +1 -0
- package/dist/gs/compress/zlib/index.js +5 -2
- package/dist/gs/compress/zlib/index.js.map +1 -1
- package/dist/gs/crypto/ecdh/index.js +27 -8
- package/dist/gs/crypto/ecdh/index.js.map +1 -1
- package/dist/gs/crypto/ed25519/index.js +3 -3
- package/dist/gs/crypto/ed25519/index.js.map +1 -1
- package/dist/gs/crypto/rand/index.js +6 -3
- package/dist/gs/crypto/rand/index.js.map +1 -1
- package/dist/gs/embed/index.js +9 -3
- package/dist/gs/embed/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +1 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +33 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
- package/dist/gs/github.com/mr-tron/base58/base58/index.js +4 -1
- package/dist/gs/github.com/mr-tron/base58/base58/index.js.map +1 -1
- package/dist/gs/golang.org/x/crypto/scrypt/index.d.ts +2 -0
- package/dist/gs/golang.org/x/crypto/scrypt/index.js +39 -0
- package/dist/gs/golang.org/x/crypto/scrypt/index.js.map +1 -0
- package/dist/gs/hash/fnv/index.js +13 -5
- package/dist/gs/hash/fnv/index.js.map +1 -1
- package/dist/gs/io/fs/glob.d.ts +3 -3
- package/dist/gs/io/fs/glob.js +9 -9
- package/dist/gs/io/fs/glob.js.map +1 -1
- package/dist/gs/io/fs/readdir.d.ts +2 -2
- package/dist/gs/io/fs/readdir.js +13 -74
- package/dist/gs/io/fs/readdir.js.map +1 -1
- package/dist/gs/io/fs/readlink.d.ts +1 -1
- package/dist/gs/io/fs/readlink.js +2 -2
- package/dist/gs/io/fs/readlink.js.map +1 -1
- package/dist/gs/io/fs/stat.d.ts +4 -2
- package/dist/gs/io/fs/stat.js +12 -73
- package/dist/gs/io/fs/stat.js.map +1 -1
- package/dist/gs/io/fs/sub.d.ts +2 -2
- package/dist/gs/io/fs/sub.js +11 -11
- package/dist/gs/io/fs/sub.js.map +1 -1
- package/dist/gs/io/fs/walk.js +2 -2
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/maps/iter.js.map +1 -1
- package/dist/gs/maps/maps.js.map +1 -1
- package/dist/gs/mime/index.js +5 -2
- package/dist/gs/mime/index.js.map +1 -1
- package/dist/gs/net/http/httptest/index.js +6 -3
- package/dist/gs/net/http/httptest/index.js.map +1 -1
- package/dist/gs/net/http/index.d.ts +34 -18
- package/dist/gs/net/http/index.js +280 -63
- package/dist/gs/net/http/index.js.map +1 -1
- package/dist/gs/net/http/pprof/index.d.ts +5 -5
- package/dist/gs/net/http/pprof/index.js +21 -21
- package/dist/gs/net/http/pprof/index.js.map +1 -1
- package/dist/gs/reflect/iter.js +1 -1
- package/dist/gs/reflect/iter.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +2 -0
- package/dist/gs/reflect/type.js +53 -21
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/runtime/pprof/index.js.map +1 -1
- package/dist/gs/runtime/runtime.js +2 -2
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/runtime/trace/index.js.map +1 -1
- package/dist/gs/slices/slices.d.ts +1 -1
- package/dist/gs/slices/slices.js +37 -4
- package/dist/gs/slices/slices.js.map +1 -1
- package/gs/builtin/builtin.ts +11 -14
- package/gs/builtin/defer.ts +2 -2
- package/gs/builtin/hostio.ts +5 -5
- package/gs/builtin/map.ts +4 -1
- package/gs/builtin/runtime-contract.test.ts +25 -0
- package/gs/builtin/slice.test.ts +14 -0
- package/gs/builtin/slice.ts +64 -0
- package/gs/builtin/type.ts +72 -0
- package/gs/bytes/bytes.test.ts +14 -13
- package/gs/compress/gzip/index.test.ts +86 -0
- package/gs/compress/gzip/index.ts +297 -0
- package/gs/compress/gzip/meta.json +6 -0
- package/gs/compress/gzip/parity.json +45 -0
- package/gs/compress/zlib/index.test.ts +19 -5
- package/gs/compress/zlib/index.ts +16 -7
- package/gs/context/context.test.ts +3 -1
- package/gs/crypto/ecdh/index.test.ts +6 -2
- package/gs/crypto/ecdh/index.ts +49 -12
- package/gs/crypto/ed25519/index.ts +20 -7
- package/gs/crypto/rand/index.ts +6 -3
- package/gs/embed/index.test.ts +4 -4
- package/gs/embed/index.ts +9 -3
- package/gs/fmt/fmt.test.ts +29 -4
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +126 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +46 -0
- package/gs/github.com/mr-tron/base58/base58/index.ts +9 -3
- package/gs/github.com/zeebo/blake3/internal/consts/index.test.ts +2 -8
- package/gs/golang.org/x/crypto/scrypt/index.test.ts +81 -0
- package/gs/golang.org/x/crypto/scrypt/index.ts +54 -0
- package/gs/golang.org/x/crypto/scrypt/meta.json +5 -0
- package/gs/hash/fnv/index.test.ts +1 -8
- package/gs/hash/fnv/index.ts +27 -10
- package/gs/io/fs/glob.ts +14 -11
- package/gs/io/fs/meta.json +5 -0
- package/gs/io/fs/readdir.test.ts +63 -2
- package/gs/io/fs/readdir.ts +33 -30
- package/gs/io/fs/readlink.test.ts +2 -2
- package/gs/io/fs/readlink.ts +5 -2
- package/gs/io/fs/stat.test.ts +79 -0
- package/gs/io/fs/stat.ts +24 -10
- package/gs/io/fs/sub.test.ts +93 -0
- package/gs/io/fs/sub.ts +13 -13
- package/gs/io/fs/walk.ts +2 -2
- package/gs/maps/iter.ts +9 -9
- package/gs/maps/maps.ts +4 -4
- package/gs/math/bits/index.test.ts +10 -1
- package/gs/mime/index.test.ts +33 -15
- package/gs/mime/index.ts +9 -2
- package/gs/net/http/httptest/index.test.ts +17 -3
- package/gs/net/http/httptest/index.ts +8 -3
- package/gs/net/http/index.test.ts +851 -124
- package/gs/net/http/index.ts +612 -146
- package/gs/net/http/meta.json +3 -1
- package/gs/net/http/pprof/index.test.ts +4 -4
- package/gs/net/http/pprof/index.ts +43 -22
- package/gs/os/file_unix_js.test.ts +22 -0
- package/gs/reflect/iter.ts +4 -2
- package/gs/reflect/map.test.ts +56 -1
- package/gs/reflect/type.ts +76 -37
- package/gs/runtime/pprof/index.test.ts +7 -1
- package/gs/runtime/pprof/index.ts +5 -1
- package/gs/runtime/runtime.test.ts +7 -0
- package/gs/runtime/runtime.ts +2 -4
- package/gs/runtime/trace/index.test.ts +9 -1
- package/gs/runtime/trace/index.ts +5 -1
- package/gs/slices/meta.json +3 -0
- package/gs/slices/slices.test.ts +59 -21
- package/gs/slices/slices.ts +61 -20
- package/gs/strconv/complex.test.ts +17 -3
- package/gs/sync/atomic/doc_64.test.ts +2 -9
- package/gs/sync/sync.test.ts +18 -8
- package/gs/syscall/js/index.test.ts +9 -4
- package/package.json +5 -4
package/dist/gs/reflect/type.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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
|
-
|
|
793
|
+
const value = this.currentValue();
|
|
794
|
+
if (value === null || value === undefined) {
|
|
772
795
|
return new MapIter(new globalThis.Map());
|
|
773
796
|
}
|
|
774
|
-
if (!(
|
|
797
|
+
if (!(value instanceof globalThis.Map)) {
|
|
775
798
|
throw new ValueError({ Kind: this.Kind(), Method: 'MapRange' });
|
|
776
799
|
}
|
|
777
|
-
return new MapIter(
|
|
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
|
-
|
|
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 (!
|
|
811
|
+
if (!value.has(rawKey)) {
|
|
788
812
|
return new Value(null, new BasicType(Invalid, 'invalid'));
|
|
789
813
|
}
|
|
790
|
-
return new Value(
|
|
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
|
-
|
|
820
|
+
const value = this.currentValue();
|
|
821
|
+
if (value === null || value === undefined) {
|
|
797
822
|
return $.makeSlice(0);
|
|
798
823
|
}
|
|
799
|
-
if (!(
|
|
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
|
|
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.
|
|
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.
|
|
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
|