goscript 0.2.3 → 0.2.5
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/README.md +8 -8
- package/cmd/go_js_wasm_exec/main.go +1 -1
- package/cmd/go_js_wasm_exec/main_test.go +1 -1
- package/cmd/goscript/cmd-compile.go +9 -1
- package/cmd/goscript/cmd-test.go +1 -1
- package/cmd/goscript/cmd_compile_test.go +44 -0
- package/cmd/goscript/deps.go +1 -1
- package/cmd/goscript-wasm/main.go +2 -2
- package/compiler/compile-request.go +19 -0
- package/compiler/compile_bench_test.go +121 -0
- package/compiler/compliance_test.go +17 -1
- package/compiler/config.go +2 -0
- package/compiler/gotest/result.go +1 -1
- package/compiler/gotest/runner.go +2 -2
- package/compiler/gotest/runner_test.go +4 -7
- package/compiler/index.test.ts +28 -0
- package/compiler/index.ts +32 -16
- package/compiler/lowering.go +1236 -143
- package/compiler/lowering_bench_test.go +4 -0
- package/compiler/override-facts.go +1 -1
- package/compiler/override-registry_test.go +125 -0
- package/compiler/package-graph.go +92 -0
- package/compiler/package-graph_test.go +113 -0
- package/compiler/runtime-contract.go +1 -1
- package/compiler/semantic-model.go +32 -0
- package/compiler/skeleton_test.go +284 -11
- package/compiler/wasm/compile.go +1 -1
- package/compiler/wasm/compile_test.go +1 -1
- package/dist/compiler/index.d.ts +4 -0
- package/dist/compiler/index.js +26 -15
- package/dist/compiler/index.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/database/sql/driver/index.d.ts +165 -0
- package/dist/gs/database/sql/driver/index.js +432 -0
- package/dist/gs/database/sql/driver/index.js.map +1 -0
- package/dist/gs/encoding/binary/index.d.ts +71 -0
- package/dist/gs/encoding/binary/index.js +778 -0
- package/dist/gs/encoding/binary/index.js.map +1 -0
- package/dist/gs/fmt/fmt.js +156 -57
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/github.com/klauspost/cpuid/v2/index.d.ts +11 -0
- package/dist/gs/github.com/klauspost/cpuid/v2/index.js +28 -0
- package/dist/gs/github.com/klauspost/cpuid/v2/index.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/errors.d.ts +0 -2
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/index.d.ts +2 -1
- package/dist/gs/github.com/pkg/errors/index.js +1 -1
- package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/stack.d.ts +8 -19
- package/dist/gs/github.com/pkg/errors/stack.js +26 -61
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
- package/dist/gs/golang.org/x/crypto/cryptobyte/asn1/index.d.ts +19 -0
- package/dist/gs/golang.org/x/crypto/cryptobyte/asn1/index.js +25 -0
- package/dist/gs/golang.org/x/crypto/cryptobyte/asn1/index.js.map +1 -0
- package/dist/gs/golang.org/x/crypto/cryptobyte/index.d.ts +104 -0
- package/dist/gs/golang.org/x/crypto/cryptobyte/index.js +1107 -0
- package/dist/gs/golang.org/x/crypto/cryptobyte/index.js.map +1 -0
- package/dist/gs/golang.org/x/crypto/internal/alias/index.d.ts +3 -0
- package/dist/gs/golang.org/x/crypto/internal/alias/index.js +39 -0
- package/dist/gs/golang.org/x/crypto/internal/alias/index.js.map +1 -0
- package/dist/gs/io/fs/glob.js +1 -1
- package/dist/gs/io/fs/glob.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 +7 -7
- package/dist/gs/io/fs/sub.js.map +1 -1
- package/dist/gs/io/fs/walk.js +1 -1
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/net/http/index.d.ts +18 -14
- package/dist/gs/net/http/index.js +44 -23
- 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/runtime/runtime.d.ts +6 -1
- package/dist/gs/runtime/runtime.js +15 -8
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/runtime/trace/index.d.ts +8 -5
- package/dist/gs/runtime/trace/index.js +324 -23
- package/dist/gs/runtime/trace/index.js.map +1 -1
- package/dist/gs/slices/slices.d.ts +2 -1
- package/dist/gs/slices/slices.js +9 -3
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sort/search.gs.d.ts +3 -1
- package/dist/gs/sort/search.gs.js +18 -53
- package/dist/gs/sort/search.gs.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +1 -1
- package/dist/gs/sync/sync.js +3 -0
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/time/time.d.ts +22 -29
- package/dist/gs/time/time.js +111 -32
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unsafe/unsafe.d.ts +3 -2
- package/dist/gs/unsafe/unsafe.js.map +1 -1
- package/go.mod +7 -5
- package/go.sum +12 -26
- package/gs/builtin/runtime-contract.test.ts +25 -0
- 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/database/sql/driver/index.test.ts +88 -0
- package/gs/database/sql/driver/index.ts +675 -0
- package/gs/database/sql/driver/meta.json +3 -0
- package/gs/database/sql/driver/parity.json +144 -0
- package/gs/embed/index.test.ts +1 -1
- package/gs/encoding/binary/index.test.ts +239 -0
- package/gs/encoding/binary/index.ts +999 -0
- package/gs/encoding/binary/meta.json +9 -0
- package/gs/encoding/binary/parity.json +72 -0
- package/gs/fmt/fmt.test.ts +28 -0
- package/gs/fmt/fmt.ts +198 -61
- package/gs/fmt/meta.json +2 -1
- package/gs/github.com/klauspost/cpuid/v2/index.ts +38 -0
- package/gs/github.com/klauspost/cpuid/v2/meta.json +3 -0
- package/gs/github.com/pkg/errors/errors.ts +1 -2
- package/gs/github.com/pkg/errors/index.ts +2 -1
- package/gs/github.com/pkg/errors/stack.ts +34 -62
- package/gs/golang.org/x/crypto/cryptobyte/asn1/index.test.ts +19 -0
- package/gs/golang.org/x/crypto/cryptobyte/asn1/index.ts +29 -0
- package/gs/golang.org/x/crypto/cryptobyte/index.test.ts +255 -0
- package/gs/golang.org/x/crypto/cryptobyte/index.ts +1441 -0
- package/gs/golang.org/x/crypto/cryptobyte/meta.json +3 -0
- package/gs/golang.org/x/crypto/internal/alias/index.test.ts +40 -0
- package/gs/golang.org/x/crypto/internal/alias/index.ts +40 -0
- package/gs/io/fs/glob.ts +1 -1
- package/gs/io/fs/meta.json +3 -0
- 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 +9 -9
- package/gs/io/fs/walk.ts +1 -1
- package/gs/net/http/index.test.ts +207 -2
- package/gs/net/http/index.ts +68 -37
- 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 +30 -27
- package/gs/runtime/runtime.test.ts +16 -0
- package/gs/runtime/runtime.ts +17 -9
- package/gs/runtime/trace/index.test.ts +113 -14
- package/gs/runtime/trace/index.ts +384 -34
- package/gs/runtime/trace/meta.json +1 -0
- package/gs/slices/slices.test.ts +24 -1
- package/gs/slices/slices.ts +14 -4
- package/gs/sort/meta.json +1 -0
- package/gs/sort/search.gs.ts +20 -5
- package/gs/sync/sync.ts +4 -1
- package/gs/time/time.test.ts +79 -2
- package/gs/time/time.ts +133 -33
- package/gs/unsafe/unsafe.ts +4 -2
- package/package.json +2 -2
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"strict": true,
|
|
4
|
+
"symbols": {
|
|
5
|
+
"Bool": {
|
|
6
|
+
"status": "real"
|
|
7
|
+
},
|
|
8
|
+
"ColumnConverter": {
|
|
9
|
+
"status": "real"
|
|
10
|
+
},
|
|
11
|
+
"Conn": {
|
|
12
|
+
"status": "real"
|
|
13
|
+
},
|
|
14
|
+
"ConnBeginTx": {
|
|
15
|
+
"status": "real"
|
|
16
|
+
},
|
|
17
|
+
"ConnPrepareContext": {
|
|
18
|
+
"status": "real"
|
|
19
|
+
},
|
|
20
|
+
"Connector": {
|
|
21
|
+
"status": "real"
|
|
22
|
+
},
|
|
23
|
+
"DefaultParameterConverter": {
|
|
24
|
+
"status": "real"
|
|
25
|
+
},
|
|
26
|
+
"Driver": {
|
|
27
|
+
"status": "real"
|
|
28
|
+
},
|
|
29
|
+
"DriverContext": {
|
|
30
|
+
"status": "real"
|
|
31
|
+
},
|
|
32
|
+
"ErrBadConn": {
|
|
33
|
+
"status": "real"
|
|
34
|
+
},
|
|
35
|
+
"ErrRemoveArgument": {
|
|
36
|
+
"status": "real"
|
|
37
|
+
},
|
|
38
|
+
"ErrSkip": {
|
|
39
|
+
"status": "real"
|
|
40
|
+
},
|
|
41
|
+
"Execer": {
|
|
42
|
+
"status": "real"
|
|
43
|
+
},
|
|
44
|
+
"ExecerContext": {
|
|
45
|
+
"status": "real"
|
|
46
|
+
},
|
|
47
|
+
"Int32": {
|
|
48
|
+
"status": "real"
|
|
49
|
+
},
|
|
50
|
+
"IsScanValue": {
|
|
51
|
+
"status": "real"
|
|
52
|
+
},
|
|
53
|
+
"IsValue": {
|
|
54
|
+
"status": "real"
|
|
55
|
+
},
|
|
56
|
+
"IsolationLevel": {
|
|
57
|
+
"status": "real"
|
|
58
|
+
},
|
|
59
|
+
"NamedValue": {
|
|
60
|
+
"status": "real"
|
|
61
|
+
},
|
|
62
|
+
"NamedValueChecker": {
|
|
63
|
+
"status": "real"
|
|
64
|
+
},
|
|
65
|
+
"NotNull": {
|
|
66
|
+
"status": "real"
|
|
67
|
+
},
|
|
68
|
+
"Null": {
|
|
69
|
+
"status": "real"
|
|
70
|
+
},
|
|
71
|
+
"Pinger": {
|
|
72
|
+
"status": "real"
|
|
73
|
+
},
|
|
74
|
+
"Queryer": {
|
|
75
|
+
"status": "real"
|
|
76
|
+
},
|
|
77
|
+
"QueryerContext": {
|
|
78
|
+
"status": "real"
|
|
79
|
+
},
|
|
80
|
+
"Result": {
|
|
81
|
+
"status": "real"
|
|
82
|
+
},
|
|
83
|
+
"ResultNoRows": {
|
|
84
|
+
"status": "real"
|
|
85
|
+
},
|
|
86
|
+
"Rows": {
|
|
87
|
+
"status": "real"
|
|
88
|
+
},
|
|
89
|
+
"RowsAffected": {
|
|
90
|
+
"status": "real"
|
|
91
|
+
},
|
|
92
|
+
"RowsColumnTypeDatabaseTypeName": {
|
|
93
|
+
"status": "real"
|
|
94
|
+
},
|
|
95
|
+
"RowsColumnTypeLength": {
|
|
96
|
+
"status": "real"
|
|
97
|
+
},
|
|
98
|
+
"RowsColumnTypeNullable": {
|
|
99
|
+
"status": "real"
|
|
100
|
+
},
|
|
101
|
+
"RowsColumnTypePrecisionScale": {
|
|
102
|
+
"status": "real"
|
|
103
|
+
},
|
|
104
|
+
"RowsColumnTypeScanType": {
|
|
105
|
+
"status": "real"
|
|
106
|
+
},
|
|
107
|
+
"RowsNextResultSet": {
|
|
108
|
+
"status": "real"
|
|
109
|
+
},
|
|
110
|
+
"SessionResetter": {
|
|
111
|
+
"status": "real"
|
|
112
|
+
},
|
|
113
|
+
"Stmt": {
|
|
114
|
+
"status": "real"
|
|
115
|
+
},
|
|
116
|
+
"StmtExecContext": {
|
|
117
|
+
"status": "real"
|
|
118
|
+
},
|
|
119
|
+
"StmtQueryContext": {
|
|
120
|
+
"status": "real"
|
|
121
|
+
},
|
|
122
|
+
"String": {
|
|
123
|
+
"status": "real"
|
|
124
|
+
},
|
|
125
|
+
"Tx": {
|
|
126
|
+
"status": "real"
|
|
127
|
+
},
|
|
128
|
+
"TxOptions": {
|
|
129
|
+
"status": "real"
|
|
130
|
+
},
|
|
131
|
+
"Value": {
|
|
132
|
+
"status": "real"
|
|
133
|
+
},
|
|
134
|
+
"ValueConverter": {
|
|
135
|
+
"status": "real"
|
|
136
|
+
},
|
|
137
|
+
"Valuer": {
|
|
138
|
+
"status": "real"
|
|
139
|
+
},
|
|
140
|
+
"Validator": {
|
|
141
|
+
"status": "real"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
package/gs/embed/index.test.ts
CHANGED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
4
|
+
import * as bytes from '@goscript/bytes/index.js'
|
|
5
|
+
import * as io from '@goscript/io/index.js'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Append,
|
|
9
|
+
AppendUvarint,
|
|
10
|
+
AppendVarint,
|
|
11
|
+
BigEndian,
|
|
12
|
+
Decode,
|
|
13
|
+
Encode,
|
|
14
|
+
LittleEndian,
|
|
15
|
+
MaxVarintLen64,
|
|
16
|
+
PutUvarint,
|
|
17
|
+
PutVarint,
|
|
18
|
+
Read,
|
|
19
|
+
ReadUvarint,
|
|
20
|
+
ReadVarint,
|
|
21
|
+
Size,
|
|
22
|
+
Uvarint,
|
|
23
|
+
Varint,
|
|
24
|
+
Write,
|
|
25
|
+
type AppendByteOrder,
|
|
26
|
+
type ByteOrder,
|
|
27
|
+
} from './index.js'
|
|
28
|
+
|
|
29
|
+
describe('encoding/binary override', () => {
|
|
30
|
+
it('encodes and decodes big and little endian integers', () => {
|
|
31
|
+
const buf = $.makeSlice<number>(8, undefined, 'byte')
|
|
32
|
+
|
|
33
|
+
BigEndian.PutUint16(buf, 0x1234)
|
|
34
|
+
expect(Array.from($.bytesToUint8Array($.goSlice(buf, 0, 2)))).toEqual([
|
|
35
|
+
0x12, 0x34,
|
|
36
|
+
])
|
|
37
|
+
expect(BigEndian.Uint16(buf)).toBe(0x1234)
|
|
38
|
+
|
|
39
|
+
LittleEndian.PutUint32(buf, 0x12345678)
|
|
40
|
+
expect(Array.from($.bytesToUint8Array($.goSlice(buf, 0, 4)))).toEqual([
|
|
41
|
+
0x78, 0x56, 0x34, 0x12,
|
|
42
|
+
])
|
|
43
|
+
expect(LittleEndian.Uint32(buf)).toBe(0x12345678)
|
|
44
|
+
|
|
45
|
+
BigEndian.PutUint64(buf, 0x0102030405060708n as unknown as number)
|
|
46
|
+
expect(Array.from($.bytesToUint8Array(buf))).toEqual([
|
|
47
|
+
1, 2, 3, 4, 5, 6, 7, 8,
|
|
48
|
+
])
|
|
49
|
+
expect(BigEndian.Uint64(buf)).toBe(0x0102030405060708n)
|
|
50
|
+
expect(LittleEndian.String()).toBe('LittleEndian')
|
|
51
|
+
expect(BigEndian.GoString()).toBe('binary.BigEndian')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('appends endian integers', () => {
|
|
55
|
+
let out = BigEndian.AppendUint16(null, 0x1234)
|
|
56
|
+
out = LittleEndian.AppendUint32(out, 0x01020304)
|
|
57
|
+
out = BigEndian.AppendUint64(out, 0x05060708090a0b0cn as unknown as number)
|
|
58
|
+
|
|
59
|
+
expect(Array.from($.bytesToUint8Array(out))).toEqual([
|
|
60
|
+
0x12, 0x34, 0x04, 0x03, 0x02, 0x01, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
|
|
61
|
+
0x0b, 0x0c,
|
|
62
|
+
])
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('registers ByteOrder and AppendByteOrder interfaces', () => {
|
|
66
|
+
const [, byteOrderOK] = $.typeAssertTuple<ByteOrder>(
|
|
67
|
+
BigEndian,
|
|
68
|
+
'binary.ByteOrder',
|
|
69
|
+
)
|
|
70
|
+
const [, appendOrderOK] = $.typeAssertTuple<AppendByteOrder>(
|
|
71
|
+
LittleEndian,
|
|
72
|
+
'binary.AppendByteOrder',
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
expect(byteOrderOK).toBe(true)
|
|
76
|
+
expect(appendOrderOK).toBe(true)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('matches Go varint semantics', async () => {
|
|
80
|
+
const buf = $.makeSlice<number>(MaxVarintLen64, undefined, 'byte')
|
|
81
|
+
const n = PutUvarint(buf, 300)
|
|
82
|
+
|
|
83
|
+
expect(n).toBe(2)
|
|
84
|
+
expect(Array.from($.bytesToUint8Array($.goSlice(buf, 0, n)))).toEqual([
|
|
85
|
+
0xac, 0x02,
|
|
86
|
+
])
|
|
87
|
+
expect(Uvarint($.goSlice(buf, 0, n))).toEqual([300, 2])
|
|
88
|
+
|
|
89
|
+
const signed = $.makeSlice<number>(MaxVarintLen64, undefined, 'byte')
|
|
90
|
+
const signedN = PutVarint(signed, -150)
|
|
91
|
+
expect(Varint($.goSlice(signed, 0, signedN))).toEqual([-150, signedN])
|
|
92
|
+
|
|
93
|
+
expect(Array.from($.bytesToUint8Array(AppendUvarint(null, 300)))).toEqual([
|
|
94
|
+
0xac, 0x02,
|
|
95
|
+
])
|
|
96
|
+
expect(Varint(AppendVarint(null, -150))[0]).toBe(-150)
|
|
97
|
+
|
|
98
|
+
const reader = bytes.NewReader($.goSlice(buf, 0, n))!
|
|
99
|
+
expect(await ReadUvarint(reader)).toEqual([300, null])
|
|
100
|
+
|
|
101
|
+
const signedReader = bytes.NewReader($.goSlice(signed, 0, signedN))!
|
|
102
|
+
expect(await ReadVarint(signedReader)).toEqual([-150, null])
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('reports varint short buffers and overflows', async () => {
|
|
106
|
+
expect(Uvarint($.stringToBytes('\x80'))).toEqual([0, 0])
|
|
107
|
+
|
|
108
|
+
const overflow = $.makeSlice<number>(11, undefined, 'byte')
|
|
109
|
+
for (let i = 0; i < $.len(overflow); i++) {
|
|
110
|
+
overflow[i] = 0x80
|
|
111
|
+
}
|
|
112
|
+
expect(Uvarint(overflow)).toEqual([0, -11])
|
|
113
|
+
|
|
114
|
+
const shortReader = bytes.NewReader($.stringToBytes('\x80'))!
|
|
115
|
+
const [, shortErr] = await ReadUvarint(shortReader)
|
|
116
|
+
expect(shortErr).toBe(io.ErrUnexpectedEOF)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('encodes, decodes, reads, and writes byte slices', async () => {
|
|
120
|
+
const source = $.stringToBytes('abc')
|
|
121
|
+
const target = $.makeSlice<number>(3, undefined, 'byte')
|
|
122
|
+
|
|
123
|
+
expect(Decode(source, BigEndian, target)).toEqual([3, null])
|
|
124
|
+
expect($.bytesToString(target)).toBe('abc')
|
|
125
|
+
expect(Encode(target, BigEndian, $.stringToBytes('xyz'))).toEqual([3, null])
|
|
126
|
+
expect($.bytesToString(target)).toBe('xyz')
|
|
127
|
+
expect(
|
|
128
|
+
Append($.stringToBytes('go'), BigEndian, $.stringToBytes('ts')),
|
|
129
|
+
).toEqual([$.stringToBytes('gots'), null])
|
|
130
|
+
expect(Size($.stringToBytes('data'))).toBe(4)
|
|
131
|
+
|
|
132
|
+
const readTarget = $.makeSlice<number>(3, undefined, 'byte')
|
|
133
|
+
expect(
|
|
134
|
+
await Read(
|
|
135
|
+
bytes.NewReader($.stringToBytes('bin'))!,
|
|
136
|
+
BigEndian,
|
|
137
|
+
readTarget,
|
|
138
|
+
),
|
|
139
|
+
).toBeNull()
|
|
140
|
+
expect($.bytesToString(readTarget)).toBe('bin')
|
|
141
|
+
|
|
142
|
+
const written: $.Bytes[] = []
|
|
143
|
+
const writer = {
|
|
144
|
+
Write(p: $.Bytes): [number, $.GoError] {
|
|
145
|
+
written.push($.bytesToUint8Array(p).slice())
|
|
146
|
+
return [$.len(p), null]
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
expect(await Write(writer, BigEndian, $.stringToBytes('out'))).toBeNull()
|
|
150
|
+
expect($.bytesToString(written[0])).toBe('out')
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('handles boxed fixed-width primitive fast paths', async () => {
|
|
154
|
+
const value = $.namedValueInterfaceValue<unknown>(0x1234, 'uint16', {})
|
|
155
|
+
const [encoded, encErr] = Append(null, BigEndian, value)
|
|
156
|
+
expect(encErr).toBeNull()
|
|
157
|
+
expect(Array.from($.bytesToUint8Array(encoded))).toEqual([0x12, 0x34])
|
|
158
|
+
|
|
159
|
+
const target = $.namedValueInterfaceValue<unknown>(
|
|
160
|
+
$.varRef(0),
|
|
161
|
+
'*uint16',
|
|
162
|
+
{},
|
|
163
|
+
)
|
|
164
|
+
expect(Decode(encoded, BigEndian, target)).toEqual([2, null])
|
|
165
|
+
expect($.pointerValue(target as any)).toBe(0x1234)
|
|
166
|
+
expect(Size(value)).toBe(2)
|
|
167
|
+
|
|
168
|
+
const polType: $.TypeInfo = {
|
|
169
|
+
kind: $.TypeKind.Basic,
|
|
170
|
+
name: 'uint64',
|
|
171
|
+
typeName: 'chunker.Pol',
|
|
172
|
+
}
|
|
173
|
+
const polValue = $.namedValueInterfaceValue<unknown>(
|
|
174
|
+
0x010203040506,
|
|
175
|
+
'chunker.Pol',
|
|
176
|
+
{},
|
|
177
|
+
polType,
|
|
178
|
+
)
|
|
179
|
+
const [polEncoded, polEncErr] = Append(null, LittleEndian, polValue)
|
|
180
|
+
expect(polEncErr).toBeNull()
|
|
181
|
+
expect(Array.from($.bytesToUint8Array(polEncoded))).toEqual([
|
|
182
|
+
0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00,
|
|
183
|
+
])
|
|
184
|
+
expect(Size(polValue)).toBe(8)
|
|
185
|
+
|
|
186
|
+
const polRef = $.varRef(0)
|
|
187
|
+
const polTarget = $.namedValueInterfaceValue<unknown>(
|
|
188
|
+
polRef,
|
|
189
|
+
'*chunker.Pol',
|
|
190
|
+
{},
|
|
191
|
+
{ kind: $.TypeKind.Pointer, elemType: polType },
|
|
192
|
+
)
|
|
193
|
+
expect(Decode(polEncoded, LittleEndian, polTarget)).toEqual([8, null])
|
|
194
|
+
expect(polRef.value).toBe(0x010203040506)
|
|
195
|
+
|
|
196
|
+
polRef.value = 0
|
|
197
|
+
expect(
|
|
198
|
+
await Read(bytes.NewReader(polEncoded)!, LittleEndian, polTarget),
|
|
199
|
+
).toBeNull()
|
|
200
|
+
expect(polRef.value).toBe(0x010203040506)
|
|
201
|
+
|
|
202
|
+
const written: $.Bytes[] = []
|
|
203
|
+
const writer = {
|
|
204
|
+
Write(p: $.Bytes): [number, $.GoError] {
|
|
205
|
+
written.push($.bytesToUint8Array(p).slice())
|
|
206
|
+
return [$.len(p), null]
|
|
207
|
+
},
|
|
208
|
+
}
|
|
209
|
+
expect(await Write(writer, LittleEndian, polValue)).toBeNull()
|
|
210
|
+
expect(Array.from(written[0])).toEqual([
|
|
211
|
+
0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00,
|
|
212
|
+
])
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('fails unsupported reflect-shaped cases closed', () => {
|
|
216
|
+
class StructLike {
|
|
217
|
+
public _fields = {
|
|
218
|
+
Value: $.varRef(1),
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const [, encodeErr] = Encode(
|
|
223
|
+
$.makeSlice<number>(8, undefined, 'byte'),
|
|
224
|
+
BigEndian,
|
|
225
|
+
new StructLike(),
|
|
226
|
+
)
|
|
227
|
+
expect(encodeErr?.Error()).toBe(
|
|
228
|
+
'encoding/binary: Encode of object is not supported in the GoScript browser build',
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
expect(Size(new StructLike())).toBe(-1)
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
it('panics on short endian buffers with Go-style bounds text', () => {
|
|
235
|
+
expect(() =>
|
|
236
|
+
BigEndian.PutUint32($.makeSlice<number>(1, undefined, 'byte'), 1),
|
|
237
|
+
).toThrow('runtime error: index out of range [3] with length 1')
|
|
238
|
+
})
|
|
239
|
+
})
|