-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(napi): fix is_detached_arraybuffer (#16478)
- Loading branch information
Showing
5 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
|
||
import { assertEquals, loadTestLibrary } from "./common.js"; | ||
|
||
const typedarray = loadTestLibrary(); | ||
|
||
Deno.test("napi arraybuffer detach", function () { | ||
const buf = new ArrayBuffer(5); | ||
assertEquals(buf.byteLength, 5); | ||
typedarray.test_detached(buf); | ||
assertEquals(buf.byteLength, 0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
|
||
use napi_sys::Status::napi_ok; | ||
use napi_sys::*; | ||
use std::ptr; | ||
|
||
extern "C" fn test_detached( | ||
env: napi_env, | ||
info: napi_callback_info, | ||
) -> napi_value { | ||
let (args, argc, _) = crate::get_callback_info!(env, info, 1); | ||
assert_eq!(argc, 1); | ||
|
||
let mut value = false; | ||
assert!( | ||
unsafe { napi_is_detached_arraybuffer(env, args[0], &mut value) } | ||
== napi_ok | ||
); | ||
assert!(!value); | ||
assert!(unsafe { napi_detach_arraybuffer(env, args[0]) } == napi_ok); | ||
assert!( | ||
unsafe { napi_is_detached_arraybuffer(env, args[0], &mut value) } | ||
== napi_ok | ||
); | ||
assert!(value); | ||
args[0] | ||
} | ||
|
||
pub fn init(env: napi_env, exports: napi_value) { | ||
let properties = | ||
&[crate::new_property!(env, "test_detached\0", test_detached)]; | ||
|
||
unsafe { | ||
napi_define_properties(env, exports, properties.len(), properties.as_ptr()) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters