diff --git a/src/binding.cc b/src/binding.cc index 2f33ae7a..9f9e4954 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -261,6 +261,10 @@ v8::Value* v8__Local__New(v8::Isolate* isolate, v8::Value* other) { return local_to_ptr(v8::Local::New(isolate, ptr_to_local(other))); } +bool v8__Local__EQ(v8::Local self, v8::Local other) { + return self == other; +} + v8::Value* v8__Global__New(v8::Isolate* isolate, v8::Value* other) { // We have to use `std::move()` here because v8 disables the copy constructor // for class `v8::Global`. diff --git a/src/data.rs b/src/data.rs index 54a684bf..c96fcc98 100644 --- a/src/data.rs +++ b/src/data.rs @@ -3,6 +3,7 @@ use std::convert::From; use std::convert::TryFrom; use std::error::Error; +use std::ffi::c_void; use std::fmt; use std::fmt::Display; use std::fmt::Formatter; @@ -47,6 +48,33 @@ macro_rules! impl_try_from { }; } +macro_rules! impl_eq { + { for $type:ident } => { + impl<'sc> Eq for Local<'sc, $type> {} + }; +} + +macro_rules! impl_partial_eq { + { $rhs:ident for $type:ident use identity } => { + impl<'sc> PartialEq> for Local<'sc, $type> { + fn eq(&self, other: &Local<'sc, $rhs>) -> bool { + unsafe { v8__Local__EQ(transmute(*self), transmute(*other)) } + } + } + }; + { $rhs:ident for $type:ident use strict_equals } => { + impl<'sc> PartialEq> for Local<'sc, $type> { + fn eq(&self, other: &Local<'sc, $rhs>) -> bool { + self.strict_equals((*other).into()) + } + } + }; +} + +extern "C" { + fn v8__Local__EQ(this: Local, other: Local) -> bool; +} + #[derive(Clone, Copy, Debug)] pub struct TryFromTypeError { expected_type: &'static str, @@ -71,6 +99,9 @@ impl Error for TryFromTypeError {} #[repr(C)] pub struct Context(Opaque); +impl_eq! { for Context } +impl_partial_eq! { Context for Context use identity } + /// The superclass of objects that can reside on V8's heap. #[repr(C)] pub struct Data(Opaque); @@ -128,6 +159,50 @@ impl_from! { Number for Data } impl_from! { Integer for Data } impl_from! { Int32 for Data } impl_from! { Uint32 for Data } +impl_partial_eq! { AccessorSignature for Data use identity } +impl_partial_eq! { Module for Data use identity } +impl_partial_eq! { Private for Data use identity } +impl_partial_eq! { Signature for Data use identity } +impl_partial_eq! { Template for Data use identity } +impl_partial_eq! { FunctionTemplate for Data use identity } +impl_partial_eq! { ObjectTemplate for Data use identity } +impl_partial_eq! { UnboundModuleScript for Data use identity } +impl_partial_eq! { External for Data use identity } +impl_partial_eq! { Object for Data use identity } +impl_partial_eq! { Array for Data use identity } +impl_partial_eq! { ArrayBuffer for Data use identity } +impl_partial_eq! { ArrayBufferView for Data use identity } +impl_partial_eq! { DataView for Data use identity } +impl_partial_eq! { TypedArray for Data use identity } +impl_partial_eq! { BigInt64Array for Data use identity } +impl_partial_eq! { BigUint64Array for Data use identity } +impl_partial_eq! { Float32Array for Data use identity } +impl_partial_eq! { Float64Array for Data use identity } +impl_partial_eq! { Int16Array for Data use identity } +impl_partial_eq! { Int32Array for Data use identity } +impl_partial_eq! { Int8Array for Data use identity } +impl_partial_eq! { Uint16Array for Data use identity } +impl_partial_eq! { Uint32Array for Data use identity } +impl_partial_eq! { Uint8Array for Data use identity } +impl_partial_eq! { Uint8ClampedArray for Data use identity } +impl_partial_eq! { BigIntObject for Data use identity } +impl_partial_eq! { BooleanObject for Data use identity } +impl_partial_eq! { Date for Data use identity } +impl_partial_eq! { FinalizationGroup for Data use identity } +impl_partial_eq! { Function for Data use identity } +impl_partial_eq! { Map for Data use identity } +impl_partial_eq! { NumberObject for Data use identity } +impl_partial_eq! { Promise for Data use identity } +impl_partial_eq! { PromiseResolver for Data use identity } +impl_partial_eq! { Proxy for Data use identity } +impl_partial_eq! { RegExp for Data use identity } +impl_partial_eq! { Set for Data use identity } +impl_partial_eq! { SharedArrayBuffer for Data use identity } +impl_partial_eq! { StringObject for Data use identity } +impl_partial_eq! { SymbolObject for Data use identity } +impl_partial_eq! { WasmModuleObject for Data use identity } +impl_partial_eq! { Boolean for Data use identity } +impl_partial_eq! { Symbol for Data use identity } /// An AccessorSignature specifies which receivers are valid parameters /// to an accessor callback. @@ -135,12 +210,18 @@ impl_from! { Uint32 for Data } pub struct AccessorSignature(Opaque); impl_deref! { Data for AccessorSignature } +impl_eq! { for AccessorSignature } +impl_partial_eq! { Data for AccessorSignature use identity } +impl_partial_eq! { AccessorSignature for AccessorSignature use identity } /// A compiled JavaScript module. #[repr(C)] pub struct Module(Opaque); impl_deref! { Data for Module } +impl_eq! { for Module } +impl_partial_eq! { Data for Module use identity } +impl_partial_eq! { Module for Module use identity } /// A private symbol /// @@ -149,6 +230,9 @@ impl_deref! { Data for Module } pub struct Private(Opaque); impl_deref! { Data for Private } +impl_eq! { for Private } +impl_partial_eq! { Data for Private use identity } +impl_partial_eq! { Private for Private use identity } /// A Signature specifies which receiver is valid for a function. /// @@ -160,6 +244,9 @@ impl_deref! { Data for Private } pub struct Signature(Opaque); impl_deref! { Data for Signature } +impl_eq! { for Signature } +impl_partial_eq! { Data for Signature use identity } +impl_partial_eq! { Signature for Signature use identity } /// The superclass of object and function templates. #[repr(C)] @@ -168,6 +255,11 @@ pub struct Template(Opaque); impl_deref! { Data for Template } impl_from! { FunctionTemplate for Template } impl_from! { ObjectTemplate for Template } +impl_eq! { for Template } +impl_partial_eq! { Data for Template use identity } +impl_partial_eq! { Template for Template use identity } +impl_partial_eq! { FunctionTemplate for Template use identity } +impl_partial_eq! { ObjectTemplate for Template use identity } /// A FunctionTemplate is used to create functions at runtime. There /// can only be one function created from a FunctionTemplate in a @@ -271,6 +363,10 @@ impl_from! { ObjectTemplate for Template } pub struct FunctionTemplate(Opaque); impl_deref! { Template for FunctionTemplate } +impl_eq! { for FunctionTemplate } +impl_partial_eq! { Data for FunctionTemplate use identity } +impl_partial_eq! { Template for FunctionTemplate use identity } +impl_partial_eq! { FunctionTemplate for FunctionTemplate use identity } /// An ObjectTemplate is used to create objects at runtime. /// @@ -280,12 +376,19 @@ impl_deref! { Template for FunctionTemplate } pub struct ObjectTemplate(Opaque); impl_deref! { Template for ObjectTemplate } +impl_eq! { for ObjectTemplate } +impl_partial_eq! { Data for ObjectTemplate use identity } +impl_partial_eq! { Template for ObjectTemplate use identity } +impl_partial_eq! { ObjectTemplate for ObjectTemplate use identity } /// A compiled JavaScript module, not yet tied to a Context. #[repr(C)] pub struct UnboundModuleScript(Opaque); impl_deref! { Data for UnboundModuleScript } +impl_eq! { for UnboundModuleScript } +impl_partial_eq! { Data for UnboundModuleScript use identity } +impl_partial_eq! { UnboundModuleScript for UnboundModuleScript use identity } /// The superclass of all JavaScript values and objects. #[repr(C)] @@ -336,6 +439,51 @@ impl_from! { Number for Value } impl_from! { Integer for Value } impl_from! { Int32 for Value } impl_from! { Uint32 for Value } +impl_partial_eq! { Value for Value use strict_equals } +impl_partial_eq! { External for Value use identity } +impl_partial_eq! { Object for Value use identity } +impl_partial_eq! { Array for Value use identity } +impl_partial_eq! { ArrayBuffer for Value use identity } +impl_partial_eq! { ArrayBufferView for Value use identity } +impl_partial_eq! { DataView for Value use identity } +impl_partial_eq! { TypedArray for Value use identity } +impl_partial_eq! { BigInt64Array for Value use identity } +impl_partial_eq! { BigUint64Array for Value use identity } +impl_partial_eq! { Float32Array for Value use identity } +impl_partial_eq! { Float64Array for Value use identity } +impl_partial_eq! { Int16Array for Value use identity } +impl_partial_eq! { Int32Array for Value use identity } +impl_partial_eq! { Int8Array for Value use identity } +impl_partial_eq! { Uint16Array for Value use identity } +impl_partial_eq! { Uint32Array for Value use identity } +impl_partial_eq! { Uint8Array for Value use identity } +impl_partial_eq! { Uint8ClampedArray for Value use identity } +impl_partial_eq! { BigIntObject for Value use identity } +impl_partial_eq! { BooleanObject for Value use identity } +impl_partial_eq! { Date for Value use identity } +impl_partial_eq! { FinalizationGroup for Value use identity } +impl_partial_eq! { Function for Value use identity } +impl_partial_eq! { Map for Value use identity } +impl_partial_eq! { NumberObject for Value use identity } +impl_partial_eq! { Promise for Value use identity } +impl_partial_eq! { PromiseResolver for Value use identity } +impl_partial_eq! { Proxy for Value use identity } +impl_partial_eq! { RegExp for Value use identity } +impl_partial_eq! { Set for Value use identity } +impl_partial_eq! { SharedArrayBuffer for Value use identity } +impl_partial_eq! { StringObject for Value use identity } +impl_partial_eq! { SymbolObject for Value use identity } +impl_partial_eq! { WasmModuleObject for Value use identity } +impl_partial_eq! { Primitive for Value use strict_equals } +impl_partial_eq! { BigInt for Value use strict_equals } +impl_partial_eq! { Boolean for Value use identity } +impl_partial_eq! { Name for Value use strict_equals } +impl_partial_eq! { String for Value use strict_equals } +impl_partial_eq! { Symbol for Value use identity } +impl_partial_eq! { Number for Value use strict_equals } +impl_partial_eq! { Integer for Value use strict_equals } +impl_partial_eq! { Int32 for Value use strict_equals } +impl_partial_eq! { Uint32 for Value use strict_equals } /// A JavaScript value that wraps a C++ void*. This type of value is mainly used /// to associate C++ data structures with JavaScript objects. @@ -344,6 +492,10 @@ pub struct External(Opaque); impl_deref! { Value for External } impl_try_from! { Value for External if v => v.is_external() } +impl_eq! { for External } +impl_partial_eq! { Data for External use identity } +impl_partial_eq! { Value for External use identity } +impl_partial_eq! { External for External use identity } /// A JavaScript object (ECMA-262, 4.3.3) #[repr(C)] @@ -383,6 +535,42 @@ impl_from! { SharedArrayBuffer for Object } impl_from! { StringObject for Object } impl_from! { SymbolObject for Object } impl_from! { WasmModuleObject for Object } +impl_eq! { for Object } +impl_partial_eq! { Data for Object use identity } +impl_partial_eq! { Value for Object use identity } +impl_partial_eq! { Object for Object use identity } +impl_partial_eq! { Array for Object use identity } +impl_partial_eq! { ArrayBuffer for Object use identity } +impl_partial_eq! { ArrayBufferView for Object use identity } +impl_partial_eq! { DataView for Object use identity } +impl_partial_eq! { TypedArray for Object use identity } +impl_partial_eq! { BigInt64Array for Object use identity } +impl_partial_eq! { BigUint64Array for Object use identity } +impl_partial_eq! { Float32Array for Object use identity } +impl_partial_eq! { Float64Array for Object use identity } +impl_partial_eq! { Int16Array for Object use identity } +impl_partial_eq! { Int32Array for Object use identity } +impl_partial_eq! { Int8Array for Object use identity } +impl_partial_eq! { Uint16Array for Object use identity } +impl_partial_eq! { Uint32Array for Object use identity } +impl_partial_eq! { Uint8Array for Object use identity } +impl_partial_eq! { Uint8ClampedArray for Object use identity } +impl_partial_eq! { BigIntObject for Object use identity } +impl_partial_eq! { BooleanObject for Object use identity } +impl_partial_eq! { Date for Object use identity } +impl_partial_eq! { FinalizationGroup for Object use identity } +impl_partial_eq! { Function for Object use identity } +impl_partial_eq! { Map for Object use identity } +impl_partial_eq! { NumberObject for Object use identity } +impl_partial_eq! { Promise for Object use identity } +impl_partial_eq! { PromiseResolver for Object use identity } +impl_partial_eq! { Proxy for Object use identity } +impl_partial_eq! { RegExp for Object use identity } +impl_partial_eq! { Set for Object use identity } +impl_partial_eq! { SharedArrayBuffer for Object use identity } +impl_partial_eq! { StringObject for Object use identity } +impl_partial_eq! { SymbolObject for Object use identity } +impl_partial_eq! { WasmModuleObject for Object use identity } /// An instance of the built-in array constructor (ECMA-262, 15.4.2). #[repr(C)] @@ -391,6 +579,11 @@ pub struct Array(Opaque); impl_deref! { Object for Array } impl_try_from! { Value for Array if v => v.is_array() } impl_try_from! { Object for Array if v => v.is_array() } +impl_eq! { for Array } +impl_partial_eq! { Data for Array use identity } +impl_partial_eq! { Value for Array use identity } +impl_partial_eq! { Object for Array use identity } +impl_partial_eq! { Array for Array use identity } /// An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). #[repr(C)] @@ -399,6 +592,11 @@ pub struct ArrayBuffer(Opaque); impl_deref! { Object for ArrayBuffer } impl_try_from! { Value for ArrayBuffer if v => v.is_array_buffer() } impl_try_from! { Object for ArrayBuffer if v => v.is_array_buffer() } +impl_eq! { for ArrayBuffer } +impl_partial_eq! { Data for ArrayBuffer use identity } +impl_partial_eq! { Value for ArrayBuffer use identity } +impl_partial_eq! { Object for ArrayBuffer use identity } +impl_partial_eq! { ArrayBuffer for ArrayBuffer use identity } /// A base class for an instance of one of "views" over ArrayBuffer, /// including TypedArrays and DataView (ES6 draft 15.13). @@ -421,6 +619,24 @@ impl_from! { Uint16Array for ArrayBufferView } impl_from! { Uint32Array for ArrayBufferView } impl_from! { Uint8Array for ArrayBufferView } impl_from! { Uint8ClampedArray for ArrayBufferView } +impl_eq! { for ArrayBufferView } +impl_partial_eq! { Data for ArrayBufferView use identity } +impl_partial_eq! { Value for ArrayBufferView use identity } +impl_partial_eq! { Object for ArrayBufferView use identity } +impl_partial_eq! { ArrayBufferView for ArrayBufferView use identity } +impl_partial_eq! { DataView for ArrayBufferView use identity } +impl_partial_eq! { TypedArray for ArrayBufferView use identity } +impl_partial_eq! { BigInt64Array for ArrayBufferView use identity } +impl_partial_eq! { BigUint64Array for ArrayBufferView use identity } +impl_partial_eq! { Float32Array for ArrayBufferView use identity } +impl_partial_eq! { Float64Array for ArrayBufferView use identity } +impl_partial_eq! { Int16Array for ArrayBufferView use identity } +impl_partial_eq! { Int32Array for ArrayBufferView use identity } +impl_partial_eq! { Int8Array for ArrayBufferView use identity } +impl_partial_eq! { Uint16Array for ArrayBufferView use identity } +impl_partial_eq! { Uint32Array for ArrayBufferView use identity } +impl_partial_eq! { Uint8Array for ArrayBufferView use identity } +impl_partial_eq! { Uint8ClampedArray for ArrayBufferView use identity } /// An instance of DataView constructor (ES6 draft 15.13.7). #[repr(C)] @@ -430,6 +646,12 @@ impl_deref! { ArrayBufferView for DataView } impl_try_from! { Value for DataView if v => v.is_data_view() } impl_try_from! { Object for DataView if v => v.is_data_view() } impl_try_from! { ArrayBufferView for DataView if v => v.is_data_view() } +impl_eq! { for DataView } +impl_partial_eq! { Data for DataView use identity } +impl_partial_eq! { Value for DataView use identity } +impl_partial_eq! { Object for DataView use identity } +impl_partial_eq! { ArrayBufferView for DataView use identity } +impl_partial_eq! { DataView for DataView use identity } /// A base class for an instance of TypedArray series of constructors /// (ES6 draft 15.13.6). @@ -451,6 +673,23 @@ impl_from! { Uint16Array for TypedArray } impl_from! { Uint32Array for TypedArray } impl_from! { Uint8Array for TypedArray } impl_from! { Uint8ClampedArray for TypedArray } +impl_eq! { for TypedArray } +impl_partial_eq! { Data for TypedArray use identity } +impl_partial_eq! { Value for TypedArray use identity } +impl_partial_eq! { Object for TypedArray use identity } +impl_partial_eq! { ArrayBufferView for TypedArray use identity } +impl_partial_eq! { TypedArray for TypedArray use identity } +impl_partial_eq! { BigInt64Array for TypedArray use identity } +impl_partial_eq! { BigUint64Array for TypedArray use identity } +impl_partial_eq! { Float32Array for TypedArray use identity } +impl_partial_eq! { Float64Array for TypedArray use identity } +impl_partial_eq! { Int16Array for TypedArray use identity } +impl_partial_eq! { Int32Array for TypedArray use identity } +impl_partial_eq! { Int8Array for TypedArray use identity } +impl_partial_eq! { Uint16Array for TypedArray use identity } +impl_partial_eq! { Uint32Array for TypedArray use identity } +impl_partial_eq! { Uint8Array for TypedArray use identity } +impl_partial_eq! { Uint8ClampedArray for TypedArray use identity } /// An instance of BigInt64Array constructor. #[repr(C)] @@ -461,6 +700,13 @@ impl_try_from! { Value for BigInt64Array if v => v.is_big_int64_array() } impl_try_from! { Object for BigInt64Array if v => v.is_big_int64_array() } impl_try_from! { ArrayBufferView for BigInt64Array if v => v.is_big_int64_array() } impl_try_from! { TypedArray for BigInt64Array if v => v.is_big_int64_array() } +impl_eq! { for BigInt64Array } +impl_partial_eq! { Data for BigInt64Array use identity } +impl_partial_eq! { Value for BigInt64Array use identity } +impl_partial_eq! { Object for BigInt64Array use identity } +impl_partial_eq! { ArrayBufferView for BigInt64Array use identity } +impl_partial_eq! { TypedArray for BigInt64Array use identity } +impl_partial_eq! { BigInt64Array for BigInt64Array use identity } /// An instance of BigUint64Array constructor. #[repr(C)] @@ -471,6 +717,13 @@ impl_try_from! { Value for BigUint64Array if v => v.is_big_uint64_array() } impl_try_from! { Object for BigUint64Array if v => v.is_big_uint64_array() } impl_try_from! { ArrayBufferView for BigUint64Array if v => v.is_big_uint64_array() } impl_try_from! { TypedArray for BigUint64Array if v => v.is_big_uint64_array() } +impl_eq! { for BigUint64Array } +impl_partial_eq! { Data for BigUint64Array use identity } +impl_partial_eq! { Value for BigUint64Array use identity } +impl_partial_eq! { Object for BigUint64Array use identity } +impl_partial_eq! { ArrayBufferView for BigUint64Array use identity } +impl_partial_eq! { TypedArray for BigUint64Array use identity } +impl_partial_eq! { BigUint64Array for BigUint64Array use identity } /// An instance of Float32Array constructor (ES6 draft 15.13.6). #[repr(C)] @@ -481,6 +734,13 @@ impl_try_from! { Value for Float32Array if v => v.is_float32_array() } impl_try_from! { Object for Float32Array if v => v.is_float32_array() } impl_try_from! { ArrayBufferView for Float32Array if v => v.is_float32_array() } impl_try_from! { TypedArray for Float32Array if v => v.is_float32_array() } +impl_eq! { for Float32Array } +impl_partial_eq! { Data for Float32Array use identity } +impl_partial_eq! { Value for Float32Array use identity } +impl_partial_eq! { Object for Float32Array use identity } +impl_partial_eq! { ArrayBufferView for Float32Array use identity } +impl_partial_eq! { TypedArray for Float32Array use identity } +impl_partial_eq! { Float32Array for Float32Array use identity } /// An instance of Float64Array constructor (ES6 draft 15.13.6). #[repr(C)] @@ -491,6 +751,13 @@ impl_try_from! { Value for Float64Array if v => v.is_float64_array() } impl_try_from! { Object for Float64Array if v => v.is_float64_array() } impl_try_from! { ArrayBufferView for Float64Array if v => v.is_float64_array() } impl_try_from! { TypedArray for Float64Array if v => v.is_float64_array() } +impl_eq! { for Float64Array } +impl_partial_eq! { Data for Float64Array use identity } +impl_partial_eq! { Value for Float64Array use identity } +impl_partial_eq! { Object for Float64Array use identity } +impl_partial_eq! { ArrayBufferView for Float64Array use identity } +impl_partial_eq! { TypedArray for Float64Array use identity } +impl_partial_eq! { Float64Array for Float64Array use identity } /// An instance of Int16Array constructor (ES6 draft 15.13.6). #[repr(C)] @@ -501,6 +768,13 @@ impl_try_from! { Value for Int16Array if v => v.is_int16_array() } impl_try_from! { Object for Int16Array if v => v.is_int16_array() } impl_try_from! { ArrayBufferView for Int16Array if v => v.is_int16_array() } impl_try_from! { TypedArray for Int16Array if v => v.is_int16_array() } +impl_eq! { for Int16Array } +impl_partial_eq! { Data for Int16Array use identity } +impl_partial_eq! { Value for Int16Array use identity } +impl_partial_eq! { Object for Int16Array use identity } +impl_partial_eq! { ArrayBufferView for Int16Array use identity } +impl_partial_eq! { TypedArray for Int16Array use identity } +impl_partial_eq! { Int16Array for Int16Array use identity } /// An instance of Int32Array constructor (ES6 draft 15.13.6). #[repr(C)] @@ -511,6 +785,13 @@ impl_try_from! { Value for Int32Array if v => v.is_int32_array() } impl_try_from! { Object for Int32Array if v => v.is_int32_array() } impl_try_from! { ArrayBufferView for Int32Array if v => v.is_int32_array() } impl_try_from! { TypedArray for Int32Array if v => v.is_int32_array() } +impl_eq! { for Int32Array } +impl_partial_eq! { Data for Int32Array use identity } +impl_partial_eq! { Value for Int32Array use identity } +impl_partial_eq! { Object for Int32Array use identity } +impl_partial_eq! { ArrayBufferView for Int32Array use identity } +impl_partial_eq! { TypedArray for Int32Array use identity } +impl_partial_eq! { Int32Array for Int32Array use identity } /// An instance of Int8Array constructor (ES6 draft 15.13.6). #[repr(C)] @@ -521,6 +802,13 @@ impl_try_from! { Value for Int8Array if v => v.is_int8_array() } impl_try_from! { Object for Int8Array if v => v.is_int8_array() } impl_try_from! { ArrayBufferView for Int8Array if v => v.is_int8_array() } impl_try_from! { TypedArray for Int8Array if v => v.is_int8_array() } +impl_eq! { for Int8Array } +impl_partial_eq! { Data for Int8Array use identity } +impl_partial_eq! { Value for Int8Array use identity } +impl_partial_eq! { Object for Int8Array use identity } +impl_partial_eq! { ArrayBufferView for Int8Array use identity } +impl_partial_eq! { TypedArray for Int8Array use identity } +impl_partial_eq! { Int8Array for Int8Array use identity } /// An instance of Uint16Array constructor (ES6 draft 15.13.6). #[repr(C)] @@ -531,6 +819,13 @@ impl_try_from! { Value for Uint16Array if v => v.is_uint16_array() } impl_try_from! { Object for Uint16Array if v => v.is_uint16_array() } impl_try_from! { ArrayBufferView for Uint16Array if v => v.is_uint16_array() } impl_try_from! { TypedArray for Uint16Array if v => v.is_uint16_array() } +impl_eq! { for Uint16Array } +impl_partial_eq! { Data for Uint16Array use identity } +impl_partial_eq! { Value for Uint16Array use identity } +impl_partial_eq! { Object for Uint16Array use identity } +impl_partial_eq! { ArrayBufferView for Uint16Array use identity } +impl_partial_eq! { TypedArray for Uint16Array use identity } +impl_partial_eq! { Uint16Array for Uint16Array use identity } /// An instance of Uint32Array constructor (ES6 draft 15.13.6). #[repr(C)] @@ -541,6 +836,13 @@ impl_try_from! { Value for Uint32Array if v => v.is_uint32_array() } impl_try_from! { Object for Uint32Array if v => v.is_uint32_array() } impl_try_from! { ArrayBufferView for Uint32Array if v => v.is_uint32_array() } impl_try_from! { TypedArray for Uint32Array if v => v.is_uint32_array() } +impl_eq! { for Uint32Array } +impl_partial_eq! { Data for Uint32Array use identity } +impl_partial_eq! { Value for Uint32Array use identity } +impl_partial_eq! { Object for Uint32Array use identity } +impl_partial_eq! { ArrayBufferView for Uint32Array use identity } +impl_partial_eq! { TypedArray for Uint32Array use identity } +impl_partial_eq! { Uint32Array for Uint32Array use identity } /// An instance of Uint8Array constructor (ES6 draft 15.13.6). #[repr(C)] @@ -551,6 +853,13 @@ impl_try_from! { Value for Uint8Array if v => v.is_uint8_array() } impl_try_from! { Object for Uint8Array if v => v.is_uint8_array() } impl_try_from! { ArrayBufferView for Uint8Array if v => v.is_uint8_array() } impl_try_from! { TypedArray for Uint8Array if v => v.is_uint8_array() } +impl_eq! { for Uint8Array } +impl_partial_eq! { Data for Uint8Array use identity } +impl_partial_eq! { Value for Uint8Array use identity } +impl_partial_eq! { Object for Uint8Array use identity } +impl_partial_eq! { ArrayBufferView for Uint8Array use identity } +impl_partial_eq! { TypedArray for Uint8Array use identity } +impl_partial_eq! { Uint8Array for Uint8Array use identity } /// An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6). #[repr(C)] @@ -561,6 +870,13 @@ impl_try_from! { Value for Uint8ClampedArray if v => v.is_uint8_clamped_array() impl_try_from! { Object for Uint8ClampedArray if v => v.is_uint8_clamped_array() } impl_try_from! { ArrayBufferView for Uint8ClampedArray if v => v.is_uint8_clamped_array() } impl_try_from! { TypedArray for Uint8ClampedArray if v => v.is_uint8_clamped_array() } +impl_eq! { for Uint8ClampedArray } +impl_partial_eq! { Data for Uint8ClampedArray use identity } +impl_partial_eq! { Value for Uint8ClampedArray use identity } +impl_partial_eq! { Object for Uint8ClampedArray use identity } +impl_partial_eq! { ArrayBufferView for Uint8ClampedArray use identity } +impl_partial_eq! { TypedArray for Uint8ClampedArray use identity } +impl_partial_eq! { Uint8ClampedArray for Uint8ClampedArray use identity } /// A BigInt object (https://tc39.github.io/proposal-bigint) #[repr(C)] @@ -569,6 +885,11 @@ pub struct BigIntObject(Opaque); impl_deref! { Object for BigIntObject } impl_try_from! { Value for BigIntObject if v => v.is_big_int_object() } impl_try_from! { Object for BigIntObject if v => v.is_big_int_object() } +impl_eq! { for BigIntObject } +impl_partial_eq! { Data for BigIntObject use identity } +impl_partial_eq! { Value for BigIntObject use identity } +impl_partial_eq! { Object for BigIntObject use identity } +impl_partial_eq! { BigIntObject for BigIntObject use identity } /// A Boolean object (ECMA-262, 4.3.15). #[repr(C)] @@ -577,6 +898,11 @@ pub struct BooleanObject(Opaque); impl_deref! { Object for BooleanObject } impl_try_from! { Value for BooleanObject if v => v.is_boolean_object() } impl_try_from! { Object for BooleanObject if v => v.is_boolean_object() } +impl_eq! { for BooleanObject } +impl_partial_eq! { Data for BooleanObject use identity } +impl_partial_eq! { Value for BooleanObject use identity } +impl_partial_eq! { Object for BooleanObject use identity } +impl_partial_eq! { BooleanObject for BooleanObject use identity } /// An instance of the built-in Date constructor (ECMA-262, 15.9). #[repr(C)] @@ -585,6 +911,11 @@ pub struct Date(Opaque); impl_deref! { Object for Date } impl_try_from! { Value for Date if v => v.is_date() } impl_try_from! { Object for Date if v => v.is_date() } +impl_eq! { for Date } +impl_partial_eq! { Data for Date use identity } +impl_partial_eq! { Value for Date use identity } +impl_partial_eq! { Object for Date use identity } +impl_partial_eq! { Date for Date use identity } /// An instance of the built-in FinalizationGroup constructor. /// @@ -593,6 +924,11 @@ impl_try_from! { Object for Date if v => v.is_date() } pub struct FinalizationGroup(Opaque); impl_deref! { Object for FinalizationGroup } +impl_eq! { for FinalizationGroup } +impl_partial_eq! { Data for FinalizationGroup use identity } +impl_partial_eq! { Value for FinalizationGroup use identity } +impl_partial_eq! { Object for FinalizationGroup use identity } +impl_partial_eq! { FinalizationGroup for FinalizationGroup use identity } /// A JavaScript function object (ECMA-262, 15.3). #[repr(C)] @@ -601,6 +937,11 @@ pub struct Function(Opaque); impl_deref! { Object for Function } impl_try_from! { Value for Function if v => v.is_function() } impl_try_from! { Object for Function if v => v.is_function() } +impl_eq! { for Function } +impl_partial_eq! { Data for Function use identity } +impl_partial_eq! { Value for Function use identity } +impl_partial_eq! { Object for Function use identity } +impl_partial_eq! { Function for Function use identity } /// An instance of the built-in Map constructor (ECMA-262, 6th Edition, 23.1.1). #[repr(C)] @@ -609,6 +950,11 @@ pub struct Map(Opaque); impl_deref! { Object for Map } impl_try_from! { Value for Map if v => v.is_map() } impl_try_from! { Object for Map if v => v.is_map() } +impl_eq! { for Map } +impl_partial_eq! { Data for Map use identity } +impl_partial_eq! { Value for Map use identity } +impl_partial_eq! { Object for Map use identity } +impl_partial_eq! { Map for Map use identity } /// A Number object (ECMA-262, 4.3.21). #[repr(C)] @@ -617,6 +963,11 @@ pub struct NumberObject(Opaque); impl_deref! { Object for NumberObject } impl_try_from! { Value for NumberObject if v => v.is_number_object() } impl_try_from! { Object for NumberObject if v => v.is_number_object() } +impl_eq! { for NumberObject } +impl_partial_eq! { Data for NumberObject use identity } +impl_partial_eq! { Value for NumberObject use identity } +impl_partial_eq! { Object for NumberObject use identity } +impl_partial_eq! { NumberObject for NumberObject use identity } /// An instance of the built-in Promise constructor (ES6 draft). #[repr(C)] @@ -625,11 +976,21 @@ pub struct Promise(Opaque); impl_deref! { Object for Promise } impl_try_from! { Value for Promise if v => v.is_promise() } impl_try_from! { Object for Promise if v => v.is_promise() } +impl_eq! { for Promise } +impl_partial_eq! { Data for Promise use identity } +impl_partial_eq! { Value for Promise use identity } +impl_partial_eq! { Object for Promise use identity } +impl_partial_eq! { Promise for Promise use identity } #[repr(C)] pub struct PromiseResolver(Opaque); impl_deref! { Object for PromiseResolver } +impl_eq! { for PromiseResolver } +impl_partial_eq! { Data for PromiseResolver use identity } +impl_partial_eq! { Value for PromiseResolver use identity } +impl_partial_eq! { Object for PromiseResolver use identity } +impl_partial_eq! { PromiseResolver for PromiseResolver use identity } /// An instance of the built-in Proxy constructor (ECMA-262, 6th Edition, /// 26.2.1). @@ -639,6 +1000,11 @@ pub struct Proxy(Opaque); impl_deref! { Object for Proxy } impl_try_from! { Value for Proxy if v => v.is_proxy() } impl_try_from! { Object for Proxy if v => v.is_proxy() } +impl_eq! { for Proxy } +impl_partial_eq! { Data for Proxy use identity } +impl_partial_eq! { Value for Proxy use identity } +impl_partial_eq! { Object for Proxy use identity } +impl_partial_eq! { Proxy for Proxy use identity } /// An instance of the built-in RegExp constructor (ECMA-262, 15.10). #[repr(C)] @@ -647,6 +1013,11 @@ pub struct RegExp(Opaque); impl_deref! { Object for RegExp } impl_try_from! { Value for RegExp if v => v.is_reg_exp() } impl_try_from! { Object for RegExp if v => v.is_reg_exp() } +impl_eq! { for RegExp } +impl_partial_eq! { Data for RegExp use identity } +impl_partial_eq! { Value for RegExp use identity } +impl_partial_eq! { Object for RegExp use identity } +impl_partial_eq! { RegExp for RegExp use identity } /// An instance of the built-in Set constructor (ECMA-262, 6th Edition, 23.2.1). #[repr(C)] @@ -655,6 +1026,11 @@ pub struct Set(Opaque); impl_deref! { Object for Set } impl_try_from! { Value for Set if v => v.is_set() } impl_try_from! { Object for Set if v => v.is_set() } +impl_eq! { for Set } +impl_partial_eq! { Data for Set use identity } +impl_partial_eq! { Value for Set use identity } +impl_partial_eq! { Object for Set use identity } +impl_partial_eq! { Set for Set use identity } /// An instance of the built-in SharedArrayBuffer constructor. #[repr(C)] @@ -663,6 +1039,11 @@ pub struct SharedArrayBuffer(Opaque); impl_deref! { Object for SharedArrayBuffer } impl_try_from! { Value for SharedArrayBuffer if v => v.is_shared_array_buffer() } impl_try_from! { Object for SharedArrayBuffer if v => v.is_shared_array_buffer() } +impl_eq! { for SharedArrayBuffer } +impl_partial_eq! { Data for SharedArrayBuffer use identity } +impl_partial_eq! { Value for SharedArrayBuffer use identity } +impl_partial_eq! { Object for SharedArrayBuffer use identity } +impl_partial_eq! { SharedArrayBuffer for SharedArrayBuffer use identity } /// A String object (ECMA-262, 4.3.18). #[repr(C)] @@ -671,6 +1052,11 @@ pub struct StringObject(Opaque); impl_deref! { Object for StringObject } impl_try_from! { Value for StringObject if v => v.is_string_object() } impl_try_from! { Object for StringObject if v => v.is_string_object() } +impl_eq! { for StringObject } +impl_partial_eq! { Data for StringObject use identity } +impl_partial_eq! { Value for StringObject use identity } +impl_partial_eq! { Object for StringObject use identity } +impl_partial_eq! { StringObject for StringObject use identity } /// A Symbol object (ECMA-262 edition 6). #[repr(C)] @@ -679,6 +1065,11 @@ pub struct SymbolObject(Opaque); impl_deref! { Object for SymbolObject } impl_try_from! { Value for SymbolObject if v => v.is_symbol_object() } impl_try_from! { Object for SymbolObject if v => v.is_symbol_object() } +impl_eq! { for SymbolObject } +impl_partial_eq! { Data for SymbolObject use identity } +impl_partial_eq! { Value for SymbolObject use identity } +impl_partial_eq! { Object for SymbolObject use identity } +impl_partial_eq! { SymbolObject for SymbolObject use identity } #[repr(C)] pub struct WasmModuleObject(Opaque); @@ -686,6 +1077,11 @@ pub struct WasmModuleObject(Opaque); impl_deref! { Object for WasmModuleObject } impl_try_from! { Value for WasmModuleObject if v => v.is_wasm_module_object() } impl_try_from! { Object for WasmModuleObject if v => v.is_wasm_module_object() } +impl_eq! { for WasmModuleObject } +impl_partial_eq! { Data for WasmModuleObject use identity } +impl_partial_eq! { Value for WasmModuleObject use identity } +impl_partial_eq! { Object for WasmModuleObject use identity } +impl_partial_eq! { WasmModuleObject for WasmModuleObject use identity } /// The superclass of primitive values. See ECMA-262 4.3.2. #[repr(C)] @@ -702,6 +1098,17 @@ impl_from! { Number for Primitive } impl_from! { Integer for Primitive } impl_from! { Int32 for Primitive } impl_from! { Uint32 for Primitive } +impl_partial_eq! { Value for Primitive use strict_equals } +impl_partial_eq! { Primitive for Primitive use strict_equals } +impl_partial_eq! { BigInt for Primitive use strict_equals } +impl_partial_eq! { Boolean for Primitive use identity } +impl_partial_eq! { Name for Primitive use strict_equals } +impl_partial_eq! { String for Primitive use strict_equals } +impl_partial_eq! { Symbol for Primitive use identity } +impl_partial_eq! { Number for Primitive use strict_equals } +impl_partial_eq! { Integer for Primitive use strict_equals } +impl_partial_eq! { Int32 for Primitive use strict_equals } +impl_partial_eq! { Uint32 for Primitive use strict_equals } /// A JavaScript BigInt value (https://tc39.github.io/proposal-bigint) #[repr(C)] @@ -710,6 +1117,10 @@ pub struct BigInt(Opaque); impl_deref! { Primitive for BigInt } impl_try_from! { Value for BigInt if v => v.is_big_int() } impl_try_from! { Primitive for BigInt if v => v.is_big_int() } +impl_eq! { for BigInt } +impl_partial_eq! { Value for BigInt use strict_equals } +impl_partial_eq! { Primitive for BigInt use strict_equals } +impl_partial_eq! { BigInt for BigInt use strict_equals } /// A primitive boolean value (ECMA-262, 4.3.14). Either the true /// or false value. @@ -719,6 +1130,11 @@ pub struct Boolean(Opaque); impl_deref! { Primitive for Boolean } impl_try_from! { Value for Boolean if v => v.is_boolean() } impl_try_from! { Primitive for Boolean if v => v.is_boolean() } +impl_eq! { for Boolean } +impl_partial_eq! { Data for Boolean use identity } +impl_partial_eq! { Value for Boolean use identity } +impl_partial_eq! { Primitive for Boolean use identity } +impl_partial_eq! { Boolean for Boolean use identity } /// A superclass for symbols and strings. #[repr(C)] @@ -729,6 +1145,12 @@ impl_try_from! { Value for Name if v => v.is_name() } impl_try_from! { Primitive for Name if v => v.is_name() } impl_from! { String for Name } impl_from! { Symbol for Name } +impl_eq! { for Name } +impl_partial_eq! { Value for Name use strict_equals } +impl_partial_eq! { Primitive for Name use strict_equals } +impl_partial_eq! { Name for Name use strict_equals } +impl_partial_eq! { String for Name use strict_equals } +impl_partial_eq! { Symbol for Name use identity } /// A JavaScript string value (ECMA-262, 4.3.17). #[repr(C)] @@ -738,6 +1160,11 @@ impl_deref! { Name for String } impl_try_from! { Value for String if v => v.is_string() } impl_try_from! { Primitive for String if v => v.is_string() } impl_try_from! { Name for String if v => v.is_string() } +impl_eq! { for String } +impl_partial_eq! { Value for String use strict_equals } +impl_partial_eq! { Primitive for String use strict_equals } +impl_partial_eq! { Name for String use strict_equals } +impl_partial_eq! { String for String use strict_equals } /// A JavaScript symbol (ECMA-262 edition 6) #[repr(C)] @@ -747,6 +1174,12 @@ impl_deref! { Name for Symbol } impl_try_from! { Value for Symbol if v => v.is_symbol() } impl_try_from! { Primitive for Symbol if v => v.is_symbol() } impl_try_from! { Name for Symbol if v => v.is_symbol() } +impl_eq! { for Symbol } +impl_partial_eq! { Data for Symbol use identity } +impl_partial_eq! { Value for Symbol use identity } +impl_partial_eq! { Primitive for Symbol use identity } +impl_partial_eq! { Name for Symbol use identity } +impl_partial_eq! { Symbol for Symbol use identity } /// A JavaScript number value (ECMA-262, 4.3.20) #[repr(C)] @@ -758,6 +1191,12 @@ impl_try_from! { Primitive for Number if v => v.is_number() } impl_from! { Integer for Number } impl_from! { Int32 for Number } impl_from! { Uint32 for Number } +impl_partial_eq! { Value for Number use strict_equals } +impl_partial_eq! { Primitive for Number use strict_equals } +impl_partial_eq! { Number for Number use strict_equals } +impl_partial_eq! { Integer for Number use strict_equals } +impl_partial_eq! { Int32 for Number use strict_equals } +impl_partial_eq! { Uint32 for Number use strict_equals } /// A JavaScript value representing a signed integer. #[repr(C)] @@ -769,6 +1208,13 @@ impl_try_from! { Primitive for Integer if v => v.is_int32() || v.is_uint32() } impl_try_from! { Number for Integer if v => v.is_int32() || v.is_uint32() } impl_from! { Int32 for Integer } impl_from! { Uint32 for Integer } +impl_eq! { for Integer } +impl_partial_eq! { Value for Integer use strict_equals } +impl_partial_eq! { Primitive for Integer use strict_equals } +impl_partial_eq! { Number for Integer use strict_equals } +impl_partial_eq! { Integer for Integer use strict_equals } +impl_partial_eq! { Int32 for Integer use strict_equals } +impl_partial_eq! { Uint32 for Integer use strict_equals } /// A JavaScript value representing a 32-bit signed integer. #[repr(C)] @@ -779,6 +1225,12 @@ impl_try_from! { Value for Int32 if v => v.is_int32() } impl_try_from! { Primitive for Int32 if v => v.is_int32() } impl_try_from! { Number for Int32 if v => v.is_int32() } impl_try_from! { Integer for Int32 if v => v.is_int32() } +impl_eq! { for Int32 } +impl_partial_eq! { Value for Int32 use strict_equals } +impl_partial_eq! { Primitive for Int32 use strict_equals } +impl_partial_eq! { Number for Int32 use strict_equals } +impl_partial_eq! { Integer for Int32 use strict_equals } +impl_partial_eq! { Int32 for Int32 use strict_equals } /// A JavaScript value representing a 32-bit unsigned integer. #[repr(C)] @@ -789,11 +1241,20 @@ impl_try_from! { Value for Uint32 if v => v.is_uint32() } impl_try_from! { Primitive for Uint32 if v => v.is_uint32() } impl_try_from! { Number for Uint32 if v => v.is_uint32() } impl_try_from! { Integer for Uint32 if v => v.is_uint32() } +impl_eq! { for Uint32 } +impl_partial_eq! { Value for Uint32 use strict_equals } +impl_partial_eq! { Primitive for Uint32 use strict_equals } +impl_partial_eq! { Number for Uint32 use strict_equals } +impl_partial_eq! { Integer for Uint32 use strict_equals } +impl_partial_eq! { Uint32 for Uint32 use strict_equals } /// An error message. #[repr(C)] pub struct Message(Opaque); +impl_eq! { for Message } +impl_partial_eq! { Message for Message use identity } + /// An array to hold Primitive values. This is used by the embedder to /// pass host defined options to the ScriptOptions during compilation. /// @@ -802,11 +1263,17 @@ pub struct Message(Opaque); #[repr(C)] pub struct PrimitiveArray(Opaque); +impl_eq! { for PrimitiveArray } +impl_partial_eq! { PrimitiveArray for PrimitiveArray use identity } + /// A compiled JavaScript script, tied to a Context which was active when the /// script was compiled. #[repr(C)] pub struct Script(Opaque); +impl_eq! { for Script } +impl_partial_eq! { Script for Script use identity } + /// A container type that holds relevant metadata for module loading. /// /// This is passed back to the embedder as part of @@ -814,16 +1281,28 @@ pub struct Script(Opaque); #[repr(C)] pub struct ScriptOrModule(Opaque); +impl_eq! { for ScriptOrModule } +impl_partial_eq! { ScriptOrModule for ScriptOrModule use identity } + /// A single JavaScript stack frame. #[repr(C)] pub struct StackFrame(Opaque); +impl_eq! { for StackFrame } +impl_partial_eq! { StackFrame for StackFrame use identity } + /// Representation of a JavaScript stack trace. The information collected is a /// snapshot of the execution stack and the information remains valid after /// execution continues. #[repr(C)] pub struct StackTrace(Opaque); +impl_eq! { for StackTrace } +impl_partial_eq! { StackTrace for StackTrace use identity } + /// A compiled JavaScript script, not yet tied to a Context. #[repr(C)] pub struct UnboundScript(Opaque); + +impl_eq! { for UnboundScript } +impl_partial_eq! { UnboundScript for UnboundScript use identity } diff --git a/tests/test_api.rs b/tests/test_api.rs index 3d93f0cf..df443135 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -244,8 +244,8 @@ fn context_scope() { let mut cs = v8::ContextScope::new(scope, context); let scope = cs.enter(); - scope.get_current_context().unwrap(); - scope.get_entered_or_microtask_context().unwrap(); + assert!(scope.get_current_context().unwrap() == context); + assert!(scope.get_entered_or_microtask_context().unwrap() == context); } assert!(scope.get_current_context().is_none()); @@ -1980,6 +1980,7 @@ fn shared_array_buffer() { #[test] #[allow(clippy::cognitive_complexity)] +#[allow(clippy::eq_op)] fn value_checker() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); @@ -1995,41 +1996,88 @@ fn value_checker() { let value = eval(scope, context, "undefined").unwrap(); assert!(value.is_undefined()); assert!(value.is_null_or_undefined()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::undefined(scope)); + assert!(value != v8::null(scope)); + assert!(value != v8::Boolean::new(scope, false)); + assert!(value != v8::Integer::new(scope, 0)); let value = eval(scope, context, "null").unwrap(); assert!(value.is_null()); assert!(value.is_null_or_undefined()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::null(scope)); + assert!(value != v8::undefined(scope)); + assert!(value != v8::Boolean::new(scope, false)); + assert!(value != v8::Integer::new(scope, 0)); let value = eval(scope, context, "true").unwrap(); assert!(value.is_boolean()); assert!(value.is_true()); assert!(!value.is_false()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::Boolean::new(scope, true)); + assert!(value != v8::Boolean::new(scope, false)); let value = eval(scope, context, "false").unwrap(); assert!(value.is_boolean()); assert!(!value.is_true()); assert!(value.is_false()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::Boolean::new(scope, false)); + assert!(value != v8::Boolean::new(scope, true)); + assert!(value != v8::null(scope)); + assert!(value != v8::undefined(scope)); + assert!(value != v8::Integer::new(scope, 0)); let value = eval(scope, context, "'name'").unwrap(); assert!(value.is_name()); assert!(value.is_string()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::String::new(scope, "name").unwrap()); + assert!(value != v8::String::new(scope, "name\0").unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "Symbol()").unwrap(); assert!(value.is_name()); assert!(value.is_symbol()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::Global::new_from(scope, value).get(scope).unwrap()); + assert!(value != eval(scope, context, "Symbol()").unwrap()); let value = eval(scope, context, "() => 0").unwrap(); assert!(value.is_function()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::Global::new_from(scope, value).get(scope).unwrap()); + assert!(value != eval(scope, context, "() => 0").unwrap()); let value = eval(scope, context, "async () => 0").unwrap(); assert!(value.is_async_function()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::Global::new_from(scope, value).get(scope).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "[]").unwrap(); assert!(value.is_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Array::new(scope, 0)); - let value = eval(scope, context, "BigInt('9007199254740995')").unwrap(); + let value = eval(scope, context, "9007199254740995n").unwrap(); assert!(value.is_big_int()); assert!(value.to_big_int(scope).is_some()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == eval(scope, context, "1801439850948199n * 5n").unwrap()); + assert!(value != eval(scope, context, "1801439850948199 * 5").unwrap()); let detail_string = value.to_detail_string(scope).unwrap(); let detail_string = detail_string.to_rust_string_lossy(scope); assert_eq!("9007199254740995", detail_string); @@ -2038,6 +2086,12 @@ fn value_checker() { assert!(value.is_number()); assert!(value.is_int32()); assert!(value.is_uint32()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::Integer::new(scope, 123)); + assert!(value == v8::Number::new(scope, 123f64)); + assert!(value == value.to_int32(scope).unwrap()); + assert!(value != value.to_string(scope).unwrap()); assert_eq!(123, value.to_uint32(scope).unwrap().value()); assert_eq!(123, value.to_int32(scope).unwrap().value()); assert_eq!(123, value.to_integer(scope).unwrap().value()); @@ -2046,107 +2100,218 @@ fn value_checker() { assert_eq!(123, value.int32_value(scope).unwrap()); let value = eval(scope, context, "12.3").unwrap(); + assert!(value.is_number()); + assert!(!value.is_int32()); + assert!(!value.is_uint32()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::Number::new(scope, 12.3f64)); + assert!(value != value.to_integer(scope).unwrap()); assert!(12.3 - value.number_value(scope).unwrap() < 0.00001); let value = eval(scope, context, "-123").unwrap(); assert!(value.is_number()); + assert!(value.is_int32()); assert!(!value.is_uint32()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::Integer::new(scope, -123)); + assert!(value == v8::Number::new(scope, -123f64)); + assert!(value != v8::String::new(scope, "-123").unwrap()); + assert!( + value + == v8::Integer::new_from_unsigned(scope, -123i32 as u32) + .to_int32(scope) + .unwrap() + ); + // The following test does not pass. This appears to be a V8 bug. + // assert!(value != value.to_uint32(scope).unwrap()); + + let value = eval(scope, context, "NaN").unwrap(); + assert!(value.is_number()); + assert!(!value.is_int32()); + assert!(!value.is_uint32()); + assert!(value != value); + assert!( + value.to_string(scope).unwrap() == v8::String::new(scope, "NaN").unwrap() + ); + + let value = eval(scope, context, "({})").unwrap(); + assert!(value.is_object()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value == v8::Global::new_from(scope, value).get(scope).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Date()").unwrap(); assert!(value.is_date()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != eval(scope, context, "new Date()").unwrap()); let value = eval(scope, context, "(function(){return arguments})()").unwrap(); assert!(value.is_arguments_object()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Promise(function(){})").unwrap(); assert!(value.is_promise()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Map()").unwrap(); assert!(value.is_map()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Set").unwrap(); assert!(value.is_set()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Map().entries()").unwrap(); assert!(value.is_map_iterator()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Set().entries()").unwrap(); assert!(value.is_set_iterator()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new WeakMap()").unwrap(); assert!(value.is_weak_map()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new WeakSet()").unwrap(); assert!(value.is_weak_set()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new ArrayBuffer(8)").unwrap(); assert!(value.is_array_buffer()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Uint8Array([])").unwrap(); assert!(value.is_uint8_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Uint8ClampedArray([])").unwrap(); assert!(value.is_uint8_clamped_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!( + value == v8::Local::::try_from(value).unwrap() + ); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Int8Array([])").unwrap(); assert!(value.is_int8_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Uint16Array([])").unwrap(); assert!(value.is_uint16_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Int16Array([])").unwrap(); assert!(value.is_int16_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Uint32Array([])").unwrap(); assert!(value.is_uint32_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Int32Array([])").unwrap(); assert!(value.is_int32_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Float32Array([])").unwrap(); assert!(value.is_float32_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Float64Array([])").unwrap(); assert!(value.is_float64_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new BigInt64Array([])").unwrap(); assert!(value.is_big_int64_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new BigUint64Array([])").unwrap(); assert!(value.is_big_uint64_array()); assert!(value.is_array_buffer_view()); assert!(value.is_typed_array()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new SharedArrayBuffer(64)").unwrap(); assert!(value.is_shared_array_buffer()); + assert!(value == value); + assert!( + value == v8::Local::::try_from(value).unwrap() + ); + assert!(value != v8::Object::new(scope)); let value = eval(scope, context, "new Proxy({},{})").unwrap(); assert!(value.is_proxy()); + assert!(value == value); + assert!(value == v8::Local::::try_from(value).unwrap()); + assert!(value != v8::Object::new(scope)); // Other checker, Just check if it can be called value.is_external(); value.is_module_namespace_object(); + value.is_wasm_module_object(); } }