mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 20:25:12 -05:00
examples(core): panik (#15983)
This commit is contained in:
parent
707e9e3580
commit
388e880dd0
1 changed files with 35 additions and 0 deletions
35
core/examples/panik.rs
Normal file
35
core/examples/panik.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||||
|
//! This example shows that op-panics currently result in UB (likely "failed to initiate panic")
|
||||||
|
//! without a custom panic hook that aborts the process or -C panic=abort.
|
||||||
|
//!
|
||||||
|
//! This happens due to the UB of panicking in an extern "C",
|
||||||
|
//! given how ops are reduced via rusty_v8::MapFnTo
|
||||||
|
//! See:
|
||||||
|
//! - https://github.com/rust-lang/rust/issues/74990
|
||||||
|
//! - https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html
|
||||||
|
|
||||||
|
use deno_core::op;
|
||||||
|
use deno_core::Extension;
|
||||||
|
use deno_core::JsRuntime;
|
||||||
|
use deno_core::RuntimeOptions;
|
||||||
|
|
||||||
|
// This is a hack to make the `#[op]` macro work with
|
||||||
|
// deno_core examples.
|
||||||
|
// You can remove this:
|
||||||
|
use deno_core::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
#[op]
|
||||||
|
fn op_panik() {
|
||||||
|
panic!("panik !!!")
|
||||||
|
}
|
||||||
|
|
||||||
|
let extensions =
|
||||||
|
vec![Extension::builder().ops(vec![op_panik::decl()]).build()];
|
||||||
|
let mut rt = JsRuntime::new(RuntimeOptions {
|
||||||
|
extensions,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
rt.execute_script("panik", "Deno.core.ops.op_panik()")
|
||||||
|
.unwrap();
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue