From 2aed322dd507a8568b6ee6f4897e9a8e3220f763 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Mon, 5 Apr 2021 18:40:24 +0200 Subject: refactor: convert ops to use serde_v8 (#10009) This commit rewrites most of the ops to use "serde_v8" instead of "json" serialization. --- op_crates/webgpu/buffer.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'op_crates/webgpu/buffer.rs') diff --git a/op_crates/webgpu/buffer.rs b/op_crates/webgpu/buffer.rs index ade4122d5..19fc428cb 100644 --- a/op_crates/webgpu/buffer.rs +++ b/op_crates/webgpu/buffer.rs @@ -4,8 +4,6 @@ use deno_core::error::bad_resource_id; use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::futures::channel::oneshot; -use deno_core::serde_json::json; -use deno_core::serde_json::Value; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; @@ -17,7 +15,7 @@ use std::rc::Rc; use std::time::Duration; use super::error::DomExceptionOperationError; -use super::error::WebGpuError; +use super::error::WebGpuResult; pub(crate) struct WebGpuBuffer(pub(crate) wgpu_core::id::BufferId); impl Resource for WebGpuBuffer { @@ -47,7 +45,7 @@ pub fn op_webgpu_create_buffer( state: &mut OpState, args: CreateBufferArgs, _zero_copy: Option, -) -> Result { +) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table @@ -70,10 +68,7 @@ pub fn op_webgpu_create_buffer( let rid = state.resource_table.add(WebGpuBuffer(buffer)); - Ok(json!({ - "rid": rid, - "err": maybe_err.map(WebGpuError::from) - })) + Ok(WebGpuResult::rid_err(rid, maybe_err)) } #[derive(Deserialize)] @@ -90,7 +85,7 @@ pub async fn op_webgpu_buffer_get_map_async( state: Rc>, args: BufferGetMapAsyncArgs, _bufs: Option, -) -> Result { +) -> Result { let (sender, receiver) = oneshot::channel::>(); let device; @@ -164,7 +159,7 @@ pub async fn op_webgpu_buffer_get_map_async( tokio::try_join!(device_poll_fut, receiver_fut)?; - Ok(json!({})) + Ok(WebGpuResult::empty()) } #[derive(Deserialize)] @@ -179,7 +174,7 @@ pub fn op_webgpu_buffer_get_mapped_range( state: &mut OpState, args: BufferGetMappedRangeArgs, zero_copy: Option, -) -> Result { +) -> Result { let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?; let instance = state.borrow::(); let buffer_resource = state @@ -204,9 +199,7 @@ pub fn op_webgpu_buffer_get_mapped_range( .resource_table .add(WebGpuBufferMapped(slice_pointer, args.size as usize)); - Ok(json!({ - "rid": rid, - })) + Ok(WebGpuResult::rid(rid)) } #[derive(Deserialize)] @@ -220,7 +213,7 @@ pub fn op_webgpu_buffer_unmap( state: &mut OpState, args: BufferUnmapArgs, zero_copy: Option, -) -> Result { +) -> Result { let mapped_resource = state .resource_table .take::(args.mapped_rid) @@ -242,5 +235,5 @@ pub fn op_webgpu_buffer_unmap( let maybe_err = gfx_select!(buffer => instance.buffer_unmap(buffer)).err(); - Ok(json!({ "err": maybe_err.map(WebGpuError::from) })) + Ok(WebGpuResult::maybe_err(maybe_err)) } -- cgit v1.2.3