From 8ca430249d1b0682a8b0cd7243d2d7adc271e1d3 Mon Sep 17 00:00:00 2001 From: Patrick Pijnappel Date: Tue, 9 Nov 2021 15:34:32 +1100 Subject: [PATCH 1/5] Fix recursion in TypedArray initializer --- Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift b/Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift index a3d43aff6..e1dac0cef 100644 --- a/Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift +++ b/Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift @@ -52,8 +52,8 @@ public class JSTypedArray: JSBridgedClass, ExpressibleByArrayLiteral wh } /// Convenience initializer for `Sequence`. - public convenience init(_ sequence: S) { - self.init(sequence.map({ $0 })) + public convenience init(_ sequence: S) where S.Element == Element { + self.init(Array(sequence)) } } From 9187c481d75d4270dae00191082f8a57c83879b2 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Sun, 21 Nov 2021 22:33:13 +0100 Subject: [PATCH 2/5] Update tests, fix formatting --- .../TestSuites/Sources/ConcurrencyTests/main.swift | 8 ++++---- .../TestSuites/Sources/PrimaryTests/main.swift | 4 ++++ Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/IntegrationTests/TestSuites/Sources/ConcurrencyTests/main.swift b/IntegrationTests/TestSuites/Sources/ConcurrencyTests/main.swift index 9d8483117..5447032fe 100644 --- a/IntegrationTests/TestSuites/Sources/ConcurrencyTests/main.swift +++ b/IntegrationTests/TestSuites/Sources/ConcurrencyTests/main.swift @@ -60,7 +60,7 @@ func entrypoint() async throws { try await asyncTest("Task.sleep(_:)") { let start = time(nil) - await Task.sleep(2_000_000_000) + try await Task.sleep(nanoseconds: 2_000_000_000) let diff = difftime(time(nil), start); try expectEqual(diff >= 2, true) } @@ -100,9 +100,9 @@ func entrypoint() async throws { // FIXME(katei): Somehow it doesn't work due to a mysterious unreachable inst // at the end of thunk. // This issue is not only on JS host environment, but also on standalone coop executor. - // try await asyncTest("Task.sleep(nanoseconds:)") { - // try await Task.sleep(nanoseconds: 1_000_000_000) - // } + try await asyncTest("Task.sleep(nanoseconds:)") { + try await Task.sleep(nanoseconds: 1_000_000_000) + } } diff --git a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift index 6c054a791..614322342 100644 --- a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift +++ b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift @@ -441,6 +441,10 @@ try test("TypedArray") { let typedArray = JSTypedArray(numbers) try expectEqual(typedArray[12], 12) + let numbersSet = Set(0 ... 255) + let typedArrayFromSet = JSTypedArray(numbersSet) + try expectEqual(typedArrayFromSet.jsObject.length, 12) + try checkArray([0, .max, 127, 1] as [UInt8]) try checkArray([0, 1, .max, .min, -1] as [Int8]) diff --git a/Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift b/Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift index e1dac0cef..347d74992 100644 --- a/Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift +++ b/Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift @@ -50,7 +50,7 @@ public class JSTypedArray: JSBridgedClass, ExpressibleByArrayLiteral wh } self.init(unsafelyWrapping: JSObject(id: resultObj)) } - + /// Convenience initializer for `Sequence`. public convenience init(_ sequence: S) where S.Element == Element { self.init(Array(sequence)) From 51f844153a31e1ea6d76af1cf8af9c66c3aa8e15 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Sun, 21 Nov 2021 22:37:37 +0100 Subject: [PATCH 3/5] Fix tests --- IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift | 2 +- Runtime/src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift index 614322342..153797949 100644 --- a/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift +++ b/IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift @@ -443,7 +443,7 @@ try test("TypedArray") { let numbersSet = Set(0 ... 255) let typedArrayFromSet = JSTypedArray(numbersSet) - try expectEqual(typedArrayFromSet.jsObject.length, 12) + try expectEqual(typedArrayFromSet.jsObject.length, 256) try checkArray([0, .max, 127, 1] as [UInt8]) try checkArray([0, 1, .max, .min, -1] as [Int8]) diff --git a/Runtime/src/index.ts b/Runtime/src/index.ts index a48e8fa72..6fc139443 100644 --- a/Runtime/src/index.ts +++ b/Runtime/src/index.ts @@ -154,7 +154,7 @@ export class SwiftRuntime { const exports = (this.instance .exports as any) as SwiftRuntimeExportedFunctions; if (exports.swjs_library_version() != this.version) { - throw new Error("The versions of JavaScriptKit are incompatible."); + throw new Error(`The versions of JavaScriptKit are incompatible. ${exports.swjs_library_version()} != ${this.version}`); } } get closureHeap(): SwiftClosureHeap | null { From cd5a483084d0f4d94fb4133221a8664db46809e0 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Sun, 21 Nov 2021 22:42:10 +0100 Subject: [PATCH 4/5] Remove SwiftWasm 5.3.1 from GitHub Actions matrix --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5e72d38a9..282ac57db 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,6 @@ jobs: matrix: os: [macos-10.15, macos-11, ubuntu-18.04, ubuntu-20.04] toolchain: - - wasm-5.3.1-RELEASE - wasm-5.4.0-RELEASE - wasm-5.5-SNAPSHOT-2021-10-02-a runs-on: ${{ matrix.os }} From 1ab9ea554973b87b1c20a91c812600a0a7afc5d1 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Sun, 21 Nov 2021 22:47:55 +0100 Subject: [PATCH 5/5] Use latest 5.5 snapshot on CI --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 282ac57db..8bdab9311 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,8 +10,7 @@ jobs: matrix: os: [macos-10.15, macos-11, ubuntu-18.04, ubuntu-20.04] toolchain: - - wasm-5.4.0-RELEASE - - wasm-5.5-SNAPSHOT-2021-10-02-a + - wasm-5.5-SNAPSHOT-2021-11-20-a runs-on: ${{ matrix.os }} steps: - name: Checkout