Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 40b1614

Browse files
authoredNov 22, 2021
Bump to v0.11.0, update CHANGELOG.md & Example (#143)
I had to remove SwiftWasm 5.3 and 5.4 from CI because OpenCombine/OpenCombine#225 is reproducible with all code, not just OpenCombine, with old toolchains when Xcode 13.1 is installed. I've also updated `Example` code to try using `fetch` with `async`/`await` and a section with a simple guide for this to `README.md` Node.js and npm dependencies together with webpack.js config in `Example` directory were also updated. * Bump to v0.11.0, update `CHANGELOG.md` & `Example` * Add simple `async`/`await` guide to `README.md` * Use `wasm-5.5-SNAPSHOT-2021-11-20-a` * Update `CHANGELOG.md` * Update `.swift-version` * Add acknowledgements to `CHANGELOG.md`
1 parent 9e2f414 commit 40b1614

File tree

11 files changed

+3282
-8191
lines changed

11 files changed

+3282
-8191
lines changed
 

‎.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
wasm-5.3.0-RELEASE
1+
wasm-5.5-SNAPSHOT-2021-11-20-a

‎CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
# 0.11.0 (22 November 2021)
2+
3+
This release adds support for `async`/`await` and SwiftWasm 5.5. Use the new `value` async property
4+
on a `JSPromise` instance to `await` for its result. You'll have to add a dependency on the new
5+
`JavaScriptEventLoop` target in your `Package.swift`, `import JavaScriptEventLoop`, and call
6+
`JavaScriptEventLoop.installGlobalExecutor()` in your code before you start using `await` and `Task`
7+
APIs.
8+
9+
Additionally, manual memory management API of `JSClosure` has been removed to improve usability.
10+
This significantly bumps minimum browser version requirements for users of apps depending on
11+
JavaScriptKit. Previous manual memory management mode is still available though with a special
12+
compiler flags, see [`README.md`](./README.md) for more details.
13+
14+
This new release of JavaScriptKit may work with SwiftWasm 5.4 and 5.3, but is no longer tested with
15+
those versions due to compatibility issues introduced on macOS by latest versions of Xcode.
16+
17+
Many thanks to [@j-f1](https://github.com/j-f1), [@kateinoigakukun](https://github.com/kateinoigakukun),
18+
and [@PatrickPijnappel](https://github.com/PatrickPijnappel) for their contributions to this release!
19+
20+
**Closed issues:**
21+
22+
- Enchancement: Add a link to the docs ([#136](https://github.com/swiftwasm/JavaScriptKit/issues/136))
23+
- Use `FinalizationRegistry` to auto-deinit `JSClosure` ([#131](https://github.com/swiftwasm/JavaScriptKit/issues/131))
24+
- `make test` crashes due to `JSClosure` memory issues ([#129](https://github.com/swiftwasm/JavaScriptKit/issues/129))
25+
- Avoid manual memory management with `JSClosure` ([#106](https://github.com/swiftwasm/JavaScriptKit/issues/106))
26+
27+
**Merged pull requests:**
28+
29+
- Fix recursion in `JSTypedArray` initializer ([#142](https://github.com/swiftwasm/JavaScriptKit/pull/142)) via [@PatrickPijnappel](https://github.com/PatrickPijnappel)
30+
- Experimental global executor cooperating with JS event loop ([#141](https://github.com/swiftwasm/JavaScriptKit/pull/141)) via [@kateinoigakukun](https://github.com/kateinoigakukun)
31+
- Update NPM dependencies of `Example` project ([#140](https://github.com/swiftwasm/JavaScriptKit/pull/140)) via [@MaxDesiatov](https://github.com/MaxDesiatov)
32+
- Refactor `JSClosure` to leverage `FinalizationRegistry` ([#128](https://github.com/swiftwasm/JavaScriptKit/pull/128)) via [@j-f1](https://github.com/j-f1)
33+
- Test with the latest 5.5 snapshot ([#138](https://github.com/swiftwasm/JavaScriptKit/pull/138)) via [@MaxDesiatov](https://github.com/MaxDesiatov)
34+
- Test with multiple toolchain versions ([#135](https://github.com/swiftwasm/JavaScriptKit/pull/135)) via [@kateinoigakukun](https://github.com/kateinoigakukun)
35+
- Gardening tests ([#133](https://github.com/swiftwasm/JavaScriptKit/pull/133)) via [@kateinoigakukun](https://github.com/kateinoigakukun)
36+
137
# 0.10.1 (29 April 2021)
238

339
This is a minor patch release that includes updates to our dependencies and minor documentation

‎Example/JavaScriptKitExample/Package.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,13 @@ let package = Package(
1010
),
1111
],
1212
dependencies: [.package(name: "JavaScriptKit", path: "../../")],
13-
targets: [.target(name: "JavaScriptKitExample", dependencies: ["JavaScriptKit"])]
13+
targets: [
14+
.target(
15+
name: "JavaScriptKitExample",
16+
dependencies: [
17+
"JavaScriptKit",
18+
.product(name: "JavaScriptEventLoop", package: "JavaScriptKit")
19+
]
20+
)
21+
]
1422
)
Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import JavaScriptKit
2+
import JavaScriptEventLoop
23

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

1011
var buttonElement = document.createElement("button")
11-
buttonElement.innerText = "Click me!"
12-
let listener = JSClosure { _ in
12+
buttonElement.innerText = "Alert demo"
13+
buttonElement.onclick = .object(JSClosure { _ in
1314
alert("Swift is running on browser!")
14-
}
15-
buttonElement.onclick = .object(listener)
15+
return .undefined
16+
})
1617

1718
_ = document.body.appendChild(buttonElement)
19+
20+
private let jsFetch = JSObject.global.fetch.function!
21+
func fetch(_ url: String) -> JSPromise {
22+
JSPromise(jsFetch(url).object!)!
23+
}
24+
25+
JavaScriptEventLoop.installGlobalExecutor()
26+
27+
struct Response: Decodable {
28+
let uuid: String
29+
}
30+
31+
var asyncButtonElement = document.createElement("button")
32+
asyncButtonElement.innerText = "Fetch UUID demo"
33+
asyncButtonElement.onclick = .object(JSClosure { _ in
34+
Task {
35+
do {
36+
let response = try await fetch("https://httpbin.org/uuid").value
37+
let json = try await JSPromise(response.json().object!)!.value
38+
let parsedResponse = try JSValueDecoder().decode(Response.self, from: json)
39+
alert(parsedResponse.uuid)
40+
} catch {
41+
print(error)
42+
}
43+
}
44+
45+
return .undefined
46+
})
47+
48+
_ = document.body.appendChild(asyncButtonElement)

‎Example/package-lock.json

Lines changed: 3076 additions & 8153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Example/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"javascript-kit-swift": "file:.."
1010
},
1111
"devDependencies": {
12-
"webpack": "^4.44.2",
13-
"webpack-cli": "^3.3.12",
14-
"webpack-dev-server": "^3.11.0"
12+
"webpack": "^5.64.2",
13+
"webpack-cli": "^4.9.1",
14+
"webpack-dev-server": "^4.5.0"
1515
},
1616
"scripts": {
1717
"build": "webpack",

‎Example/webpack.config.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ module.exports = {
99
path: outputPath,
1010
},
1111
devServer: {
12-
inline: true,
13-
watchContentBase: true,
14-
contentBase: [
15-
path.join(__dirname, "public"),
16-
path.join(__dirname, "dist"),
12+
static: [
13+
{
14+
directory: path.join(__dirname, "public"),
15+
watch: true,
16+
},
17+
{
18+
directory: path.join(__dirname, "dist"),
19+
watch: true,
20+
},
1721
],
1822
},
1923
};

‎IntegrationTests/package-lock.json

Lines changed: 41 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,69 @@ let swiftPet: Pet = try JSValueDecoder().decode(from: jsPet)
5353
JSObject.global.alert!("Swift is running in the browser!")
5454
```
5555

56-
### Usage in a browser application
56+
### `async`/`await`
57+
58+
Starting with SwiftWasm 5.5 you can use `async`/`await` with `JSPromise` objects. This requires
59+
a few additional steps though (you can skip these steps if your app depends on
60+
[Tokamak](https://tokamak.dev)):
61+
62+
1. Make sure that your target depends on `JavaScriptEventLoop` in your `Packages.swift`:
63+
64+
```swift
65+
.target(
66+
name: "JavaScriptKitExample",
67+
dependencies: [
68+
"JavaScriptKit",
69+
.product(name: "JavaScriptEventLoop", package: "JavaScriptKit")
70+
]
71+
)
72+
```
73+
74+
2. Add an explicit import in the code that executes **before* you start using `await` and/or `Task`
75+
APIs (most likely in `main.swift`):
76+
77+
```swift
78+
import JavaScriptEventLoop
79+
```
80+
81+
3. Run this function **before* you start using `await` and/or `Task` APIs (again, most likely in
82+
`main.swift`):
83+
84+
```swift
85+
JavaScriptEventLoop.installGlobalExecutor()
86+
```
87+
88+
## Requirements
89+
90+
### For developers
91+
92+
- macOS 11 and Xcode 13.0. *Xcode 13.1 is currently not supported.*
93+
- [Swift 5.4 or later](https://swift.org/download/) and Ubuntu 18.04 if you'd like to use Linux.
94+
Other Linux distributions are currently not supported.
95+
96+
### For users of apps depending
97+
98+
Any recent browser that [supports WebAssembly](https://caniuse.com/#feat=wasm) and required
99+
JavaScript features should work, which currently includes:
100+
101+
- Edge 84+
102+
- Firefox 79+
103+
- Chrome 84+
104+
- Desktop Safari 14.1+
105+
- Mobile Safari 14.8+
106+
107+
If you need to support older browser versions, you'll have to build with
108+
`JAVASCRIPTKIT_WITHOUT_WEAKREFS` flag, passing `-Xswiftc -DJAVASCRIPTKIT_WITHOUT_WEAKREFS` flags
109+
when compiling. This should lower browser requirements to these versions:
110+
111+
- Edge 16+
112+
- Firefox 61+
113+
- Chrome 66+
114+
- (Mobile) Safari 12+
115+
116+
Not all of these versions are tested on regular basis though, compatibility reports are very welcome!
117+
118+
## Usage in a browser application
57119

58120
The easiest way to get started with JavaScriptKit in your browser app is with [the `carton`
59121
bundler](https://carton.dev).
@@ -104,7 +166,7 @@ You can also build your project with webpack.js and a manually installed SwiftWa
104166
see the following sections and the [Example](https://github.com/swiftwasm/JavaScriptKit/tree/main/Example)
105167
directory for more information in this more advanced use case.
106168

107-
### Manual toolchain installation
169+
## Manual toolchain installation
108170

109171
This library only supports [`swiftwasm/swift`](https://github.com/swiftwasm/swift) toolchain distribution.
110172
The toolchain can be installed via [`swiftenv`](https://github.com/kylef/swiftenv), in
@@ -115,18 +177,18 @@ especially if you change anything in the JavaScript runtime parts. This is becau
115177
embedded in `carton` and currently can't be replaced dynamically with the JavaScript code you've
116178
updated locally.
117179

118-
Just pass a toolchain archive URL for [the latest SwiftWasm 5.3
119-
snapshot](https://github.com/swiftwasm/swift/releases) appropriate for your platform:
180+
Just pass a toolchain archive URL for [the latest SwiftWasm 5.5
181+
release](https://github.com/swiftwasm/swift/releases) appropriate for your platform:
120182

121183
```sh
122-
$ swiftenv install https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.3.0-RELEASE/swift-wasm-5.3.0-RELEASE-macos_x86_64.pkg
184+
$ swiftenv install https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.5.0-RELEASE/swift-wasm-5.5.0-RELEASE-macos_x86_64.pkg
123185
```
124186

125187
You can also use the `install-toolchain.sh` helper script that uses a hardcoded toolchain snapshot:
126188

127189
```sh
128190
$ ./scripts/install-toolchain.sh
129191
$ swift --version
130-
Swift version 5.3 (swiftlang-5.3.0)
131-
Target: x86_64-apple-darwin19.6.0
192+
Swift version 5.5 (swiftlang-5.5.0)
193+
Target: arm64-apple-darwin20.6.0
132194
```

‎package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "javascript-kit-swift",
3-
"version": "0.10.1",
3+
"version": "0.11.0",
44
"description": "A runtime library of JavaScriptKit which is Swift framework to interact with JavaScript through WebAssembly.",
55
"main": "Runtime/lib/index.js",
66
"files": [

0 commit comments

Comments
 (0)
Please sign in to comment.