0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

fix(ext/websocket): don't panic on bad resource id (#21431)

https://github.com/denoland/deno/issues/21379
This commit is contained in:
Divy Srivastava 2023-12-11 12:22:54 +05:30 committed by GitHub
parent 5e24e28318
commit 0bee37a5e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -719,9 +719,9 @@ pub async fn op_ws_close(
pub fn op_ws_get_buffer( pub fn op_ws_get_buffer(
state: &mut OpState, state: &mut OpState,
#[smi] rid: ResourceId, #[smi] rid: ResourceId,
) -> ToJsBuffer { ) -> Result<ToJsBuffer, AnyError> {
let resource = state.resource_table.get::<ServerWebSocket>(rid).unwrap(); let resource = state.resource_table.get::<ServerWebSocket>(rid)?;
resource.buffer.take().unwrap().into() Ok(resource.buffer.take().unwrap().into())
} }
#[op2] #[op2]
@ -729,9 +729,9 @@ pub fn op_ws_get_buffer(
pub fn op_ws_get_buffer_as_string( pub fn op_ws_get_buffer_as_string(
state: &mut OpState, state: &mut OpState,
#[smi] rid: ResourceId, #[smi] rid: ResourceId,
) -> String { ) -> Result<String, AnyError> {
let resource = state.resource_table.get::<ServerWebSocket>(rid).unwrap(); let resource = state.resource_table.get::<ServerWebSocket>(rid)?;
resource.string.take().unwrap() Ok(resource.string.take().unwrap())
} }
#[op2] #[op2]