Skip to content

Fix recursion in TypedArray initializer #142

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Merged
merged 5 commits into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ 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
- wasm-5.5-SNAPSHOT-2021-11-20-a
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
}


Expand Down
4 changes: 4 additions & 0 deletions IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, 256)

try checkArray([0, .max, 127, 1] as [UInt8])
try checkArray([0, 1, .max, .min, -1] as [Int8])

Expand Down
2 changes: 1 addition & 1 deletion Runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral wh
}
self.init(unsafelyWrapping: JSObject(id: resultObj))
}

/// Convenience initializer for `Sequence`.
public convenience init<S: Sequence>(_ sequence: S) {
self.init(sequence.map({ $0 }))
public convenience init<S: Sequence>(_ sequence: S) where S.Element == Element {
self.init(Array(sequence))
}
}

Expand Down