summaryrefslogtreecommitdiff
path: root/core/bindings.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2022-03-15 22:50:17 +0100
committerGitHub <noreply@github.com>2022-03-15 22:50:17 +0100
commit07d8431f100e8df5f523adf542b47f8b91af3539 (patch)
tree97241da33c3f0e9f45617bdbd0a81d64c49b8e51 /core/bindings.rs
parent163e1d61920fbc6a0bdb18adc57b249b2d600472 (diff)
fix(core): nuke Deno.core.ops pre-snapshot (#13970)
To avoid OOB & other ExternalReference snapshot serialization issues Co-authored-by: Bert Belder <bertbelder@gmail.com>
Diffstat (limited to 'core/bindings.rs')
-rw-r--r--core/bindings.rs152
1 files changed, 71 insertions, 81 deletions
diff --git a/core/bindings.rs b/core/bindings.rs
index 2ab55187d..0a87c0ffa 100644
--- a/core/bindings.rs
+++ b/core/bindings.rs
@@ -14,6 +14,7 @@ use crate::PromiseId;
use crate::ZeroCopyBuf;
use anyhow::Error;
use log::debug;
+use once_cell::sync::Lazy;
use serde::Deserialize;
use serde::Serialize;
use serde_v8::to_v8;
@@ -29,88 +30,77 @@ use v8::SharedArrayBuffer;
use v8::ValueDeserializerHelper;
use v8::ValueSerializerHelper;
-pub fn external_references(
- ops: &[OpPair],
- op_state: Rc<RefCell<OpState>>,
-) -> v8::ExternalReferences {
- let mut refs = vec![
- v8::ExternalReference {
- function: ref_op.map_fn_to(),
- },
- v8::ExternalReference {
- function: unref_op.map_fn_to(),
- },
- v8::ExternalReference {
- function: set_macrotask_callback.map_fn_to(),
- },
- v8::ExternalReference {
- function: set_nexttick_callback.map_fn_to(),
- },
- v8::ExternalReference {
- function: set_promise_reject_callback.map_fn_to(),
- },
- v8::ExternalReference {
- function: set_uncaught_exception_callback.map_fn_to(),
- },
- v8::ExternalReference {
- function: run_microtasks.map_fn_to(),
- },
- v8::ExternalReference {
- function: has_tick_scheduled.map_fn_to(),
- },
- v8::ExternalReference {
- function: set_has_tick_scheduled.map_fn_to(),
- },
- v8::ExternalReference {
- function: eval_context.map_fn_to(),
- },
- v8::ExternalReference {
- function: queue_microtask.map_fn_to(),
- },
- v8::ExternalReference {
- function: create_host_object.map_fn_to(),
- },
- v8::ExternalReference {
- function: encode.map_fn_to(),
- },
- v8::ExternalReference {
- function: decode.map_fn_to(),
- },
- v8::ExternalReference {
- function: serialize.map_fn_to(),
- },
- v8::ExternalReference {
- function: deserialize.map_fn_to(),
- },
- v8::ExternalReference {
- function: get_promise_details.map_fn_to(),
- },
- v8::ExternalReference {
- function: get_proxy_details.map_fn_to(),
- },
- v8::ExternalReference {
- function: is_proxy.map_fn_to(),
- },
- v8::ExternalReference {
- function: memory_usage.map_fn_to(),
- },
- v8::ExternalReference {
- function: call_console.map_fn_to(),
- },
- v8::ExternalReference {
- function: set_wasm_streaming_callback.map_fn_to(),
- },
- ];
- let op_refs = ops
- .iter()
- .map(|(_, opref)| v8::ExternalReference { function: *opref });
- refs.extend(op_refs);
- let raw_op_state = Rc::as_ptr(&op_state) as *mut c_void;
- refs.push(v8::ExternalReference {
- pointer: raw_op_state,
+pub static EXTERNAL_REFERENCES: Lazy<v8::ExternalReferences> =
+ Lazy::new(|| {
+ v8::ExternalReferences::new(&[
+ v8::ExternalReference {
+ function: ref_op.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: unref_op.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: set_macrotask_callback.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: set_nexttick_callback.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: set_promise_reject_callback.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: set_uncaught_exception_callback.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: run_microtasks.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: has_tick_scheduled.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: set_has_tick_scheduled.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: eval_context.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: queue_microtask.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: create_host_object.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: encode.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: decode.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: serialize.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: deserialize.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: get_promise_details.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: get_proxy_details.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: is_proxy.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: memory_usage.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: call_console.map_fn_to(),
+ },
+ v8::ExternalReference {
+ function: set_wasm_streaming_callback.map_fn_to(),
+ },
+ ])
});
- v8::ExternalReferences::new(&refs)
-}
pub fn script_origin<'a>(
s: &mut v8::HandleScope<'a>,