mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
90c0381272
In Rust, it is UB if a slice is mutated while borrowed except through the slice itself, and it is also UB if a mutable slice is read while borrowed. The op macro allows borrowing an `ArrayBuffer{,View}` as a memory slice for the duration of an op, but this is not sound for async ops, since the `ArrayBuffer` could be accessed from JS during the await points. This PR therefore disallows such automatic borrowing only for async ops. Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
24 lines
446 B
Rust
24 lines
446 B
Rust
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
use deno_ops::op;
|
|
|
|
#[op]
|
|
fn sync_test(slice: &mut [u32]) {
|
|
//
|
|
}
|
|
|
|
#[op]
|
|
async fn async_test(slice: &[u8]) {
|
|
// Memory slices are not allowed in async ops.
|
|
}
|
|
|
|
#[op]
|
|
fn async_test2(slice: &mut [u8]) -> impl Future<Output = ()> {
|
|
// Memory slices are not allowed in async ops, even when not implemented as an
|
|
// async function.
|
|
async {}
|
|
}
|
|
|
|
fn main() {
|
|
// pass
|
|
}
|