diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-08-15 13:29:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-15 13:29:19 +0200 |
commit | 2ca454b402d48c1808f8233c5adedc11b714c63c (patch) | |
tree | 592f9e877e9b0ae92be80383ab723cc290e4b01e /ext/webgpu/buffer.rs | |
parent | 18ff6bb053d600c277613628a256fe5fdd4dda67 (diff) |
refactor(ops): return BadResource errors in ResourceTable calls (#11710)
* refactor(ops): return BadResource errors in ResourceTable calls
Instead of relying on callers to map Options to Results via `.ok_or_else(bad_resource_id)` at over 176 different call sites ...
Diffstat (limited to 'ext/webgpu/buffer.rs')
-rw-r--r-- | ext/webgpu/buffer.rs | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/ext/webgpu/buffer.rs b/ext/webgpu/buffer.rs index 6980b6348..e42c77598 100644 --- a/ext/webgpu/buffer.rs +++ b/ext/webgpu/buffer.rs @@ -1,6 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -use deno_core::error::bad_resource_id; use deno_core::error::null_opbuf; use deno_core::error::type_error; use deno_core::error::AnyError; @@ -50,8 +49,7 @@ pub fn op_webgpu_create_buffer( let instance = state.borrow::<super::Instance>(); let device_resource = state .resource_table - .get::<super::WebGpuDevice>(args.device_rid) - .ok_or_else(bad_resource_id)?; + .get::<super::WebGpuDevice>(args.device_rid)?; let device = device_resource.0; let descriptor = wgpu_core::resource::BufferDescriptor { @@ -90,15 +88,12 @@ pub async fn op_webgpu_buffer_get_map_async( { let state_ = state.borrow(); let instance = state_.borrow::<super::Instance>(); - let buffer_resource = state_ - .resource_table - .get::<WebGpuBuffer>(args.buffer_rid) - .ok_or_else(bad_resource_id)?; + let buffer_resource = + state_.resource_table.get::<WebGpuBuffer>(args.buffer_rid)?; let buffer = buffer_resource.0; let device_resource = state_ .resource_table - .get::<super::WebGpuDevice>(args.device_rid) - .ok_or_else(bad_resource_id)?; + .get::<super::WebGpuDevice>(args.device_rid)?; device = device_resource.0; let boxed_sender = Box::new(sender); @@ -180,10 +175,8 @@ pub fn op_webgpu_buffer_get_mapped_range( ) -> Result<WebGpuResult, AnyError> { let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?; let instance = state.borrow::<super::Instance>(); - let buffer_resource = state - .resource_table - .get::<WebGpuBuffer>(args.buffer_rid) - .ok_or_else(bad_resource_id)?; + let buffer_resource = + state.resource_table.get::<WebGpuBuffer>(args.buffer_rid)?; let buffer = buffer_resource.0; let (slice_pointer, range_size) = @@ -220,13 +213,10 @@ pub fn op_webgpu_buffer_unmap( ) -> Result<WebGpuResult, AnyError> { let mapped_resource = state .resource_table - .take::<WebGpuBufferMapped>(args.mapped_rid) - .ok_or_else(bad_resource_id)?; + .take::<WebGpuBufferMapped>(args.mapped_rid)?; let instance = state.borrow::<super::Instance>(); - let buffer_resource = state - .resource_table - .get::<WebGpuBuffer>(args.buffer_rid) - .ok_or_else(bad_resource_id)?; + let buffer_resource = + state.resource_table.get::<WebGpuBuffer>(args.buffer_rid)?; let buffer = buffer_resource.0; let slice_pointer = mapped_resource.0; |