mirror of
https://github.com/lexmount/moli.git
synced 2026-10-31 00:06:19 +00:00
34 lines
1.3 KiB
Rust
34 lines
1.3 KiB
Rust
use moli_webidl::Context;
|
|
|
|
#[test]
|
|
fn buffer_source_row_writes_preserve_padding_and_reject_out_of_bounds() {
|
|
moli_v8_test_util::ensure_v8();
|
|
let mut isolate = v8::Isolate::new(v8::CreateParams::default());
|
|
v8::scope!(let scope, &mut isolate);
|
|
let context = v8::Context::new(scope, Default::default());
|
|
let scope = &mut v8::ContextScope::new(scope, context);
|
|
for source in [
|
|
"new DataView(new ArrayBuffer(8),2,4)",
|
|
"new DataView(new SharedArrayBuffer(8),2,4)",
|
|
] {
|
|
let source = v8::String::new(scope, source).unwrap();
|
|
let value = v8::Script::compile(scope, source, None)
|
|
.unwrap()
|
|
.run(scope)
|
|
.unwrap();
|
|
let buffer = moli_webidl::convert::<moli_webidl::AllowSharedBufferSource>(
|
|
scope,
|
|
value,
|
|
Context::argument("Test", 1),
|
|
)
|
|
.unwrap();
|
|
assert!(buffer.write_bytes(scope, &[7, 7, 7, 7]));
|
|
assert!(buffer.write_bytes_at(scope, 1, &[1, 2]));
|
|
assert_eq!(buffer.to_vec(scope), vec![7, 1, 2, 7]);
|
|
assert!(!buffer.write_bytes_at(scope, 3, &[1, 2]));
|
|
assert!(!buffer.write_bytes_at(scope, usize::MAX, &[1]));
|
|
assert!(buffer.write_bytes_at(scope, 4, &[]));
|
|
assert_eq!(buffer.to_vec(scope), vec![7, 1, 2, 7]);
|
|
}
|
|
}
|