forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(napi): return node globalThis from napi_get_global (denoland#17613)
Fixes denoland#17587
- Loading branch information
1 parent
1b46b2f
commit 524bccd
Showing
7 changed files
with
68 additions
and
6 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
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-2023 the Deno authors. All rights reserved. MIT license. | ||
|
||
import { assert, loadTestLibrary } from "./common.js"; | ||
|
||
const env = loadTestLibrary(); | ||
|
||
Deno.test("napi get global", function () { | ||
const g = env.testNodeGlobal(); | ||
// Note: global is a mock object in the tests. | ||
// See common.js | ||
assert(g.Buffer); | ||
}); |
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,39 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
|
||
use crate::assert_napi_ok; | ||
use crate::napi_get_callback_info; | ||
use crate::napi_new_property; | ||
use napi_sys::*; | ||
|
||
extern "C" fn get_node_global( | ||
env: napi_env, | ||
info: napi_callback_info, | ||
) -> napi_value { | ||
let (_, argc, _) = napi_get_callback_info!(env, info, 0); | ||
assert_eq!(argc, 0); | ||
|
||
let mut result: napi_value = std::ptr::null_mut(); | ||
assert_napi_ok!(napi_get_global(env, &mut result)); | ||
|
||
let mut r1: napi_value = std::ptr::null_mut(); | ||
assert_napi_ok!(napi_get_named_property( | ||
env, | ||
result, | ||
"Buffer\0".as_ptr() as _, | ||
&mut r1 | ||
)); | ||
|
||
result | ||
} | ||
|
||
pub fn init(env: napi_env, exports: napi_value) { | ||
let properties = | ||
&[napi_new_property!(env, "testNodeGlobal", get_node_global)]; | ||
|
||
assert_napi_ok!(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