js-sandbox 0.1.6

Execute JavaScript code from Rust in a secure sandbox, and transport data to/from JS plug-ins.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Copyright (c) 2020-2021 Jan Haller. zlib/libpng license.

use deno_core::error::JsError;

use js_sandbox::AnyError;

pub fn expect_error<T>(result: Result<T, AnyError>, error_type: &str) {
	let err = match result {
		Ok(_) => panic!("Call with {} must not succeed", error_type),
		Err(e) => e,
	};

	let err = err.downcast_ref::<JsError>()
		.expect(&format!("{} must lead to JsError type", error_type));

	println!("Expected error occurred:\n{}", err.message);
}