GeezerVison is showing github.com — Support latest nightly snapshot (#246) · aehlke/JavaScriptKit@74c35de
File treeExpand file treeCollapse file tree Open diff view settings TestSuites/Sources/PrimaryTests
_CJavaScriptEventLoop/include
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/test.yml +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,12 +18,10 @@ jobs: | 18 | 18 | # Ensure that test succeeds with all toolchains and wasi backend combinations | 19 | 19 | - { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: Node } | 20 | 20 | - { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node } | 21 | | - - { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: Wasmer } | 22 | | - - { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Wasmer } | 23 | | - - { os: ubuntu-20.04, toolchain: wasm-5.9.1-RELEASE, wasi-backend: Wasmer } | 24 | 21 | - { os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: MicroWASI } | 25 | 22 | - { os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: MicroWASI } | 26 | 23 | - { os: ubuntu-20.04, toolchain: wasm-5.9.1-RELEASE, wasi-backend: MicroWASI } | | 24 | + - { os: ubuntu-22.04, toolchain: wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a, wasi-backend: Node } | 27 | 25 |
| 28 | 26 | runs-on: ${{ matrix.entry.os }} | 29 | 27 | env: | |
Collapse file Copy file name to clipboardExpand all lines: IntegrationTests/Makefile +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,8 @@ TestSuites/.build/$(CONFIGURATION)/%.wasm: FORCE | 11 | 11 | --triple wasm32-unknown-wasi \ | 12 | 12 | --configuration $(CONFIGURATION) \ | 13 | 13 | -Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor \ | 14 | | - -Xlinker --export=main \ | | 14 | + -Xlinker --export-if-defined=main -Xlinker --export-if-defined=__main_argc_argv \ | | 15 | + --static-swift-stdlib -Xswiftc -static-stdlib \ | 15 | 16 | $(SWIFT_BUILD_FLAGS) | 16 | 17 |
| 17 | 18 | dist/%.wasm: TestSuites/.build/$(CONFIGURATION)/%.wasm | |
Collapse file Copy file name to clipboardExpand all lines: IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -400,7 +400,7 @@ try test("Call Function With This") { | 400 | 400 | let setName = try expectFunction(getJSValue(this: cat1, name: "setName")) | 401 | 401 |
| 402 | 402 | // Direct call without this | 403 | | - try expectEqual(getIsCat(), .undefined) | | 403 | + _ = try expectThrow(try getIsCat.throws()) | 404 | 404 |
| 405 | 405 | // Call with this | 406 | 406 | let gotIsCat = getIsCat(this: cat1) | |
Collapse file Copy file name to clipboardExpand all lines: IntegrationTests/bin/benchmark-tests.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -const { startWasiTask } = require("../lib"); | 2 | | -const { performance } = require("perf_hooks"); | | 1 | +import { startWasiTask } from "../lib.js"; | | 2 | +import { performance } from "perf_hooks"; | 3 | 3 |
| 4 | 4 | const SAMPLE_ITERATION = 1000000 | 5 | 5 |
| |
Collapse file Copy file name to clipboardExpand all lines: IntegrationTests/bin/concurrency-tests.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -const { startWasiTask } = require("../lib"); | | 1 | +import { startWasiTask } from "../lib.js"; | 2 | 2 |
| 3 | 3 | Error.stackTraceLimit = Infinity; | 4 | 4 |
| |
Collapse file Copy file name to clipboardExpand all lines: IntegrationTests/bin/primary-tests.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -102,7 +102,7 @@ global.objectDecodingTest = { | 102 | 102 | bi: BigInt(3) | 103 | 103 | }; | 104 | 104 |
| 105 | | -const { startWasiTask, WASI } = require("../lib"); | | 105 | +import { startWasiTask } from "../lib.js"; | 106 | 106 |
| 107 | 107 | startWasiTask("./dist/PrimaryTests.wasm").catch((err) => { | 108 | 108 | console.log(err); | |
Collapse file Copy file name to clipboard +14-53Lines changed: 14 additions & 53 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -const SwiftRuntime = require("javascript-kit-swift").SwiftRuntime; | 2 | | -const WasmerWASI = require("@wasmer/wasi").WASI; | 3 | | -const WasmFs = require("@wasmer/wasmfs").WasmFs; | 4 | | -const NodeWASI = require("wasi").WASI; | 5 | | -const { WASI: MicroWASI, useAll } = require("uwasi"); | 6 | | - | 7 | | -const promisify = require("util").promisify; | 8 | | -const fs = require("fs"); | 9 | | -const readFile = promisify(fs.readFile); | | 1 | +import { SwiftRuntime } from "javascript-kit-swift" | | 2 | +import { WASI as NodeWASI } from "wasi" | | 3 | +import { WASI as MicroWASI, useAll } from "uwasi" | | 4 | +import * as fs from "fs/promises" | 10 | 5 |
| 11 | 6 | const WASI = { | 12 | | - Wasmer: ({ programName }) => { | 13 | | - // Instantiate a new WASI Instance | 14 | | - const wasmFs = new WasmFs(); | 15 | | - // Output stdout and stderr to console | 16 | | - const originalWriteSync = wasmFs.fs.writeSync; | 17 | | - wasmFs.fs.writeSync = (fd, buffer, offset, length, position) => { | 18 | | - const text = new TextDecoder("utf-8").decode(buffer); | 19 | | - switch (fd) { | 20 | | - case 1: | 21 | | - console.log(text); | 22 | | - break; | 23 | | - case 2: | 24 | | - console.error(text); | 25 | | - break; | 26 | | - } | 27 | | - return originalWriteSync(fd, buffer, offset, length, position); | 28 | | - }; | 29 | | - const wasi = new WasmerWASI({ | 30 | | - args: [programName], | 31 | | - env: {}, | 32 | | - bindings: { | 33 | | - ...WasmerWASI.defaultBindings, | 34 | | - fs: wasmFs.fs, | 35 | | - }, | 36 | | - }); | 37 | | - | 38 | | - return { | 39 | | - wasiImport: wasi.wasiImport, | 40 | | - start(instance) { | 41 | | - wasi.start(instance); | 42 | | - instance.exports._initialize(); | 43 | | - instance.exports.main(); | 44 | | - } | 45 | | - } | 46 | | - }, | 47 | 7 | MicroWASI: ({ programName }) => { | 48 | 8 | const wasi = new MicroWASI({ | 49 | 9 | args: [programName], | @@ -53,25 +13,28 @@ const WASI = { | 53 | 13 |
| 54 | 14 | return { | 55 | 15 | wasiImport: wasi.wasiImport, | 56 | | - start(instance) { | | 16 | + start(instance, swift) { | 57 | 17 | wasi.initialize(instance); | 58 | | - instance.exports.main(); | | 18 | + swift.main(); | 59 | 19 | } | 60 | 20 | } | 61 | 21 | }, | 62 | 22 | Node: ({ programName }) => { | 63 | 23 | const wasi = new NodeWASI({ | 64 | 24 | args: [programName], | 65 | 25 | env: {}, | | 26 | + preopens: { | | 27 | + "/": "./", | | 28 | + }, | 66 | 29 | returnOnExit: false, | 67 | 30 | version: "preview1", | 68 | 31 | }) | 69 | 32 |
| 70 | 33 | return { | 71 | 34 | wasiImport: wasi.wasiImport, | 72 | | - start(instance) { | | 35 | + start(instance, swift) { | 73 | 36 | wasi.initialize(instance); | 74 | | - instance.exports.main(); | | 37 | + swift.main(); | 75 | 38 | } | 76 | 39 | } | 77 | 40 | }, | @@ -88,10 +51,10 @@ const selectWASIBackend = () => { | 88 | 51 | return WASI.Node; | 89 | 52 | }; | 90 | 53 |
| 91 | | -const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => { | | 54 | +export const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => { | 92 | 55 | const swift = new SwiftRuntime(); | 93 | 56 | // Fetch our Wasm File | 94 | | - const wasmBinary = await readFile(wasmPath); | | 57 | + const wasmBinary = await fs.readFile(wasmPath); | 95 | 58 | const wasi = wasiConstructor({ programName: wasmPath }); | 96 | 59 |
| 97 | 60 | // Instantiate the WebAssembly file | @@ -106,7 +69,5 @@ const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) => | 106 | 69 |
| 107 | 70 | swift.setInstance(instance); | 108 | 71 | // Start the WebAssembly WASI instance! | 109 | | - wasi.start(instance); | | 72 | + wasi.start(instance, swift); | 110 | 73 | }; | 111 | | - | 112 | | -module.exports = { startWasiTask, WASI }; |
|