1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-30 16:40:57 -05:00
denoland-deno/core/examples/panik.rs
Matt Mastracci a1764f7690
refactor(core): Improve ergonomics of managing ASCII strings (#18498)
This is a follow-on to the earlier work in reducing string copies,
mainly focused on ensuring that ASCII strings are easy to provide to the
JS runtime.

While we are replacing a 16-byte reference in a number of places with a
24-byte structure (measured via `std::mem::size_of`), the reduction in
copies wins out over the additional size of the arguments passed into
functions.

Benchmarking shows approximately the same if not slightly less wallclock
time/instructions retired, but I believe this continues to open up
further refactoring opportunities.
2023-04-04 06:46:31 -06:00

36 lines
1 KiB
Rust

// Copyright 2018-2023 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("my_ext")
.ops(vec![op_panik::decl()])
.build()];
let mut rt = JsRuntime::new(RuntimeOptions {
extensions,
..Default::default()
});
rt.execute_script_static("panik", "Deno.core.ops.op_panik()")
.unwrap();
}