diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-07-22 17:54:22 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-22 17:54:22 +0530 |
commit | 03dc3b8972f460e40d0b75fc3207cae9fe4f60da (patch) | |
tree | 410bc92530e34ca2eee8a154f705be85ae9641b3 /core/runtime.rs | |
parent | 244c00d95b7ec8f30a5e81b743b4b618049b6c37 (diff) |
feat(ops): V8 Fast Calls (#15122)
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'core/runtime.rs')
-rw-r--r-- | core/runtime.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/core/runtime.rs b/core/runtime.rs index 64e7f635c..caadd0089 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -230,6 +230,7 @@ fn v8_init( " --harmony-import-assertions", " --no-validate-asm", " --turbo_fast_api_calls", + " --allow-natives-syntax", ); if predictable { @@ -242,6 +243,9 @@ fn v8_init( } } +pub const V8_WRAPPER_TYPE_INDEX: i32 = 0; +pub const V8_WRAPPER_OBJECT_INDEX: i32 = 1; + #[derive(Default)] pub struct RuntimeOptions { /// Source map reference for errors. @@ -317,7 +321,6 @@ impl JsRuntime { if let Some(get_error_class_fn) = options.get_error_class_fn { op_state.get_error_class_fn = get_error_class_fn; } - let op_state = Rc::new(RefCell::new(op_state)); let op_ctxs = ops .into_iter() @@ -330,12 +333,13 @@ impl JsRuntime { .collect::<Vec<_>>() .into_boxed_slice(); + let refs = bindings::external_references(&op_ctxs); + let refs: &'static v8::ExternalReferences = Box::leak(Box::new(refs)); let global_context; let (mut isolate, maybe_snapshot_creator) = if options.will_snapshot { // TODO(ry) Support loading snapshots before snapshotting. assert!(options.startup_snapshot.is_none()); - let mut creator = - v8::SnapshotCreator::new(Some(&bindings::EXTERNAL_REFERENCES)); + let mut creator = v8::SnapshotCreator::new(Some(refs)); // SAFETY: `get_owned_isolate` is unsafe because it may only be called // once. This is the only place we call this function, so this call is // safe. @@ -352,8 +356,13 @@ impl JsRuntime { let mut params = options .create_params .take() - .unwrap_or_else(v8::Isolate::create_params) - .external_references(&**bindings::EXTERNAL_REFERENCES); + .unwrap_or_else(|| { + v8::Isolate::create_params().embedder_wrapper_type_info_offsets( + V8_WRAPPER_TYPE_INDEX, + V8_WRAPPER_OBJECT_INDEX, + ) + }) + .external_references(&**refs); let snapshot_loaded = if let Some(snapshot) = options.startup_snapshot { params = match snapshot { Snapshot::Static(data) => params.snapshot_blob(data), |