Skip to content

Bump to v0.11.0, update CHANGELOG.md & Example #143

New issue

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

By clicking “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? Sign in to your account

Merged
merged 6 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wasm-5.3.0-RELEASE
wasm-5.5-SNAPSHOT-2021-11-20-a
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# 0.11.0 (22 November 2021)

This release adds support for `async`/`await` and SwiftWasm 5.5. Use the new `value` async property
on a `JSPromise` instance to `await` for its result. You'll have to add a dependency on the new
`JavaScriptEventLoop` target in your `Package.swift`, `import JavaScriptEventLoop`, and call
`JavaScriptEventLoop.installGlobalExecutor()` in your code before you start using `await` and `Task`
APIs.

Additionally, manual memory management API of `JSClosure` has been removed to improve usability.
This significantly bumps minimum browser version requirements for users of apps depending on
JavaScriptKit. Previous manual memory management mode is still available though with a special
compiler flags, see [`README.md`](./README.md) for more details.

This new release of JavaScriptKit may work with SwiftWasm 5.4 and 5.3, but is no longer tested with
those versions due to compatibility issues introduced on macOS by latest versions of Xcode.

**Closed issues:**

- Enchancement: Add a link to the docs ([#136](https://github.com/swiftwasm/JavaScriptKit/issues/136))
- Use FinalizationRegistry to auto-deinit `JSClosure` ([#131](https://github.com/swiftwasm/JavaScriptKit/issues/131))
- `make test` crashes due to `JSClosure` memory issues ([#129](https://github.com/swiftwasm/JavaScriptKit/issues/129))
- Avoid manual memory management with `JSClosure` ([#106](https://github.com/swiftwasm/JavaScriptKit/issues/106))

**Merged pull requests:**

- Fix recursion in `JSTypedArray` initializer ([#142](https://github.com/swiftwasm/JavaScriptKit/pull/142)) via [@PatrickPijnappel](https://github.com/PatrickPijnappel)
- Experimental global executor cooperating with JS event loop ([#141](https://github.com/swiftwasm/JavaScriptKit/pull/141)) via [@kateinoigakukun](https://github.com/kateinoigakukun)
- Update NPM dependencies of `Example` project ([#140](https://github.com/swiftwasm/JavaScriptKit/pull/140)) via [@MaxDesiatov](https://github.com/MaxDesiatov)
- Refactor `JSClosure` to leverage `FinalizationRegistry` ([#128](https://github.com/swiftwasm/JavaScriptKit/pull/128)) via [@j-f1](https://github.com/j-f1)
- Test with the latest 5.5 snapshot ([#138](https://github.com/swiftwasm/JavaScriptKit/pull/138)) via [@MaxDesiatov](https://github.com/MaxDesiatov)
- Test with multiple toolchain versions ([#135](https://github.com/swiftwasm/JavaScriptKit/pull/135)) via [@kateinoigakukun](https://github.com/kateinoigakukun)
- Gardening tests ([#133](https://github.com/swiftwasm/JavaScriptKit/pull/133)) via [@kateinoigakukun](https://github.com/kateinoigakukun)

# 0.10.1 (29 April 2021)

This is a minor patch release that includes updates to our dependencies and minor documentation
Expand Down
10 changes: 9 additions & 1 deletion Example/JavaScriptKitExample/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ let package = Package(
),
],
dependencies: [.package(name: "JavaScriptKit", path: "../../")],
targets: [.target(name: "JavaScriptKitExample", dependencies: ["JavaScriptKit"])]
targets: [
.target(
name: "JavaScriptKitExample",
dependencies: [
"JavaScriptKit",
.product(name: "JavaScriptEventLoop", package: "JavaScriptKit")
]
)
]
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import JavaScriptKit
import JavaScriptEventLoop

let alert = JSObject.global.alert.function!
let document = JSObject.global.document
Expand All @@ -8,10 +9,40 @@ divElement.innerText = "Hello, world"
_ = document.body.appendChild(divElement)

var buttonElement = document.createElement("button")
buttonElement.innerText = "Click me!"
let listener = JSClosure { _ in
buttonElement.innerText = "Alert demo"
buttonElement.onclick = .object(JSClosure { _ in
alert("Swift is running on browser!")
}
buttonElement.onclick = .object(listener)
return .undefined
})

_ = document.body.appendChild(buttonElement)

private let jsFetch = JSObject.global.fetch.function!
func fetch(_ url: String) -> JSPromise {
JSPromise(jsFetch(url).object!)!
}

JavaScriptEventLoop.installGlobalExecutor()

struct Response: Decodable {
let uuid: String
}

var asyncButtonElement = document.createElement("button")
asyncButtonElement.innerText = "Fetch UUID demo"
asyncButtonElement.onclick = .object(JSClosure { _ in
Task {
do {
let response = try await fetch("https://httpbin.org/uuid").value
let json = try await JSPromise(response.json().object!)!.value
let parsedResponse = try JSValueDecoder().decode(Response.self, from: json)
alert(parsedResponse.uuid)
} catch {
print(error)
}
}

return .undefined
})

_ = document.body.appendChild(asyncButtonElement)
Loading