fix(napi): return node globalThis from napi_get_global (#17613)

Fixes https://github.com/denoland/deno/issues/17587
This commit is contained in:
Divy Srivastava 2023-02-01 06:41:04 -08:00 committed by GitHub
parent 1b46b2f0e4
commit 524bccdf6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 6 deletions

View file

@ -1718,12 +1718,12 @@ fn napi_get_element(
#[napi_sym::napi_sym]
fn napi_get_global(env: *mut Env, result: *mut napi_value) -> Result {
check_env!(env);
let env = unsafe { &mut *env };
check_arg!(env, result);
let context = &mut env.scope().get_current_context();
let global = context.global(&mut env.scope());
let value: v8::Local<v8::Value> = global.into();
let value: v8::Local<v8::Value> =
transmute::<NonNull<v8::Value>, v8::Local<v8::Value>>((*env).global);
*result = value.into();
napi_clear_last_error(env);
Ok(())
}