Skip to content

Commit 9e2f414

Browse files
Fix recursion in JSTypedArray initializer (swiftwasm#142)
The original unconstrained version would cause infinite recursion. * Fix recursion in TypedArray initializer * Update tests, fix formatting * Fix tests * Remove SwiftWasm 5.3.1 from GitHub Actions matrix * Use latest 5.5 snapshot on CI Co-authored-by: Max Desiatov <max@desiatov.com>
1 parent b9a2573 commit 9e2f414

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

.github/workflows/test.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ jobs:
1010
matrix:
1111
os: [macos-10.15, macos-11, ubuntu-18.04, ubuntu-20.04]
1212
toolchain:
13-
- wasm-5.3.1-RELEASE
14-
- wasm-5.4.0-RELEASE
15-
- wasm-5.5-SNAPSHOT-2021-10-02-a
13+
- wasm-5.5-SNAPSHOT-2021-11-20-a
1614
runs-on: ${{ matrix.os }}
1715
steps:
1816
- name: Checkout

IntegrationTests/TestSuites/Sources/ConcurrencyTests/main.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func entrypoint() async throws {
6060

6161
try await asyncTest("Task.sleep(_:)") {
6262
let start = time(nil)
63-
await Task.sleep(2_000_000_000)
63+
try await Task.sleep(nanoseconds: 2_000_000_000)
6464
let diff = difftime(time(nil), start);
6565
try expectEqual(diff >= 2, true)
6666
}
@@ -100,9 +100,9 @@ func entrypoint() async throws {
100100
// FIXME(katei): Somehow it doesn't work due to a mysterious unreachable inst
101101
// at the end of thunk.
102102
// This issue is not only on JS host environment, but also on standalone coop executor.
103-
// try await asyncTest("Task.sleep(nanoseconds:)") {
104-
// try await Task.sleep(nanoseconds: 1_000_000_000)
105-
// }
103+
try await asyncTest("Task.sleep(nanoseconds:)") {
104+
try await Task.sleep(nanoseconds: 1_000_000_000)
105+
}
106106
}
107107

108108

IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift

+4
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ try test("TypedArray") {
441441
let typedArray = JSTypedArray(numbers)
442442
try expectEqual(typedArray[12], 12)
443443

444+
let numbersSet = Set(0 ... 255)
445+
let typedArrayFromSet = JSTypedArray(numbersSet)
446+
try expectEqual(typedArrayFromSet.jsObject.length, 256)
447+
444448
try checkArray([0, .max, 127, 1] as [UInt8])
445449
try checkArray([0, 1, .max, .min, -1] as [Int8])
446450

Runtime/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class SwiftRuntime {
154154
const exports = (this.instance
155155
.exports as any) as SwiftRuntimeExportedFunctions;
156156
if (exports.swjs_library_version() != this.version) {
157-
throw new Error("The versions of JavaScriptKit are incompatible.");
157+
throw new Error(`The versions of JavaScriptKit are incompatible. ${exports.swjs_library_version()} != ${this.version}`);
158158
}
159159
}
160160
get closureHeap(): SwiftClosureHeap | null {

Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral wh
5050
}
5151
self.init(unsafelyWrapping: JSObject(id: resultObj))
5252
}
53-
53+
5454
/// Convenience initializer for `Sequence`.
55-
public convenience init<S: Sequence>(_ sequence: S) {
56-
self.init(sequence.map({ $0 }))
55+
public convenience init<S: Sequence>(_ sequence: S) where S.Element == Element {
56+
self.init(Array(sequence))
5757
}
5858
}
5959

0 commit comments

Comments
 (0)