mirror of
https://github.com/denoland/deno.git
synced 2024-10-31 09:14:20 -04:00
10e4b2e140
Yearly tradition of creating extra noise in git.
34 lines
815 B
Rust
34 lines
815 B
Rust
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
use std::sync::Once;
|
|
|
|
pub fn js_exec<'s>(
|
|
scope: &mut v8::HandleScope<'s>,
|
|
src: &str,
|
|
) -> v8::Local<'s, v8::Value> {
|
|
let code = v8::String::new(scope, src).unwrap();
|
|
let script = v8::Script::compile(scope, code, None).unwrap();
|
|
script.run(scope).unwrap()
|
|
}
|
|
|
|
pub fn v8_init() {
|
|
let platform = v8::new_default_platform(0, false).make_shared();
|
|
v8::V8::initialize_platform(platform);
|
|
v8::V8::initialize();
|
|
}
|
|
|
|
pub fn v8_shutdown() {
|
|
// SAFETY: this is safe, because all isolates have been shut down already.
|
|
unsafe {
|
|
v8::V8::dispose();
|
|
}
|
|
v8::V8::dispose_platform();
|
|
}
|
|
|
|
pub fn v8_do(f: impl FnOnce()) {
|
|
static V8_INIT: Once = Once::new();
|
|
V8_INIT.call_once(|| {
|
|
v8_init();
|
|
});
|
|
f();
|
|
// v8_shutdown();
|
|
}
|