0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-27 01:29:19 -05:00
denoland-rusty-v8/tests/test_single_threaded_default_platform.rs
Ben Noordhuis 03e74c6f1b
Add new_single_threaded_default_platform() (#659)
This is a v8::Platform implementation that doesn't spawn additional
threads. Useful in combination with the --single_threaded flag.
2021-04-12 21:40:52 +02:00

24 lines
757 B
Rust

use rusty_v8 as v8;
#[test]
fn single_threaded_default_platform() {
v8::V8::set_flags_from_string("--single_threaded");
v8::V8::initialize_platform(
v8::new_single_threaded_default_platform().unwrap(),
);
v8::V8::initialize();
{
let isolate = &mut v8::Isolate::new(Default::default());
let scope = &mut v8::HandleScope::new(isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);
let source = v8::String::new(scope, "Math.random()").unwrap();
let script = v8::Script::compile(scope, source, None).unwrap();
let result = script.run(scope).unwrap();
let _ = result.to_string(scope).unwrap();
}
unsafe { v8::V8::dispose() };
v8::V8::shutdown_platform();
}