summaryrefslogtreecommitdiff
path: root/ops/tests/compile_fail/mem_slices.rs
diff options
context:
space:
mode:
authorAndreu Botella <andreu@andreubotella.com>2023-01-14 23:40:01 -0800
committerGitHub <noreply@github.com>2023-01-15 07:40:01 +0000
commit90c03812720c328dcb68939400b265128b6eca8f (patch)
treea1e5ce445e3c9d6eac7be43f1909cb354fe1e69d /ops/tests/compile_fail/mem_slices.rs
parent44d9acca75b5a0aa886bf370cd4658bfb6e7097e (diff)
fix(ops): disallow memory slices as inputs to async ops (#16738)
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>
Diffstat (limited to 'ops/tests/compile_fail/mem_slices.rs')
-rw-r--r--ops/tests/compile_fail/mem_slices.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/ops/tests/compile_fail/mem_slices.rs b/ops/tests/compile_fail/mem_slices.rs
new file mode 100644
index 000000000..da74ac577
--- /dev/null
+++ b/ops/tests/compile_fail/mem_slices.rs
@@ -0,0 +1,24 @@
+// 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
+}