summaryrefslogtreecommitdiff
path: root/core/bindings.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-04-30 16:51:54 +0200
committerGitHub <noreply@github.com>2021-04-30 10:51:54 -0400
commitfc9c7de94b08049dd04c4ca6016586cdac0dd2ac (patch)
tree939b1dab406e7ea9e077fed6832806016d879065 /core/bindings.rs
parent5ec478b5fa6261e2b2d3c8daed3cba9e780730c7 (diff)
cleanup(core): replace OpResponse with OpResult (#10434)
Drop the Value/Buffer enum since #10432 allows buffers to be serialized rust => v8
Diffstat (limited to 'core/bindings.rs')
-rw-r--r--core/bindings.rs42
1 files changed, 8 insertions, 34 deletions
diff --git a/core/bindings.rs b/core/bindings.rs
index 4574e2d4e..e1c1a7a43 100644
--- a/core/bindings.rs
+++ b/core/bindings.rs
@@ -5,7 +5,6 @@ use crate::JsRuntime;
use crate::Op;
use crate::OpId;
use crate::OpPayload;
-use crate::OpResponse;
use crate::OpTable;
use crate::PromiseId;
use crate::ZeroCopyBuf;
@@ -154,19 +153,6 @@ pub fn set_func(
obj.set(scope, key.into(), val.into());
}
-pub fn boxed_slice_to_uint8array<'sc>(
- scope: &mut v8::HandleScope<'sc>,
- buf: Box<[u8]>,
-) -> v8::Local<'sc, v8::Uint8Array> {
- assert!(!buf.is_empty());
- let buf_len = buf.len();
- let backing_store = v8::ArrayBuffer::new_backing_store_from_boxed_slice(buf);
- let backing_store_shared = backing_store.make_shared();
- let ab = v8::ArrayBuffer::with_backing_store(scope, &backing_store_shared);
- v8::Uint8Array::new(scope, ab, 0, buf_len)
- .expect("Failed to create UintArray8")
-}
-
pub extern "C" fn host_import_module_dynamically_callback(
context: v8::Local<v8::Context>,
referrer: v8::Local<v8::ScriptOrModule>,
@@ -368,32 +354,20 @@ fn opcall<'s>(
// Buf arg (optional)
let arg3 = args.get(3);
- let buf: Option<ZeroCopyBuf> = if arg3.is_null_or_undefined() {
- None
- } else {
- match v8::Local::<v8::ArrayBufferView>::try_from(arg3)
- .map(|view| ZeroCopyBuf::new(scope, view))
- .map_err(AnyError::from)
- {
- Ok(buf) => Some(buf),
- Err(err) => {
- throw_type_error(scope, format!("Err with buf arg: {}", err));
- return;
- }
+ let buf: Option<ZeroCopyBuf> = match serde_v8::from_v8(scope, arg3) {
+ Ok(buf) => buf,
+ Err(err) => {
+ throw_type_error(scope, format!("Err with buf arg: {}", err));
+ return;
}
};
let payload = OpPayload::new(scope, v, promise_id);
let op = OpTable::route_op(op_id, state.op_state.clone(), payload, buf);
match op {
- Op::Sync(resp) => match resp {
- OpResponse::Value(v) => {
- rv.set(v.to_v8(scope).unwrap());
- }
- OpResponse::Buffer(buf) => {
- rv.set(boxed_slice_to_uint8array(scope, buf).into());
- }
- },
+ Op::Sync(result) => {
+ rv.set(result.to_v8(scope).unwrap());
+ }
Op::Async(fut) => {
state.pending_ops.push(fut);
state.have_unpolled_ops = true;