Skip the bullshit
// docs / Ecosystem

JavaScript interop

Every web language eventually becomes a JavaScript wrapper. We got there in Milestone 16.

vcwl
extern fn shout(text: String) -> String // implemented in JavaScript
extern fn wait_for(ms: Int) -> Bool // returns a Promise
on click {
loud = shout("hi")
fetch wait_for(500) {
Ok(b) => {
done = b
}
Err(e) => {
error = e.message()
}
}
}
js
// src/interop.js, named in vcwl.toml: js = "src/interop.js"
export default {
shout: (text) => text.toUpperCase() + "!",
wait_for: (ms) => new Promise((r) => setTimeout(() => r(true), ms)),
};

@web: the browser's APIs, already wrapped

import "@web" gives about 75 functions: URL and history, popups and postMessage (OAuth, PKCE), storage and cookies (checked against the storage capability), Intl dates and numbers, Web Crypto, the clipboard, notifications, geolocation, share, fullscreen...

vcwl
import "@web"
on click {
let verifier = random_token(32)
fetch sha256_base64url(verifier) {
Ok(challenge) => {
redirect(with_params("https://auth.example.com/authorize", [
Param { name: "code_challenge", value: challenge },
Param { name: "code_challenge_method", value: "S256" },
]))
}
Err(e) => {
error = e.message()
}
}
}