Skip to content

Commit

Permalink
Add panic hook to wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Jun 24, 2024
1 parent 7443ba2 commit d98562b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
17 changes: 9 additions & 8 deletions playground/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
miette = {version = "7.2", features = ["fancy-no-syscall"]}
semver = {version = "1.0", features = ["serde"]}
veryl-analyzer = {git = "https://github.com/veryl-lang/veryl"}
veryl-emitter = {git = "https://github.com/veryl-lang/veryl"}
veryl-formatter = {git = "https://github.com/veryl-lang/veryl"}
veryl-metadata = {git = "https://github.com/veryl-lang/veryl"}
veryl-parser = {git = "https://github.com/veryl-lang/veryl"}
wasm-bindgen = "0.2"
console_error_panic_hook = "0.1.7"
miette = {version = "7.2", features = ["fancy-no-syscall"]}
semver = {version = "1.0", features = ["serde"]}
veryl-analyzer = {git = "https://github.com/veryl-lang/veryl"}
veryl-emitter = {git = "https://github.com/veryl-lang/veryl"}
veryl-formatter = {git = "https://github.com/veryl-lang/veryl"}
veryl-metadata = {git = "https://github.com/veryl-lang/veryl"}
veryl-parser = {git = "https://github.com/veryl-lang/veryl"}
wasm-bindgen = "0.2"

[workspace]

Expand Down
19 changes: 10 additions & 9 deletions playground/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ <h2>Output</h2>
</div>
</div>
<script type="module">
import init, {build, format} from "./pkg/veryl_wasm.js";
import init, {set_hook, build, format} from "./pkg/veryl_wasm.js";
init()
.then(() => {
set_hook();
});

window.build = () => {
//try {
try {
const src = document.getElementById('source').value;
const result = build(src);
const content = result.content();
Expand All @@ -106,13 +107,13 @@ <h2>Output</h2>
document.getElementById("output").textContent = content;
hljs.highlightAll();
}
//} catch (error) {
// document.getElementById("output").textContent = "Unexpected error";
//}
} catch (error) {
document.getElementById("output").textContent = "Unexpected error";
}
}

window.format = () => {
//try {
try {
const src = document.getElementById('source').value;
const result = format(src);
const content = result.content();
Expand All @@ -122,9 +123,9 @@ <h2>Output</h2>
} else {
document.getElementById("source").value = content;
}
//} catch (error) {
// document.getElementById("output").textContent = "Unexpected error";
//}
} catch (error) {
document.getElementById("output").textContent = "Unexpected error";
}
}

window.changeExample = async (name) => {
Expand Down
5 changes: 5 additions & 0 deletions playground/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ fn metadata() -> Metadata {
}
}

#[wasm_bindgen]
pub fn set_hook() {
console_error_panic_hook::set_once();
}

#[wasm_bindgen]
pub fn build(source: &str) -> Result {
let metadata = metadata();
Expand Down

0 comments on commit d98562b

Please sign in to comment.