goscript 0.0.84 → 0.1.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.
- package/README.md +267 -243
- package/cmd/goscript/cmd-test.go +193 -0
- package/cmd/goscript/cmd-test_test.go +76 -0
- package/cmd/goscript/cmd_compile.go +70 -69
- package/cmd/goscript/cmd_compile_test.go +79 -0
- package/cmd/goscript/main.go +11 -5
- package/compiler/build-flags.go +38 -0
- package/compiler/compile-request.go +220 -0
- package/compiler/compiler.go +16 -1336
- package/compiler/compliance_test.go +188 -0
- package/compiler/config.go +6 -13
- package/compiler/diagnostic.go +70 -0
- package/compiler/gotest/owner.go +24 -0
- package/compiler/gotest/package-result.go +67 -0
- package/compiler/gotest/request.go +145 -0
- package/compiler/gotest/result.go +28 -0
- package/compiler/gotest/runner.go +588 -0
- package/compiler/gotest/runner_test.go +627 -0
- package/compiler/gotest/test.go +9 -0
- package/compiler/index.test.ts +28 -28
- package/compiler/index.ts +40 -72
- package/compiler/lowered-program.go +184 -0
- package/compiler/lowering.go +8072 -0
- package/compiler/override-facts.go +307 -0
- package/compiler/override-registry.go +283 -0
- package/compiler/override-registry_test.go +254 -0
- package/compiler/package-graph.go +254 -0
- package/compiler/package-graph_test.go +316 -0
- package/compiler/package-test-function.go +9 -0
- package/compiler/package-test-graph-package.go +40 -0
- package/compiler/package-test-graph-variant.go +105 -0
- package/compiler/package-test-graph.go +117 -0
- package/compiler/package-test-graph_test.go +144 -0
- package/compiler/result.go +13 -0
- package/compiler/runtime-contract.go +439 -0
- package/compiler/runtime-contract_test.go +104 -0
- package/compiler/semantic-model-types.go +113 -0
- package/compiler/semantic-model.go +1422 -0
- package/compiler/semantic-model_test.go +471 -0
- package/compiler/service.go +133 -0
- package/compiler/skeleton_test.go +1775 -0
- package/compiler/tsworkspace/owner.go +334 -0
- package/compiler/tsworkspace/owner_test.go +93 -0
- package/compiler/tsworkspace/result.go +17 -0
- package/compiler/typescript-emitter.go +1040 -0
- package/compiler/wasm/compile.go +2 -3
- package/compiler/wasm/compile_test.go +79 -0
- package/compiler/wasm_api.go +140 -124
- package/dist/compiler/index.d.ts +1 -3
- package/dist/compiler/index.js +31 -55
- package/dist/compiler/index.js.map +1 -1
- package/dist/gs/builtin/builtin.d.ts +33 -2
- package/dist/gs/builtin/builtin.js +217 -6
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +11 -3
- package/dist/gs/builtin/channel.js +12 -0
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/builtin/hostio.d.ts +15 -1
- package/dist/gs/builtin/hostio.js +134 -49
- package/dist/gs/builtin/hostio.js.map +1 -1
- package/dist/gs/builtin/index.d.ts +1 -0
- package/dist/gs/builtin/index.js +1 -0
- package/dist/gs/builtin/index.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +23 -3
- package/dist/gs/builtin/slice.js +216 -44
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +16 -2
- package/dist/gs/builtin/type.js +134 -21
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +5 -0
- package/dist/gs/builtin/varRef.js +23 -0
- package/dist/gs/builtin/varRef.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.js +48 -44
- package/dist/gs/bytes/buffer.gs.js.map +1 -1
- package/dist/gs/bytes/bytes.gs.js.map +1 -1
- package/dist/gs/bytes/reader.gs.js +20 -18
- package/dist/gs/bytes/reader.gs.js.map +1 -1
- package/dist/gs/context/context.d.ts +5 -4
- package/dist/gs/context/context.js +10 -10
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.d.ts +1 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.js +2 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.js.map +1 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.d.ts +1 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.js +2 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.js.map +1 -0
- package/dist/gs/crypto/rand/index.d.ts +5 -0
- package/dist/gs/crypto/rand/index.js +77 -0
- package/dist/gs/crypto/rand/index.js.map +1 -0
- package/dist/gs/embed/index.d.ts +7 -0
- package/dist/gs/embed/index.js +16 -0
- package/dist/gs/embed/index.js.map +1 -0
- package/dist/gs/encoding/json/index.d.ts +4 -0
- package/dist/gs/encoding/json/index.js +178 -0
- package/dist/gs/encoding/json/index.js.map +1 -0
- package/dist/gs/errors/errors.d.ts +4 -0
- package/dist/gs/errors/errors.js +81 -0
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/fmt/fmt.d.ts +4 -4
- package/dist/gs/fmt/fmt.js +42 -11
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +36 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +212 -2
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.d.ts +189 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +825 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +163 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +449 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.js.map +1 -1
- package/dist/gs/github.com/klauspost/compress/internal/le/index.d.ts +9 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js +71 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
- package/dist/gs/go/internal/scannerhooks/index.d.ts +3 -0
- package/dist/gs/go/internal/scannerhooks/index.js +5 -0
- package/dist/gs/go/internal/scannerhooks/index.js.map +1 -0
- package/dist/gs/go/scanner/index.d.ts +42 -0
- package/dist/gs/go/scanner/index.js +155 -0
- package/dist/gs/go/scanner/index.js.map +1 -0
- package/dist/gs/go/token/index.d.ts +187 -0
- package/dist/gs/go/token/index.js +578 -0
- package/dist/gs/go/token/index.js.map +1 -0
- package/dist/gs/internal/abi/index.d.ts +4 -0
- package/dist/gs/internal/abi/index.js +10 -0
- package/dist/gs/internal/abi/index.js.map +1 -1
- package/dist/gs/internal/bytealg/index.d.ts +2 -0
- package/dist/gs/internal/bytealg/index.js +14 -0
- package/dist/gs/internal/bytealg/index.js.map +1 -1
- package/dist/gs/internal/byteorder/index.d.ts +8 -2
- package/dist/gs/internal/byteorder/index.js +56 -25
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/internal/godebug/index.d.ts +12 -0
- package/dist/gs/internal/godebug/index.js +30 -0
- package/dist/gs/internal/godebug/index.js.map +1 -0
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/io/fs/index.d.ts +1 -0
- package/dist/gs/io/fs/index.js +1 -0
- package/dist/gs/io/fs/index.js.map +1 -1
- package/dist/gs/io/fs/readdir.js.map +1 -1
- package/dist/gs/io/fs/readfile.js.map +1 -1
- package/dist/gs/io/fs/readlink.d.ts +8 -0
- package/dist/gs/io/fs/readlink.js +64 -0
- package/dist/gs/io/fs/readlink.js.map +1 -0
- package/dist/gs/io/fs/stat.js.map +1 -1
- package/dist/gs/io/fs/sub.js.map +1 -1
- package/dist/gs/io/fs/walk.d.ts +3 -3
- package/dist/gs/io/fs/walk.js +7 -7
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/io/io.d.ts +40 -6
- package/dist/gs/io/io.js +151 -26
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/maps/iter.d.ts +3 -3
- package/dist/gs/maps/iter.js +3 -3
- package/dist/gs/maps/iter.js.map +1 -1
- package/dist/gs/maps/maps.d.ts +2 -2
- package/dist/gs/maps/maps.js +1 -1
- package/dist/gs/maps/maps.js.map +1 -1
- package/dist/gs/math/bits/index.d.ts +13 -4
- package/dist/gs/math/bits/index.js +66 -34
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/math/const.gs.d.ts +5 -5
- package/dist/gs/math/const.gs.js +4 -4
- package/dist/gs/math/const.gs.js.map +1 -1
- package/dist/gs/mime/index.d.ts +1 -0
- package/dist/gs/mime/index.js +50 -0
- package/dist/gs/mime/index.js.map +1 -0
- package/dist/gs/net/http/httptest/index.d.ts +11 -0
- package/dist/gs/net/http/httptest/index.js +21 -0
- package/dist/gs/net/http/httptest/index.js.map +1 -0
- package/dist/gs/net/http/index.d.ts +27 -0
- package/dist/gs/net/http/index.js +61 -0
- package/dist/gs/net/http/index.js.map +1 -0
- package/dist/gs/os/dir_unix.gs.js +2 -2
- package/dist/gs/os/dir_unix.gs.js.map +1 -1
- package/dist/gs/os/error.gs.js +2 -4
- package/dist/gs/os/error.gs.js.map +1 -1
- package/dist/gs/os/exec.gs.js.map +1 -1
- package/dist/gs/os/exec_posix.gs.js.map +1 -1
- package/dist/gs/os/rawconn_js.gs.js.map +1 -1
- package/dist/gs/os/root_js.gs.js.map +1 -1
- package/dist/gs/os/tempfile.gs.js +66 -9
- package/dist/gs/os/tempfile.gs.js.map +1 -1
- package/dist/gs/os/types.gs.js.map +1 -1
- package/dist/gs/os/types_js.gs.js +9 -9
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/os/types_unix.gs.js.map +1 -1
- package/dist/gs/path/filepath/match.js +165 -3
- package/dist/gs/path/filepath/match.js.map +1 -1
- package/dist/gs/path/filepath/path.d.ts +3 -1
- package/dist/gs/path/filepath/path.js +133 -4
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/path/match.js.map +1 -1
- package/dist/gs/path/path.d.ts +4 -1
- package/dist/gs/path/path.js +16 -4
- package/dist/gs/path/path.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +3 -3
- package/dist/gs/reflect/index.js +2 -2
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/map.js +3 -0
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +9 -5
- package/dist/gs/reflect/type.js +233 -21
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/reflect/types.js.map +1 -1
- package/dist/gs/reflect/visiblefields.js.map +1 -1
- package/dist/gs/runtime/debug/index.d.ts +2 -0
- package/dist/gs/runtime/debug/index.js +8 -0
- package/dist/gs/runtime/debug/index.js.map +1 -0
- package/dist/gs/runtime/runtime.d.ts +35 -3
- package/dist/gs/runtime/runtime.js +72 -0
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/slices/slices.d.ts +24 -5
- package/dist/gs/slices/slices.js +214 -5
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sort/slice.gs.d.ts +3 -3
- package/dist/gs/sort/slice.gs.js +6 -6
- package/dist/gs/sort/slice.gs.js.map +1 -1
- package/dist/gs/sort/sort.gs.d.ts +4 -4
- package/dist/gs/sort/sort.gs.js +11 -8
- package/dist/gs/sort/sort.gs.js.map +1 -1
- package/dist/gs/strconv/atoi.gs.js.map +1 -1
- package/dist/gs/strconv/quote.gs.js.map +1 -1
- package/dist/gs/strings/builder.d.ts +1 -1
- package/dist/gs/strings/builder.js +3 -2
- package/dist/gs/strings/builder.js.map +1 -1
- package/dist/gs/strings/reader.js.map +1 -1
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/sync/atomic/type.gs.d.ts +9 -8
- package/dist/gs/sync/atomic/type.gs.js +0 -2
- package/dist/gs/sync/atomic/type.gs.js.map +1 -1
- package/dist/gs/sync/atomic/value.gs.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +3 -0
- package/dist/gs/sync/sync.js +39 -0
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/syscall/constants.d.ts +36 -24
- package/dist/gs/syscall/constants.js +12 -0
- package/dist/gs/syscall/constants.js.map +1 -1
- package/dist/gs/syscall/errors.d.ts +2 -0
- package/dist/gs/syscall/errors.js +8 -0
- package/dist/gs/syscall/errors.js.map +1 -1
- package/dist/gs/syscall/fs.d.ts +43 -0
- package/dist/gs/syscall/fs.js +102 -0
- package/dist/gs/syscall/fs.js.map +1 -1
- package/dist/gs/syscall/js/index.d.ts +90 -0
- package/dist/gs/syscall/js/index.js +375 -0
- package/dist/gs/syscall/js/index.js.map +1 -0
- package/dist/gs/syscall/types.d.ts +22 -0
- package/dist/gs/syscall/types.js +45 -1
- package/dist/gs/syscall/types.js.map +1 -1
- package/dist/gs/testing/index.d.ts +1 -0
- package/dist/gs/testing/index.js +2 -0
- package/dist/gs/testing/index.js.map +1 -0
- package/dist/gs/testing/testing.d.ts +77 -0
- package/dist/gs/testing/testing.js +301 -0
- package/dist/gs/testing/testing.js.map +1 -0
- package/dist/gs/time/time.d.ts +41 -4
- package/dist/gs/time/time.js +205 -36
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/unicode.d.ts +23 -1
- package/dist/gs/unicode/unicode.js +79 -10
- package/dist/gs/unicode/unicode.js.map +1 -1
- package/dist/gs/unicode/utf8/utf8.d.ts +4 -4
- package/dist/gs/unicode/utf8/utf8.js +24 -11
- package/dist/gs/unicode/utf8/utf8.js.map +1 -1
- package/dist/gs/unique/index.d.ts +11 -0
- package/dist/gs/unique/index.js +71 -0
- package/dist/gs/unique/index.js.map +1 -0
- package/go.mod +2 -2
- package/go.sum +9 -0
- package/gs/builtin/builtin.ts +266 -8
- package/gs/builtin/channel.ts +22 -0
- package/gs/builtin/hostio.test.ts +177 -0
- package/gs/builtin/hostio.ts +171 -56
- package/gs/builtin/index.ts +1 -0
- package/gs/builtin/runtime-contract.test.ts +356 -0
- package/gs/builtin/slice.ts +259 -50
- package/gs/builtin/type.ts +188 -30
- package/gs/builtin/varRef.ts +38 -1
- package/gs/bytes/buffer.gs.ts +48 -44
- package/gs/bytes/meta.json +8 -3
- package/gs/bytes/reader.gs.ts +20 -19
- package/gs/context/context.test.ts +41 -0
- package/gs/context/context.ts +22 -26
- package/gs/crypto/internal/fips140deps/byteorder/index.ts +1 -0
- package/gs/crypto/internal/fips140deps/godebug/index.ts +1 -0
- package/gs/crypto/rand/index.test.ts +32 -0
- package/gs/crypto/rand/index.ts +90 -0
- package/gs/crypto/rand/meta.json +5 -0
- package/gs/embed/index.ts +20 -0
- package/gs/embed/meta.json +5 -0
- package/gs/encoding/json/index.test.ts +79 -0
- package/gs/encoding/json/index.ts +210 -0
- package/gs/errors/errors.test.ts +82 -0
- package/gs/errors/errors.ts +104 -0
- package/gs/fmt/fmt.ts +56 -16
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +95 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +300 -2
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +159 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +1005 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +719 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +40 -0
- package/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/meta.json +3 -1
- package/gs/github.com/klauspost/compress/internal/le/index.test.ts +36 -0
- package/gs/github.com/klauspost/compress/internal/le/index.ts +114 -0
- package/gs/go/internal/scannerhooks/index.test.ts +14 -0
- package/gs/go/internal/scannerhooks/index.ts +9 -0
- package/gs/go/scanner/index.test.ts +72 -0
- package/gs/go/scanner/index.ts +204 -0
- package/gs/go/token/index.test.ts +67 -0
- package/gs/go/token/index.ts +686 -0
- package/gs/internal/abi/index.test.ts +18 -0
- package/gs/internal/abi/index.ts +14 -0
- package/gs/internal/bytealg/index.test.ts +18 -0
- package/gs/internal/bytealg/index.ts +16 -0
- package/gs/internal/byteorder/index.test.ts +39 -0
- package/gs/internal/byteorder/index.ts +100 -27
- package/gs/internal/godebug/index.test.ts +16 -0
- package/gs/internal/godebug/index.ts +35 -0
- package/gs/io/fs/index.ts +1 -0
- package/gs/io/fs/meta.json +5 -0
- package/gs/io/fs/readlink.test.ts +43 -0
- package/gs/io/fs/readlink.ts +77 -0
- package/gs/io/fs/walk.test.ts +61 -0
- package/gs/io/fs/walk.ts +9 -9
- package/gs/io/io.ts +174 -31
- package/gs/io/meta.json +10 -2
- package/gs/maps/iter.ts +12 -6
- package/gs/maps/maps.ts +8 -6
- package/gs/math/bits/index.ts +103 -47
- package/gs/math/const.gs.test.ts +11 -5
- package/gs/math/const.gs.ts +5 -6
- package/gs/mime/index.ts +54 -0
- package/gs/net/http/httptest/index.ts +25 -0
- package/gs/net/http/index.test.ts +20 -0
- package/gs/net/http/index.ts +81 -0
- package/gs/os/dir_unix.gs.ts +2 -3
- package/gs/os/file_unix_js.test.ts +50 -0
- package/gs/os/meta.json +1 -2
- package/gs/os/tempfile.gs.test.ts +85 -0
- package/gs/os/tempfile.gs.ts +71 -11
- package/gs/os/types_js.gs.ts +11 -11
- package/gs/path/filepath/match.test.ts +31 -12
- package/gs/path/filepath/match.ts +178 -3
- package/gs/path/filepath/path.test.ts +25 -0
- package/gs/path/filepath/path.ts +159 -5
- package/gs/path/path.ts +20 -5
- package/gs/reflect/index.ts +2 -1
- package/gs/reflect/map.test.ts +19 -0
- package/gs/reflect/map.ts +4 -0
- package/gs/reflect/type.ts +298 -29
- package/gs/reflect/typefor.test.ts +75 -0
- package/gs/runtime/debug/index.test.ts +24 -0
- package/gs/runtime/debug/index.ts +8 -0
- package/gs/runtime/runtime.test.ts +19 -0
- package/gs/runtime/runtime.ts +98 -3
- package/gs/slices/slices.test.ts +94 -0
- package/gs/slices/slices.ts +245 -5
- package/gs/sort/meta.json +7 -0
- package/gs/sort/slice.gs.ts +16 -7
- package/gs/sort/sort.gs.ts +16 -13
- package/gs/strings/builder.ts +4 -3
- package/gs/sync/atomic/type.gs.ts +13 -14
- package/gs/sync/meta.json +3 -1
- package/gs/sync/sync.test.ts +36 -0
- package/gs/sync/sync.ts +39 -0
- package/gs/syscall/constants.ts +39 -24
- package/gs/syscall/errors.ts +10 -0
- package/gs/syscall/fs.ts +195 -0
- package/gs/syscall/js/index.ts +458 -0
- package/gs/syscall/js/meta.json +4 -0
- package/gs/syscall/net.test.ts +85 -0
- package/gs/syscall/types.ts +56 -0
- package/gs/testing/index.ts +1 -0
- package/gs/testing/meta.json +5 -0
- package/gs/testing/testing.test.ts +90 -0
- package/gs/testing/testing.ts +382 -0
- package/gs/time/time.test.ts +106 -0
- package/gs/time/time.ts +278 -57
- package/gs/unicode/unicode.test.ts +25 -0
- package/gs/unicode/unicode.ts +119 -9
- package/gs/unicode/utf8/utf8.test.ts +13 -0
- package/gs/unicode/utf8/utf8.ts +28 -16
- package/gs/unique/index.ts +91 -0
- package/package.json +14 -13
- package/compiler/analysis.go +0 -3475
- package/compiler/analysis_test.go +0 -338
- package/compiler/assignment.go +0 -580
- package/compiler/builtin_test.go +0 -92
- package/compiler/code-writer.go +0 -115
- package/compiler/compiler_test.go +0 -149
- package/compiler/composite-lit.go +0 -779
- package/compiler/config_test.go +0 -62
- package/compiler/constraint.go +0 -86
- package/compiler/decl.go +0 -801
- package/compiler/expr-call-async.go +0 -188
- package/compiler/expr-call-builtins.go +0 -208
- package/compiler/expr-call-helpers.go +0 -382
- package/compiler/expr-call-make.go +0 -318
- package/compiler/expr-call-type-conversion.go +0 -520
- package/compiler/expr-call.go +0 -413
- package/compiler/expr-selector.go +0 -343
- package/compiler/expr-star.go +0 -82
- package/compiler/expr-type.go +0 -442
- package/compiler/expr-value.go +0 -89
- package/compiler/expr.go +0 -773
- package/compiler/field.go +0 -183
- package/compiler/gs_dependencies_test.go +0 -298
- package/compiler/lit.go +0 -322
- package/compiler/output.go +0 -72
- package/compiler/primitive.go +0 -149
- package/compiler/protobuf.go +0 -697
- package/compiler/sanitize.go +0 -100
- package/compiler/spec-struct.go +0 -995
- package/compiler/spec-value.go +0 -540
- package/compiler/spec.go +0 -725
- package/compiler/stmt-assign.go +0 -664
- package/compiler/stmt-for.go +0 -266
- package/compiler/stmt-range.go +0 -475
- package/compiler/stmt-select.go +0 -262
- package/compiler/stmt-type-switch.go +0 -147
- package/compiler/stmt.go +0 -1308
- package/compiler/type-assert.go +0 -386
- package/compiler/type-info.go +0 -156
- package/compiler/type-utils.go +0 -207
- package/compiler/type.go +0 -892
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
|
|
3
|
+
export type Type = number
|
|
4
|
+
|
|
5
|
+
export const TypeUndefined: Type = 0
|
|
6
|
+
export const TypeNull: Type = 1
|
|
7
|
+
export const TypeBoolean: Type = 2
|
|
8
|
+
export const TypeNumber: Type = 3
|
|
9
|
+
export const TypeString: Type = 4
|
|
10
|
+
export const TypeSymbol: Type = 5
|
|
11
|
+
export const TypeObject: Type = 6
|
|
12
|
+
export const TypeFunction: Type = 7
|
|
13
|
+
|
|
14
|
+
export class Value {
|
|
15
|
+
public _raw: unknown
|
|
16
|
+
|
|
17
|
+
constructor(init?: Partial<{ raw: unknown }> | unknown) {
|
|
18
|
+
if (isRawInit(init)) {
|
|
19
|
+
this._raw = init.raw
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
this._raw = init
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public clone(): Value {
|
|
26
|
+
return new Value({ raw: this._raw })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public Equal(w: Value): boolean {
|
|
30
|
+
return this._raw === w._raw && !Number.isNaN(this._raw)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public IsUndefined(): boolean {
|
|
34
|
+
return this._raw === undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public IsNull(): boolean {
|
|
38
|
+
return this._raw === null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public IsNaN(): boolean {
|
|
42
|
+
return typeof this._raw === 'number' && Number.isNaN(this._raw)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public Type(): Type {
|
|
46
|
+
if (this._raw === undefined) {
|
|
47
|
+
return TypeUndefined
|
|
48
|
+
}
|
|
49
|
+
if (this._raw === null) {
|
|
50
|
+
return TypeNull
|
|
51
|
+
}
|
|
52
|
+
switch (typeof this._raw) {
|
|
53
|
+
case 'boolean':
|
|
54
|
+
return TypeBoolean
|
|
55
|
+
case 'number':
|
|
56
|
+
return TypeNumber
|
|
57
|
+
case 'string':
|
|
58
|
+
return TypeString
|
|
59
|
+
case 'symbol':
|
|
60
|
+
return TypeSymbol
|
|
61
|
+
case 'function':
|
|
62
|
+
return TypeFunction
|
|
63
|
+
case 'object':
|
|
64
|
+
return TypeObject
|
|
65
|
+
default:
|
|
66
|
+
$.panic('bad type')
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public Get(p: string): Value {
|
|
71
|
+
this.requireObject('Value.Get')
|
|
72
|
+
return new Value({ raw: Reflect.get(this._raw as object, p) })
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public Set(p: string, x: unknown): void {
|
|
76
|
+
this.requireObject('Value.Set')
|
|
77
|
+
Reflect.set(this._raw as object, p, ValueOf(x)._raw)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public Delete(p: string): void {
|
|
81
|
+
this.requireObject('Value.Delete')
|
|
82
|
+
Reflect.deleteProperty(this._raw as object, p)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public Index(i: number): Value {
|
|
86
|
+
this.requireObject('Value.Index')
|
|
87
|
+
return new Value({ raw: Reflect.get(this._raw as object, i) })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public SetIndex(i: number, x: unknown): void {
|
|
91
|
+
this.requireObject('Value.SetIndex')
|
|
92
|
+
Reflect.set(this._raw as object, i, ValueOf(x)._raw)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public Length(): number {
|
|
96
|
+
this.requireObject('Value.SetIndex')
|
|
97
|
+
return Number(Reflect.get(this._raw as object, 'length') ?? 0)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public Call(m: string, ...args: unknown[]): Value {
|
|
101
|
+
this.requireObject('Value.Call')
|
|
102
|
+
const fn = Reflect.get(this._raw as object, m)
|
|
103
|
+
if (typeof fn !== 'function') {
|
|
104
|
+
$.panic(
|
|
105
|
+
`syscall/js: Value.Call: property ${m} is not a function, got ${Type_String(ValueOf(fn).Type())}`,
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
return new Value({ raw: fn.apply(this._raw, args.map((arg) => ValueOf(arg)._raw)) })
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public Invoke(...args: unknown[]): Value {
|
|
112
|
+
if (typeof this._raw !== 'function') {
|
|
113
|
+
$.panic(new ValueError({ Method: 'Value.Invoke', Type: this.Type() }))
|
|
114
|
+
}
|
|
115
|
+
return new Value({ raw: this._raw(...args.map((arg) => ValueOf(arg)._raw)) })
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public New(...args: unknown[]): Value {
|
|
119
|
+
if (typeof this._raw !== 'function') {
|
|
120
|
+
$.panic(new ValueError({ Method: 'Value.Invoke', Type: this.Type() }))
|
|
121
|
+
}
|
|
122
|
+
return new Value({
|
|
123
|
+
raw: Reflect.construct(this._raw, args.map((arg) => ValueOf(arg)._raw)),
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public InstanceOf(t: Value): boolean {
|
|
128
|
+
if (typeof t._raw !== 'function') {
|
|
129
|
+
return false
|
|
130
|
+
}
|
|
131
|
+
return this._raw instanceof t._raw
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public Float(): number {
|
|
135
|
+
return this.number('Value.Float')
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public Int(): number {
|
|
139
|
+
return Math.trunc(this.number('Value.Int'))
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public Bool(): boolean {
|
|
143
|
+
if (typeof this._raw !== 'boolean') {
|
|
144
|
+
$.panic(new ValueError({ Method: 'Value.Bool', Type: this.Type() }))
|
|
145
|
+
}
|
|
146
|
+
return this._raw
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public Truthy(): boolean {
|
|
150
|
+
return !!this._raw
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public String(): string {
|
|
154
|
+
switch (this.Type()) {
|
|
155
|
+
case TypeString:
|
|
156
|
+
return this._raw as string
|
|
157
|
+
case TypeUndefined:
|
|
158
|
+
return '<undefined>'
|
|
159
|
+
case TypeNull:
|
|
160
|
+
return '<null>'
|
|
161
|
+
case TypeBoolean:
|
|
162
|
+
case TypeNumber:
|
|
163
|
+
return `<${Type_String(this.Type())}: ${String(this._raw)}>`
|
|
164
|
+
case TypeSymbol:
|
|
165
|
+
return '<symbol>'
|
|
166
|
+
case TypeObject:
|
|
167
|
+
return '<object>'
|
|
168
|
+
case TypeFunction:
|
|
169
|
+
return '<function>'
|
|
170
|
+
default:
|
|
171
|
+
$.panic('bad type')
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private requireObject(method: string): void {
|
|
176
|
+
if (!Type_isObject(this.Type())) {
|
|
177
|
+
$.panic(new ValueError({ Method: method, Type: this.Type() }))
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private number(method: string): number {
|
|
182
|
+
if (typeof this._raw !== 'number') {
|
|
183
|
+
$.panic(new ValueError({ Method: method, Type: this.Type() }))
|
|
184
|
+
}
|
|
185
|
+
return this._raw
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export class Error {
|
|
190
|
+
public Value: Value
|
|
191
|
+
|
|
192
|
+
constructor(init?: Partial<Error>) {
|
|
193
|
+
this.Value = init?.Value?.clone() ?? Undefined()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public clone(): Error {
|
|
197
|
+
return new Error({ Value: this.Value })
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
public Error(): string {
|
|
201
|
+
return `JavaScript error: ${this.Value.Get('message').String()}`
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export class ValueError {
|
|
206
|
+
public Method: string
|
|
207
|
+
public Type: Type
|
|
208
|
+
|
|
209
|
+
constructor(init?: Partial<ValueError>) {
|
|
210
|
+
this.Method = init?.Method ?? ''
|
|
211
|
+
this.Type = init?.Type ?? TypeUndefined
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public clone(): ValueError {
|
|
215
|
+
return new ValueError({ Method: this.Method, Type: this.Type })
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
public Error(): string {
|
|
219
|
+
return `syscall/js: call of ${this.Method} on ${Type_String(this.Type)}`
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export class Func {
|
|
224
|
+
public Value: Value
|
|
225
|
+
private _released = false
|
|
226
|
+
|
|
227
|
+
constructor(init?: Partial<Func> & { fn?: (this$: Value, args: $.Slice<Value>) => unknown }) {
|
|
228
|
+
const fn = init?.fn
|
|
229
|
+
this.Value = init?.Value?.clone() ?? new Value({
|
|
230
|
+
raw: function (this: unknown, ...args: unknown[]) {
|
|
231
|
+
if (fn === undefined) {
|
|
232
|
+
return undefined
|
|
233
|
+
}
|
|
234
|
+
return ValueOf(
|
|
235
|
+
fn(
|
|
236
|
+
new Value({ raw: this }),
|
|
237
|
+
args.map((arg) => new Value({ raw: arg })) as $.Slice<Value>,
|
|
238
|
+
),
|
|
239
|
+
)._raw
|
|
240
|
+
},
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public clone(): Func {
|
|
245
|
+
return new Func({ Value: this.Value })
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public Release(): void {
|
|
249
|
+
this._released = true
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public Equal(w: Value): boolean {
|
|
253
|
+
return this.Value.Equal(w)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public IsUndefined(): boolean {
|
|
257
|
+
return this.Value.IsUndefined()
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public IsNull(): boolean {
|
|
261
|
+
return this.Value.IsNull()
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public IsNaN(): boolean {
|
|
265
|
+
return this.Value.IsNaN()
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public Type(): Type {
|
|
269
|
+
return this.Value.Type()
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
public Get(p: string): Value {
|
|
273
|
+
return this.Value.Get(p)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
public Set(p: string, x: unknown): void {
|
|
277
|
+
this.Value.Set(p, x)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public Delete(p: string): void {
|
|
281
|
+
this.Value.Delete(p)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
public Index(i: number): Value {
|
|
285
|
+
return this.Value.Index(i)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
public SetIndex(i: number, x: unknown): void {
|
|
289
|
+
this.Value.SetIndex(i, x)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public Length(): number {
|
|
293
|
+
return this.Value.Length()
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
public Call(m: string, ...args: unknown[]): Value {
|
|
297
|
+
return this.Value.Call(m, ...args)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
public Invoke(...args: unknown[]): Value {
|
|
301
|
+
return this.Value.Invoke(...args)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public New(...args: unknown[]): Value {
|
|
305
|
+
return this.Value.New(...args)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
public InstanceOf(t: Value): boolean {
|
|
309
|
+
return this.Value.InstanceOf(t)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
public Float(): number {
|
|
313
|
+
return this.Value.Float()
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
public Int(): number {
|
|
317
|
+
return this.Value.Int()
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
public Bool(): boolean {
|
|
321
|
+
return this.Value.Bool()
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
public Truthy(): boolean {
|
|
325
|
+
return this.Value.Truthy()
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
public String(): string {
|
|
329
|
+
return this.Value.String()
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function Undefined(): Value {
|
|
334
|
+
return new Value({ raw: undefined })
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function Null(): Value {
|
|
338
|
+
return new Value({ raw: null })
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export function Global(): Value {
|
|
342
|
+
return new Value({ raw: globalThis })
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export function ValueOf(x: unknown): Value {
|
|
346
|
+
if (x instanceof Value) {
|
|
347
|
+
return x.clone()
|
|
348
|
+
}
|
|
349
|
+
if (x instanceof Func) {
|
|
350
|
+
return x.Value.clone()
|
|
351
|
+
}
|
|
352
|
+
if (x === null || x === undefined) {
|
|
353
|
+
return Null()
|
|
354
|
+
}
|
|
355
|
+
if (typeof x === 'boolean' || typeof x === 'number' || typeof x === 'string') {
|
|
356
|
+
return new Value({ raw: x })
|
|
357
|
+
}
|
|
358
|
+
if (typeof x === 'bigint') {
|
|
359
|
+
return new Value({ raw: Number(x) })
|
|
360
|
+
}
|
|
361
|
+
if (x instanceof Uint8Array) {
|
|
362
|
+
return new Value({ raw: x })
|
|
363
|
+
}
|
|
364
|
+
if (Array.isArray(x)) {
|
|
365
|
+
return new Value({ raw: x.map((item) => ValueOf(item)._raw) })
|
|
366
|
+
}
|
|
367
|
+
if (x instanceof Map) {
|
|
368
|
+
const out: Record<string, unknown> = {}
|
|
369
|
+
for (const [key, value] of x.entries()) {
|
|
370
|
+
out[String(key)] = ValueOf(value)._raw
|
|
371
|
+
}
|
|
372
|
+
return new Value({ raw: out })
|
|
373
|
+
}
|
|
374
|
+
return new Value({ raw: x })
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export function FuncOf(
|
|
378
|
+
fn: (this$: Value, args: $.Slice<Value>) => unknown,
|
|
379
|
+
): Func {
|
|
380
|
+
return new Func({ fn })
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export function Type_String(t: Type): string {
|
|
384
|
+
switch (t) {
|
|
385
|
+
case TypeUndefined:
|
|
386
|
+
return 'undefined'
|
|
387
|
+
case TypeNull:
|
|
388
|
+
return 'null'
|
|
389
|
+
case TypeBoolean:
|
|
390
|
+
return 'boolean'
|
|
391
|
+
case TypeNumber:
|
|
392
|
+
return 'number'
|
|
393
|
+
case TypeString:
|
|
394
|
+
return 'string'
|
|
395
|
+
case TypeSymbol:
|
|
396
|
+
return 'symbol'
|
|
397
|
+
case TypeObject:
|
|
398
|
+
return 'object'
|
|
399
|
+
case TypeFunction:
|
|
400
|
+
return 'function'
|
|
401
|
+
default:
|
|
402
|
+
$.panic('bad type')
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export function Type_isObject(t: Type): boolean {
|
|
407
|
+
return t === TypeObject || t === TypeFunction
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export function CopyBytesToGo(dst: $.Bytes | null, src: Value): number {
|
|
411
|
+
const bytes = sourceBytes(src)
|
|
412
|
+
const n = Math.min($.len(dst), bytes.length)
|
|
413
|
+
if (dst instanceof Uint8Array) {
|
|
414
|
+
dst.set(bytes.subarray(0, n), 0)
|
|
415
|
+
return n
|
|
416
|
+
}
|
|
417
|
+
const arr = $.asArray(dst)
|
|
418
|
+
for (let i = 0; i < n; i++) {
|
|
419
|
+
arr[i] = bytes[i]
|
|
420
|
+
}
|
|
421
|
+
return n
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export function CopyBytesToJS(dst: Value, src: $.Bytes | null): number {
|
|
425
|
+
const target = dstRawBytes(dst)
|
|
426
|
+
const bytes = src instanceof Uint8Array ? src : Uint8Array.from($.asArray(src))
|
|
427
|
+
const n = Math.min(target.length, bytes.length)
|
|
428
|
+
target.set(bytes.subarray(0, n), 0)
|
|
429
|
+
return n
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function sourceBytes(src: Value): Uint8Array {
|
|
433
|
+
const raw = srcRaw(src)
|
|
434
|
+
if (raw instanceof Uint8Array || raw instanceof Uint8ClampedArray) {
|
|
435
|
+
return raw instanceof Uint8Array ? raw : new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength)
|
|
436
|
+
}
|
|
437
|
+
$.panic('syscall/js: CopyBytesToGo: expected src to be a Uint8Array or Uint8ClampedArray')
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function dstRawBytes(dst: Value): Uint8Array | Uint8ClampedArray {
|
|
441
|
+
const raw = srcRaw(dst)
|
|
442
|
+
if (raw instanceof Uint8Array || raw instanceof Uint8ClampedArray) {
|
|
443
|
+
return raw
|
|
444
|
+
}
|
|
445
|
+
$.panic('syscall/js: CopyBytesToJS: expected dst to be a Uint8Array or Uint8ClampedArray')
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function srcRaw(value: Value): unknown {
|
|
449
|
+
return (value as unknown as { _raw: unknown })._raw
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function isRawInit(value: unknown): value is { raw: unknown } {
|
|
453
|
+
return (
|
|
454
|
+
typeof value === 'object' &&
|
|
455
|
+
value !== null &&
|
|
456
|
+
Object.prototype.hasOwnProperty.call(value, 'raw')
|
|
457
|
+
)
|
|
458
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Bind,
|
|
5
|
+
Close,
|
|
6
|
+
CloseOnExec,
|
|
7
|
+
Connect,
|
|
8
|
+
Dup,
|
|
9
|
+
ENOSYS,
|
|
10
|
+
ENOTSUP,
|
|
11
|
+
GetsockoptInt,
|
|
12
|
+
Iovec,
|
|
13
|
+
IPPROTO_IPV6,
|
|
14
|
+
IPPROTO_TCP,
|
|
15
|
+
IPV6_V6ONLY,
|
|
16
|
+
Listen,
|
|
17
|
+
Pread,
|
|
18
|
+
Pwrite,
|
|
19
|
+
Read,
|
|
20
|
+
ReadDirent,
|
|
21
|
+
Recvfrom,
|
|
22
|
+
Recvmsg,
|
|
23
|
+
Seek,
|
|
24
|
+
SendmsgN,
|
|
25
|
+
Sendto,
|
|
26
|
+
SetReadDeadline,
|
|
27
|
+
SetNonblock,
|
|
28
|
+
SetsockoptInt,
|
|
29
|
+
SetWriteDeadline,
|
|
30
|
+
Shutdown,
|
|
31
|
+
SOCK_SEQPACKET,
|
|
32
|
+
SOMAXCONN,
|
|
33
|
+
Socket,
|
|
34
|
+
StopIO,
|
|
35
|
+
Write,
|
|
36
|
+
readv,
|
|
37
|
+
writev,
|
|
38
|
+
} from './index.js'
|
|
39
|
+
|
|
40
|
+
describe('syscall network stubs', () => {
|
|
41
|
+
test('exports network constants used by generated net', () => {
|
|
42
|
+
expect(SOCK_SEQPACKET).toBe(5)
|
|
43
|
+
expect(IPPROTO_IPV6).toBe(0x29)
|
|
44
|
+
expect(IPPROTO_TCP).toBe(6)
|
|
45
|
+
expect(IPV6_V6ONLY).toBe(0x1a)
|
|
46
|
+
expect(SOMAXCONN).toBe(0x80)
|
|
47
|
+
expect(ENOTSUP.Error()).toBe('operation not supported')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('reports unsupported socket operations as syscall errors', () => {
|
|
51
|
+
expect(Socket(0, 0, 0)).toEqual([-1, ENOSYS])
|
|
52
|
+
expect(Connect(-1, null)).toBe(ENOSYS)
|
|
53
|
+
expect(Listen(-1, 0)).toBe(ENOSYS)
|
|
54
|
+
expect(Bind(-1, null)).toBe(ENOSYS)
|
|
55
|
+
expect(StopIO(-1)).toBe(ENOSYS)
|
|
56
|
+
expect(Recvfrom(-1, null, 0)).toEqual([0, null, ENOSYS])
|
|
57
|
+
expect(Sendto(-1, null, 0, null)).toBe(ENOSYS)
|
|
58
|
+
expect(Recvmsg(-1, null, null, 0)).toEqual([0, 0, 0, null, ENOSYS])
|
|
59
|
+
expect(SendmsgN(-1, null, null, null, 0)).toEqual([0, ENOSYS])
|
|
60
|
+
expect(GetsockoptInt(-1, 0, 0)).toEqual([0, ENOSYS])
|
|
61
|
+
expect(SetsockoptInt(-1, 0, 0, 0)).toBeNull()
|
|
62
|
+
expect(SetReadDeadline(-1, 0)).toBe(ENOSYS)
|
|
63
|
+
expect(SetWriteDeadline(-1, 0)).toBe(ENOSYS)
|
|
64
|
+
expect(Shutdown(-1, 0)).toBe(ENOSYS)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('exports JavaScript no-op descriptor flag helpers', () => {
|
|
68
|
+
expect(Close(1)).toBeNull()
|
|
69
|
+
expect(CloseOnExec(1)).toBeUndefined()
|
|
70
|
+
expect(SetNonblock(1, true)).toBeNull()
|
|
71
|
+
expect(SetNonblock(1, false)).toBeNull()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('exports unsupported descriptor operations', () => {
|
|
75
|
+
expect(Read(-1, null)).toEqual([0, ENOSYS])
|
|
76
|
+
expect(ReadDirent(-1, null)).toEqual([0, ENOSYS])
|
|
77
|
+
expect(Pread(-1, null, 0)).toEqual([0, ENOSYS])
|
|
78
|
+
expect(Pwrite(-1, null, 0)).toEqual([0, ENOSYS])
|
|
79
|
+
expect(Seek(-1, 0, 0)).toEqual([0, ENOSYS])
|
|
80
|
+
expect(Write(-1, null)).toEqual([0, ENOSYS])
|
|
81
|
+
expect(Dup(-1)).toEqual([0, ENOSYS])
|
|
82
|
+
expect(readv(-1, [new Iovec()])).toEqual([0, ENOSYS])
|
|
83
|
+
expect(writev(-1, [new Iovec()])).toEqual([0, ENOSYS])
|
|
84
|
+
})
|
|
85
|
+
})
|
package/gs/syscall/types.ts
CHANGED
|
@@ -16,3 +16,59 @@ export interface RawConn {
|
|
|
16
16
|
Read(f: (fd: uintptr) => boolean): $.GoError
|
|
17
17
|
Write(f: (fd: uintptr) => boolean): $.GoError
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
export interface Sockaddr {}
|
|
21
|
+
|
|
22
|
+
export class SockaddrInet4 implements Sockaddr {
|
|
23
|
+
public Port: number = 0
|
|
24
|
+
public Addr: Uint8Array = new Uint8Array(4)
|
|
25
|
+
|
|
26
|
+
constructor(init?: Partial<SockaddrInet4>) {
|
|
27
|
+
if (init) {
|
|
28
|
+
Object.assign(this, init)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public clone(): SockaddrInet4 {
|
|
33
|
+
return new SockaddrInet4({
|
|
34
|
+
Port: this.Port,
|
|
35
|
+
Addr: new Uint8Array(this.Addr),
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class SockaddrInet6 implements Sockaddr {
|
|
41
|
+
public Port: number = 0
|
|
42
|
+
public ZoneId: number = 0
|
|
43
|
+
public Addr: Uint8Array = new Uint8Array(16)
|
|
44
|
+
|
|
45
|
+
constructor(init?: Partial<SockaddrInet6>) {
|
|
46
|
+
if (init) {
|
|
47
|
+
Object.assign(this, init)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public clone(): SockaddrInet6 {
|
|
52
|
+
return new SockaddrInet6({
|
|
53
|
+
Port: this.Port,
|
|
54
|
+
ZoneId: this.ZoneId,
|
|
55
|
+
Addr: new Uint8Array(this.Addr),
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class SockaddrUnix implements Sockaddr {
|
|
61
|
+
public Name: string = ''
|
|
62
|
+
|
|
63
|
+
constructor(init?: Partial<SockaddrUnix>) {
|
|
64
|
+
if (init) {
|
|
65
|
+
Object.assign(this, init)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public clone(): SockaddrUnix {
|
|
70
|
+
return new SockaddrUnix({ Name: this.Name })
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class Iovec {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './testing.js'
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { B, F, Short, T, type TB } from './testing.js'
|
|
4
|
+
import { runTests } from './testing.js'
|
|
5
|
+
|
|
6
|
+
describe('testing.T', () => {
|
|
7
|
+
it('runs passing subtests', async () => {
|
|
8
|
+
const t = new T('root')
|
|
9
|
+
|
|
10
|
+
const ok = await t.Run('child', (child) => {
|
|
11
|
+
expect(child.Name()).toBe('root/child')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
expect(ok).toBe(true)
|
|
15
|
+
expect(t.Failed()).toBe(false)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('runs async subtests before returning', async () => {
|
|
19
|
+
const t = new T('root')
|
|
20
|
+
let completed = false
|
|
21
|
+
|
|
22
|
+
const ok = await t.Run('child', async (child) => {
|
|
23
|
+
await Promise.resolve()
|
|
24
|
+
expect(child.Name()).toBe('root/child')
|
|
25
|
+
completed = true
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
expect(ok).toBe(true)
|
|
29
|
+
expect(completed).toBe(true)
|
|
30
|
+
expect(t.Failed()).toBe(false)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('propagates failed subtests', async () => {
|
|
34
|
+
const t = new T('root')
|
|
35
|
+
|
|
36
|
+
const ok = await t.Run('child', (child) => {
|
|
37
|
+
child.Error('failed')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
expect(ok).toBe(false)
|
|
41
|
+
expect(t.Failed()).toBe(true)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('exports the benchmark and fuzz test surfaces used by compiled tests', async () => {
|
|
45
|
+
const b = new B('bench')
|
|
46
|
+
b.N = 2
|
|
47
|
+
b.ReportAllocs()
|
|
48
|
+
b.ResetTimer()
|
|
49
|
+
b.SetBytes(12)
|
|
50
|
+
b.ReportMetric(3, 'items')
|
|
51
|
+
|
|
52
|
+
let ran = false
|
|
53
|
+
const ok = await b.Run('child', (child) => {
|
|
54
|
+
ran = true
|
|
55
|
+
expect(child.Name()).toBe('bench/child')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const f = new F('fuzz')
|
|
59
|
+
f.Add('seed')
|
|
60
|
+
f.Fuzz(() => {})
|
|
61
|
+
|
|
62
|
+
const tb: TB = b
|
|
63
|
+
tb.Helper()
|
|
64
|
+
|
|
65
|
+
expect(ok).toBe(true)
|
|
66
|
+
expect(ran).toBe(true)
|
|
67
|
+
expect(Short()).toBe(false)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('reports short mode while a short run is active', async () => {
|
|
71
|
+
let observed = false
|
|
72
|
+
|
|
73
|
+
const result = await runTests(
|
|
74
|
+
'example.test/short',
|
|
75
|
+
[
|
|
76
|
+
{
|
|
77
|
+
name: 'TestShort',
|
|
78
|
+
fn: () => {
|
|
79
|
+
observed = Short()
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
{ short: true },
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
expect(result.ok).toBe(true)
|
|
87
|
+
expect(observed).toBe(true)
|
|
88
|
+
expect(Short()).toBe(false)
|
|
89
|
+
})
|
|
90
|
+
})
|