0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-02-02 04:37:35 -05:00

Rename new_null() to null() and new_undefined() to undefined() (#216)

This is more consistent with V8's C++ API.
This commit is contained in:
Bert Belder 2020-01-17 08:34:48 +01:00
parent d4cd5d2733
commit fb19eecc31
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
2 changed files with 6 additions and 9 deletions

View file

@ -6,20 +6,17 @@ use crate::ToLocal;
extern "C" { extern "C" {
fn v8__Null(isolate: *mut Isolate) -> *mut Primitive; fn v8__Null(isolate: *mut Isolate) -> *mut Primitive;
fn v8__Undefined(isolate: *mut Isolate) -> *mut Primitive; fn v8__Undefined(isolate: *mut Isolate) -> *mut Primitive;
fn v8__Boolean__New(isolate: *mut Isolate, value: bool) -> *mut Boolean; fn v8__Boolean__New(isolate: *mut Isolate, value: bool) -> *mut Boolean;
} }
pub fn new_null<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Primitive> { pub fn null<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Primitive> {
let ptr = unsafe { v8__Null(scope.isolate()) }; let ptr = unsafe { v8__Null(scope.isolate()) };
unsafe { scope.to_local(ptr) }.unwrap() unsafe { scope.to_local(ptr) }.unwrap()
} }
pub fn new_undefined<'sc>( pub fn undefined<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Primitive> {
scope: &mut impl ToLocal<'sc>,
) -> Local<'sc, Primitive> {
let ptr = unsafe { v8__Undefined(scope.isolate()) }; let ptr = unsafe { v8__Undefined(scope.isolate()) };
unsafe { scope.to_local(ptr) }.unwrap() unsafe { scope.to_local(ptr) }.unwrap()
} }

View file

@ -763,12 +763,12 @@ fn test_primitives() {
{ {
let mut hs = v8::HandleScope::new(&mut locker); let mut hs = v8::HandleScope::new(&mut locker);
let scope = hs.enter(); let scope = hs.enter();
let null = v8::new_null(scope); let null = v8::null(scope);
assert!(!null.is_undefined()); assert!(!null.is_undefined());
assert!(null.is_null()); assert!(null.is_null());
assert!(null.is_null_or_undefined()); assert!(null.is_null_or_undefined());
let undefined = v8::new_undefined(scope); let undefined = v8::undefined(scope);
assert!(undefined.is_undefined()); assert!(undefined.is_undefined());
assert!(!undefined.is_null()); assert!(!undefined.is_null());
assert!(undefined.is_null_or_undefined()); assert!(undefined.is_null_or_undefined());
@ -894,7 +894,7 @@ fn object() {
let scope = hs.enter(); let scope = hs.enter();
let mut context = v8::Context::new(scope); let mut context = v8::Context::new(scope);
context.enter(); context.enter();
let null: v8::Local<v8::Value> = v8::new_null(scope).into(); let null: v8::Local<v8::Value> = v8::null(scope).into();
let s1 = v8::String::new(scope, "a").unwrap(); let s1 = v8::String::new(scope, "a").unwrap();
let s2 = v8::String::new(scope, "b").unwrap(); let s2 = v8::String::new(scope, "b").unwrap();
let name1 = s1.into(); let name1 = s1.into();
@ -2034,7 +2034,7 @@ fn try_from_local() {
context.enter(); context.enter();
{ {
let value: v8::Local<v8::Value> = v8::new_undefined(scope).into(); let value: v8::Local<v8::Value> = v8::undefined(scope).into();
let _primitive = v8::Local::<v8::Primitive>::try_from(value).unwrap(); let _primitive = v8::Local::<v8::Primitive>::try_from(value).unwrap();
assert_eq!( assert_eq!(
v8::Local::<v8::Object>::try_from(value) v8::Local::<v8::Object>::try_from(value)