0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-25 08:39:15 -05:00

Add v8::Boolean::new() (#184)

This commit is contained in:
Bartek Iwańczuk 2020-01-05 00:08:27 +01:00 committed by Bert Belder
parent bd598fe8dc
commit 2aaa62ae41
3 changed files with 27 additions and 31 deletions

View file

@ -528,12 +528,8 @@ v8::Primitive* v8__Undefined(v8::Isolate* isolate) {
return local_to_ptr(v8::Undefined(isolate)); return local_to_ptr(v8::Undefined(isolate));
} }
v8::Boolean* v8__True(v8::Isolate* isolate) { v8::Boolean* v8__Boolean__New(v8::Isolate* isolate, bool value) {
return local_to_ptr(v8::True(isolate)); return local_to_ptr(v8::Boolean::New(isolate, value));
}
v8::Boolean* v8__False(v8::Isolate* isolate) {
return local_to_ptr(v8::False(isolate));
} }
v8::PrimitiveArray* v8__PrimitiveArray__New(v8::Isolate* isolate, int length) { v8::PrimitiveArray* v8__PrimitiveArray__New(v8::Isolate* isolate, int length) {

View file

@ -9,9 +9,7 @@ extern "C" {
fn v8__Undefined(isolate: *mut Isolate) -> *mut Primitive; fn v8__Undefined(isolate: *mut Isolate) -> *mut Primitive;
fn v8__True(isolate: *mut Isolate) -> *mut Boolean; fn v8__Boolean__New(isolate: *mut Isolate, value: bool) -> *mut Boolean;
fn v8__False(isolate: *mut Isolate) -> *mut Boolean;
} }
pub fn new_null<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Primitive> { pub fn new_null<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Primitive> {
@ -26,12 +24,12 @@ pub fn new_undefined<'sc>(
unsafe { scope.to_local(ptr) }.unwrap() unsafe { scope.to_local(ptr) }.unwrap()
} }
pub fn new_true<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Boolean> { impl Boolean {
let ptr = unsafe { v8__True(scope.isolate()) }; pub fn new<'sc>(
unsafe { scope.to_local(ptr) }.unwrap() scope: &mut impl ToLocal<'sc>,
} value: bool,
) -> Local<'sc, Boolean> {
pub fn new_false<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Boolean> { let ptr = unsafe { v8__Boolean__New(scope.isolate(), value) };
let ptr = unsafe { v8__False(scope.isolate()) }; unsafe { scope.to_local(ptr) }.unwrap()
unsafe { scope.to_local(ptr) }.unwrap() }
} }

View file

@ -432,7 +432,7 @@ fn terminate_execution() {
let mut context = v8::Context::new(scope); let mut context = v8::Context::new(scope);
context.enter(); context.enter();
let result = eval(scope, context, "true").unwrap(); let result = eval(scope, context, "true").unwrap();
let true_val = v8::new_true(scope).into(); let true_val = v8::Boolean::new(scope, true).into();
assert!(result.same_value(true_val)); assert!(result.same_value(true_val));
context.exit(); context.exit();
} }
@ -460,7 +460,7 @@ fn terminate_execution() {
let mut context = v8::Context::new(scope); let mut context = v8::Context::new(scope);
context.enter(); context.enter();
let result = eval(scope, context, "true").unwrap(); let result = eval(scope, context, "true").unwrap();
let true_val = v8::new_true(scope).into(); let true_val = v8::Boolean::new(scope, true).into();
assert!(result.same_value(true_val)); assert!(result.same_value(true_val));
context.exit(); context.exit();
} }
@ -633,12 +633,12 @@ fn script_origin() {
let resource_name = v8::String::new(s, "foo.js").unwrap(); let resource_name = v8::String::new(s, "foo.js").unwrap();
let resource_line_offset = v8::Integer::new(s, 4); let resource_line_offset = v8::Integer::new(s, 4);
let resource_column_offset = v8::Integer::new(s, 5); let resource_column_offset = v8::Integer::new(s, 5);
let resource_is_shared_cross_origin = v8::new_true(s); let resource_is_shared_cross_origin = v8::Boolean::new(s, true);
let script_id = v8::Integer::new(s, 123); let script_id = v8::Integer::new(s, 123);
let source_map_url = v8::String::new(s, "source_map_url").unwrap(); let source_map_url = v8::String::new(s, "source_map_url").unwrap();
let resource_is_opaque = v8::new_true(s); let resource_is_opaque = v8::Boolean::new(s, true);
let is_wasm = v8::new_false(s); let is_wasm = v8::Boolean::new(s, false);
let is_module = v8::new_false(s); let is_module = v8::Boolean::new(s, false);
let script_origin = v8::ScriptOrigin::new( let script_origin = v8::ScriptOrigin::new(
resource_name.into(), resource_name.into(),
@ -728,12 +728,14 @@ fn test_primitives() {
assert!(!undefined.is_null()); assert!(!undefined.is_null());
assert!(undefined.is_null_or_undefined()); assert!(undefined.is_null_or_undefined());
let true_ = v8::new_true(scope); let true_ = v8::Boolean::new(scope, true);
assert!(true_.is_true());
assert!(!true_.is_undefined()); assert!(!true_.is_undefined());
assert!(!true_.is_null()); assert!(!true_.is_null());
assert!(!true_.is_null_or_undefined()); assert!(!true_.is_null_or_undefined());
let false_ = v8::new_false(scope); let false_ = v8::Boolean::new(scope, false);
assert!(false_.is_false());
assert!(!false_.is_undefined()); assert!(!false_.is_undefined());
assert!(!false_.is_null()); assert!(!false_.is_null());
assert!(!false_.is_null_or_undefined()); assert!(!false_.is_null_or_undefined());
@ -1177,12 +1179,12 @@ fn mock_script_origin<'sc>(
let resource_name = v8_str(scope, resource_name_); let resource_name = v8_str(scope, resource_name_);
let resource_line_offset = v8::Integer::new(scope, 0); let resource_line_offset = v8::Integer::new(scope, 0);
let resource_column_offset = v8::Integer::new(scope, 0); let resource_column_offset = v8::Integer::new(scope, 0);
let resource_is_shared_cross_origin = v8::new_true(scope); let resource_is_shared_cross_origin = v8::Boolean::new(scope, true);
let script_id = v8::Integer::new(scope, 123); let script_id = v8::Integer::new(scope, 123);
let source_map_url = v8_str(scope, "source_map_url"); let source_map_url = v8_str(scope, "source_map_url");
let resource_is_opaque = v8::new_true(scope); let resource_is_opaque = v8::Boolean::new(scope, true);
let is_wasm = v8::new_false(scope); let is_wasm = v8::Boolean::new(scope, false);
let is_module = v8::new_true(scope); let is_module = v8::Boolean::new(scope, true);
v8::ScriptOrigin::new( v8::ScriptOrigin::new(
resource_name.into(), resource_name.into(),
resource_line_offset, resource_line_offset,
@ -1536,7 +1538,7 @@ fn snapshot_creator() {
let mut script = let mut script =
v8::Script::compile(scope, context, source, None).unwrap(); v8::Script::compile(scope, context, source, None).unwrap();
let result = script.run(scope, context).unwrap(); let result = script.run(scope, context).unwrap();
let true_val = v8::new_true(scope).into(); let true_val = v8::Boolean::new(scope, true).into();
assert!(result.same_value(true_val)); assert!(result.same_value(true_val));
context.exit(); context.exit();
} }
@ -1985,7 +1987,7 @@ fn try_from_local() {
} }
{ {
let value: v8::Local<v8::Value> = v8::new_true(scope).into(); let value: v8::Local<v8::Value> = v8::Boolean::new(scope, true).into();
let primitive = v8::Local::<v8::Primitive>::try_from(value).unwrap(); let primitive = v8::Local::<v8::Primitive>::try_from(value).unwrap();
let _boolean = v8::Local::<v8::Boolean>::try_from(value).unwrap(); let _boolean = v8::Local::<v8::Boolean>::try_from(value).unwrap();
let _boolean = v8::Local::<v8::Boolean>::try_from(primitive).unwrap(); let _boolean = v8::Local::<v8::Boolean>::try_from(primitive).unwrap();