diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-10-20 00:00:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-20 00:00:45 +0200 |
commit | 4f48efcc55b9e6cc0dd212ebd8e729909efed1ab (patch) | |
tree | 78f06eff5e21bddc9c6be0a3fc809d2b4a5932cb /serde_v8/src/utils.rs | |
parent | ad20e52c27a88b8481b2d8e169bde4a9b4952cb6 (diff) |
chore: return serde_v8 to main repo (#12500)
Reduces fragmentation, avoids version drift and facilitates coordinating serde_v8 and op-layer changes
Diffstat (limited to 'serde_v8/src/utils.rs')
-rw-r--r-- | serde_v8/src/utils.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/serde_v8/src/utils.rs b/serde_v8/src/utils.rs new file mode 100644 index 000000000..6f638f7b3 --- /dev/null +++ b/serde_v8/src/utils.rs @@ -0,0 +1,34 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +use rusty_v8 as v8; +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() { + unsafe { + v8::V8::dispose(); + } + v8::V8::shutdown_platform(); +} + +pub fn v8_do(f: impl FnOnce()) { + static V8_INIT: Once = Once::new(); + V8_INIT.call_once(|| { + v8_init(); + }); + f(); + // v8_shutdown(); +} |