Skip to main content

v8/
value.rs

1use crate::BigInt;
2use crate::Boolean;
3use crate::Context;
4use crate::Int32;
5use crate::Integer;
6use crate::Local;
7use crate::Number;
8use crate::Object;
9use crate::PinScope;
10use crate::String;
11use crate::Uint32;
12use crate::Value;
13use crate::isolate::RealIsolate;
14use crate::scope::GetIsolate;
15use crate::support::Maybe;
16
17unsafe extern "C" {
18  fn v8__Value__IsUndefined(this: *const Value) -> bool;
19  fn v8__Value__IsNull(this: *const Value) -> bool;
20  fn v8__Value__IsNullOrUndefined(this: *const Value) -> bool;
21  fn v8__Value__IsTrue(this: *const Value) -> bool;
22  fn v8__Value__IsFalse(this: *const Value) -> bool;
23  fn v8__Value__IsName(this: *const Value) -> bool;
24  fn v8__Value__IsString(this: *const Value) -> bool;
25  fn v8__Value__IsSymbol(this: *const Value) -> bool;
26  fn v8__Value__IsFunction(this: *const Value) -> bool;
27  fn v8__Value__IsArray(this: *const Value) -> bool;
28  fn v8__Value__IsObject(this: *const Value) -> bool;
29  fn v8__Value__IsBigInt(this: *const Value) -> bool;
30  fn v8__Value__IsBoolean(this: *const Value) -> bool;
31  fn v8__Value__IsNumber(this: *const Value) -> bool;
32  fn v8__Value__IsExternal(this: *const Value) -> bool;
33  fn v8__Value__IsInt32(this: *const Value) -> bool;
34  fn v8__Value__IsUint32(this: *const Value) -> bool;
35  fn v8__Value__IsDate(this: *const Value) -> bool;
36  fn v8__Value__IsArgumentsObject(this: *const Value) -> bool;
37  fn v8__Value__IsBigIntObject(this: *const Value) -> bool;
38  fn v8__Value__IsBooleanObject(this: *const Value) -> bool;
39  fn v8__Value__IsNumberObject(this: *const Value) -> bool;
40  fn v8__Value__IsStringObject(this: *const Value) -> bool;
41  fn v8__Value__IsSymbolObject(this: *const Value) -> bool;
42  fn v8__Value__IsNativeError(this: *const Value) -> bool;
43  fn v8__Value__IsRegExp(this: *const Value) -> bool;
44  fn v8__Value__IsAsyncFunction(this: *const Value) -> bool;
45  fn v8__Value__IsGeneratorFunction(this: *const Value) -> bool;
46  #[allow(dead_code)]
47  fn v8__Value__IsGeneratorObject(this: *const Value) -> bool;
48  fn v8__Value__IsPromise(this: *const Value) -> bool;
49  fn v8__Value__IsMap(this: *const Value) -> bool;
50  fn v8__Value__IsSet(this: *const Value) -> bool;
51  fn v8__Value__IsMapIterator(this: *const Value) -> bool;
52  fn v8__Value__IsSetIterator(this: *const Value) -> bool;
53  fn v8__Value__IsSetGeneratorObject(this: *const Value) -> bool;
54  fn v8__Value__IsWeakMap(this: *const Value) -> bool;
55  fn v8__Value__IsWeakSet(this: *const Value) -> bool;
56  fn v8__Value__IsArrayBuffer(this: *const Value) -> bool;
57  fn v8__Value__IsArrayBufferView(this: *const Value) -> bool;
58  fn v8__Value__IsTypedArray(this: *const Value) -> bool;
59  fn v8__Value__IsUint8Array(this: *const Value) -> bool;
60  fn v8__Value__IsUint8ClampedArray(this: *const Value) -> bool;
61  fn v8__Value__IsInt8Array(this: *const Value) -> bool;
62  fn v8__Value__IsUint16Array(this: *const Value) -> bool;
63  fn v8__Value__IsInt16Array(this: *const Value) -> bool;
64  fn v8__Value__IsUint32Array(this: *const Value) -> bool;
65  fn v8__Value__IsInt32Array(this: *const Value) -> bool;
66  fn v8__Value__IsFloat16Array(this: *const Value) -> bool;
67  fn v8__Value__IsFloat32Array(this: *const Value) -> bool;
68  fn v8__Value__IsFloat64Array(this: *const Value) -> bool;
69  fn v8__Value__IsBigInt64Array(this: *const Value) -> bool;
70  fn v8__Value__IsBigUint64Array(this: *const Value) -> bool;
71  fn v8__Value__IsDataView(this: *const Value) -> bool;
72  fn v8__Value__IsSharedArrayBuffer(this: *const Value) -> bool;
73  fn v8__Value__IsProxy(this: *const Value) -> bool;
74  fn v8__Value__IsWasmMemoryObject(this: *const Value) -> bool;
75  fn v8__Value__IsWasmModuleObject(this: *const Value) -> bool;
76  fn v8__Value__IsModuleNamespaceObject(this: *const Value) -> bool;
77  fn v8__Value__StrictEquals(this: *const Value, that: *const Value) -> bool;
78  fn v8__Value__SameValue(this: *const Value, that: *const Value) -> bool;
79  fn v8__Value__InstanceOf(
80    this: *const Value,
81    context: *const Context,
82    object: *const Object,
83    out: *mut Maybe<bool>,
84  );
85  fn v8__Value__ToBigInt(
86    this: *const Value,
87    context: *const Context,
88  ) -> *const BigInt;
89  fn v8__Value__ToNumber(
90    this: *const Value,
91    context: *const Context,
92  ) -> *const Number;
93  fn v8__Value__ToString(
94    this: *const Value,
95    context: *const Context,
96  ) -> *const String;
97  fn v8__Value__ToDetailString(
98    this: *const Value,
99    context: *const Context,
100  ) -> *const String;
101  fn v8__Value__ToObject(
102    this: *const Value,
103    context: *const Context,
104  ) -> *const Object;
105  fn v8__Value__ToInteger(
106    this: *const Value,
107    context: *const Context,
108  ) -> *const Integer;
109  fn v8__Value__ToUint32(
110    this: *const Value,
111    context: *const Context,
112  ) -> *const Uint32;
113  fn v8__Value__ToInt32(
114    this: *const Value,
115    context: *const Context,
116  ) -> *const Int32;
117  fn v8__Value__ToBoolean(
118    this: *const Value,
119    isolate: *mut RealIsolate,
120  ) -> *const Boolean;
121
122  fn v8__Value__NumberValue(
123    this: *const Value,
124    context: *const Context,
125    out: *mut Maybe<f64>,
126  );
127  fn v8__Value__IntegerValue(
128    this: *const Value,
129    context: *const Context,
130    out: *mut Maybe<i64>,
131  );
132  fn v8__Value__Uint32Value(
133    this: *const Value,
134    context: *const Context,
135    out: *mut Maybe<u32>,
136  );
137  fn v8__Value__Int32Value(
138    this: *const Value,
139    context: *const Context,
140    out: *mut Maybe<i32>,
141  );
142  fn v8__Value__BooleanValue(
143    this: *const Value,
144    isolate: *mut RealIsolate,
145  ) -> bool;
146  fn v8__Value__GetHash(this: *const Value) -> u32;
147  fn v8__Value__TypeOf(
148    this: *const Value,
149    isolate: *mut RealIsolate,
150  ) -> *const String;
151}
152
153impl Value {
154  /// Returns true if this value is the undefined value.  See ECMA-262 4.3.10.
155  #[inline(always)]
156  pub fn is_undefined(&self) -> bool {
157    unsafe { v8__Value__IsUndefined(self) }
158  }
159
160  /// Returns true if this value is the null value.  See ECMA-262 4.3.11.
161  #[inline(always)]
162  pub fn is_null(&self) -> bool {
163    unsafe { v8__Value__IsNull(self) }
164  }
165
166  /// Returns true if this value is either the null or the undefined value.
167  /// See ECMA-262 4.3.11. and 4.3.12
168  #[inline(always)]
169  pub fn is_null_or_undefined(&self) -> bool {
170    unsafe { v8__Value__IsNullOrUndefined(self) }
171  }
172
173  /// Returns true if this value is true.
174  /// This is not the same as `BooleanValue()`. The latter performs a
175  /// conversion to boolean, i.e. the result of `Boolean(value)` in JS, whereas
176  /// this checks `value === true`.
177  #[inline(always)]
178  pub fn is_true(&self) -> bool {
179    unsafe { v8__Value__IsTrue(self) }
180  }
181
182  /// Returns true if this value is false.
183  /// This is not the same as `!BooleanValue()`. The latter performs a
184  /// conversion to boolean, i.e. the result of `!Boolean(value)` in JS, whereas
185  /// this checks `value === false`.
186  #[inline(always)]
187  pub fn is_false(&self) -> bool {
188    unsafe { v8__Value__IsFalse(self) }
189  }
190
191  /// Returns true if this value is a symbol or a string.
192  /// This is equivalent to
193  /// `typeof value === 'string' || typeof value === 'symbol'` in JS.
194  #[inline(always)]
195  pub fn is_name(&self) -> bool {
196    unsafe { v8__Value__IsName(self) }
197  }
198
199  /// Returns true if this value is an instance of the String type.
200  /// See ECMA-262 8.4.
201  #[inline(always)]
202  pub fn is_string(&self) -> bool {
203    unsafe { v8__Value__IsString(self) }
204  }
205
206  /// Returns true if this value is a symbol.
207  /// This is equivalent to `typeof value === 'symbol'` in JS.
208  #[inline(always)]
209  pub fn is_symbol(&self) -> bool {
210    unsafe { v8__Value__IsSymbol(self) }
211  }
212
213  /// Returns true if this value is a function.
214  #[inline(always)]
215  pub fn is_function(&self) -> bool {
216    unsafe { v8__Value__IsFunction(self) }
217  }
218
219  /// Returns true if this value is an array. Note that it will return false for
220  /// an Proxy for an array.
221  #[inline(always)]
222  pub fn is_array(&self) -> bool {
223    unsafe { v8__Value__IsArray(self) }
224  }
225
226  /// Returns true if this value is an object.
227  #[inline(always)]
228  pub fn is_object(&self) -> bool {
229    unsafe { v8__Value__IsObject(self) }
230  }
231
232  /// Returns true if this value is a bigint.
233  /// This is equivalent to `typeof value === 'bigint'` in JS.
234  #[inline(always)]
235  pub fn is_big_int(&self) -> bool {
236    unsafe { v8__Value__IsBigInt(self) }
237  }
238
239  /// Returns true if this value is boolean.
240  /// This is equivalent to `typeof value === 'boolean'` in JS.
241  #[inline(always)]
242  pub fn is_boolean(&self) -> bool {
243    unsafe { v8__Value__IsBoolean(self) }
244  }
245
246  /// Returns true if this value is a number.
247  #[inline(always)]
248  pub fn is_number(&self) -> bool {
249    unsafe { v8__Value__IsNumber(self) }
250  }
251
252  /// Returns true if this value is an `External` object.
253  #[inline(always)]
254  pub fn is_external(&self) -> bool {
255    unsafe { v8__Value__IsExternal(self) }
256  }
257
258  /// Returns true if this value is a 32-bit signed integer.
259  #[inline(always)]
260  pub fn is_int32(&self) -> bool {
261    unsafe { v8__Value__IsInt32(self) }
262  }
263
264  /// Returns true if this value is a 32-bit unsigned integer.
265  #[inline(always)]
266  pub fn is_uint32(&self) -> bool {
267    unsafe { v8__Value__IsUint32(self) }
268  }
269
270  /// Returns true if this value is a Date.
271  #[inline(always)]
272  pub fn is_date(&self) -> bool {
273    unsafe { v8__Value__IsDate(self) }
274  }
275
276  /// Returns true if this value is an Arguments object.
277  #[inline(always)]
278  pub fn is_arguments_object(&self) -> bool {
279    unsafe { v8__Value__IsArgumentsObject(self) }
280  }
281
282  /// Returns true if this value is a BigInt object.
283  #[inline(always)]
284  pub fn is_big_int_object(&self) -> bool {
285    unsafe { v8__Value__IsBigIntObject(self) }
286  }
287
288  /// Returns true if this value is a Boolean object.
289  #[inline(always)]
290  pub fn is_boolean_object(&self) -> bool {
291    unsafe { v8__Value__IsBooleanObject(self) }
292  }
293
294  /// Returns true if this value is a Number object.
295  #[inline(always)]
296  pub fn is_number_object(&self) -> bool {
297    unsafe { v8__Value__IsNumberObject(self) }
298  }
299
300  /// Returns true if this value is a String object.
301  #[inline(always)]
302  pub fn is_string_object(&self) -> bool {
303    unsafe { v8__Value__IsStringObject(self) }
304  }
305
306  /// Returns true if this value is a Symbol object.
307  #[inline(always)]
308  pub fn is_symbol_object(&self) -> bool {
309    unsafe { v8__Value__IsSymbolObject(self) }
310  }
311
312  /// Returns true if this value is a NativeError.
313  #[inline(always)]
314  pub fn is_native_error(&self) -> bool {
315    unsafe { v8__Value__IsNativeError(self) }
316  }
317
318  /// Returns true if this value is a RegExp.
319  #[inline(always)]
320  pub fn is_reg_exp(&self) -> bool {
321    unsafe { v8__Value__IsRegExp(self) }
322  }
323
324  /// Returns true if this value is an async function.
325  #[inline(always)]
326  pub fn is_async_function(&self) -> bool {
327    unsafe { v8__Value__IsAsyncFunction(self) }
328  }
329
330  /// Returns true if this value is a Generator function.
331  #[inline(always)]
332  pub fn is_generator_function(&self) -> bool {
333    unsafe { v8__Value__IsGeneratorFunction(self) }
334  }
335
336  /// Returns true if this value is a Promise.
337  #[inline(always)]
338  pub fn is_promise(&self) -> bool {
339    unsafe { v8__Value__IsPromise(self) }
340  }
341
342  /// Returns true if this value is a Map.
343  #[inline(always)]
344  pub fn is_map(&self) -> bool {
345    unsafe { v8__Value__IsMap(self) }
346  }
347
348  /// Returns true if this value is a Set.
349  #[inline(always)]
350  pub fn is_set(&self) -> bool {
351    unsafe { v8__Value__IsSet(self) }
352  }
353
354  /// Returns true if this value is a Map Iterator.
355  #[inline(always)]
356  pub fn is_map_iterator(&self) -> bool {
357    unsafe { v8__Value__IsMapIterator(self) }
358  }
359
360  /// Returns true if this value is a Set Iterator.
361  #[inline(always)]
362  pub fn is_set_iterator(&self) -> bool {
363    unsafe { v8__Value__IsSetIterator(self) }
364  }
365
366  /// Returns true if this value is a Generator Object.
367  #[inline(always)]
368  pub fn is_generator_object(&self) -> bool {
369    unsafe { v8__Value__IsSetGeneratorObject(self) }
370  }
371
372  /// Returns true if this value is a WeakMap.
373  #[inline(always)]
374  pub fn is_weak_map(&self) -> bool {
375    unsafe { v8__Value__IsWeakMap(self) }
376  }
377
378  /// Returns true if this value is a WeakSet.
379  #[inline(always)]
380  pub fn is_weak_set(&self) -> bool {
381    unsafe { v8__Value__IsWeakSet(self) }
382  }
383
384  /// Returns true if this value is an ArrayBuffer.
385  #[inline(always)]
386  pub fn is_array_buffer(&self) -> bool {
387    unsafe { v8__Value__IsArrayBuffer(self) }
388  }
389
390  /// Returns true if this value is an ArrayBufferView.
391  #[inline(always)]
392  pub fn is_array_buffer_view(&self) -> bool {
393    unsafe { v8__Value__IsArrayBufferView(self) }
394  }
395
396  /// Returns true if this value is one of TypedArrays.
397  #[inline(always)]
398  pub fn is_typed_array(&self) -> bool {
399    unsafe { v8__Value__IsTypedArray(self) }
400  }
401
402  /// Returns true if this value is an Uint8Array.
403  #[inline(always)]
404  pub fn is_uint8_array(&self) -> bool {
405    unsafe { v8__Value__IsUint8Array(self) }
406  }
407
408  /// Returns true if this value is an Uint8ClampedArray.
409  #[inline(always)]
410  pub fn is_uint8_clamped_array(&self) -> bool {
411    unsafe { v8__Value__IsUint8ClampedArray(self) }
412  }
413
414  /// Returns true if this value is an Int8Array.
415  #[inline(always)]
416  pub fn is_int8_array(&self) -> bool {
417    unsafe { v8__Value__IsInt8Array(self) }
418  }
419
420  /// Returns true if this value is an Uint16Array.
421  #[inline(always)]
422  pub fn is_uint16_array(&self) -> bool {
423    unsafe { v8__Value__IsUint16Array(self) }
424  }
425
426  /// Returns true if this value is an Int16Array.
427  #[inline(always)]
428  pub fn is_int16_array(&self) -> bool {
429    unsafe { v8__Value__IsInt16Array(self) }
430  }
431
432  /// Returns true if this value is an Uint32Array.
433  #[inline(always)]
434  pub fn is_uint32_array(&self) -> bool {
435    unsafe { v8__Value__IsUint32Array(self) }
436  }
437
438  /// Returns true if this value is an Int32Array.
439  #[inline(always)]
440  pub fn is_int32_array(&self) -> bool {
441    unsafe { v8__Value__IsInt32Array(self) }
442  }
443
444  /// Returns true if this value is a Float16Array.
445  #[inline(always)]
446  pub fn is_float16_array(&self) -> bool {
447    unsafe { v8__Value__IsFloat16Array(self) }
448  }
449
450  /// Returns true if this value is a Float32Array.
451  #[inline(always)]
452  pub fn is_float32_array(&self) -> bool {
453    unsafe { v8__Value__IsFloat32Array(self) }
454  }
455
456  /// Returns true if this value is a Float64Array.
457  #[inline(always)]
458  pub fn is_float64_array(&self) -> bool {
459    unsafe { v8__Value__IsFloat64Array(self) }
460  }
461
462  /// Returns true if this value is a BigInt64Array.
463  #[inline(always)]
464  pub fn is_big_int64_array(&self) -> bool {
465    unsafe { v8__Value__IsBigInt64Array(self) }
466  }
467
468  /// Returns true if this value is a BigUint64Array.
469  #[inline(always)]
470  pub fn is_big_uint64_array(&self) -> bool {
471    unsafe { v8__Value__IsBigUint64Array(self) }
472  }
473
474  /// Returns true if this value is a DataView.
475  #[inline(always)]
476  pub fn is_data_view(&self) -> bool {
477    unsafe { v8__Value__IsDataView(self) }
478  }
479
480  /// Returns true if this value is a SharedArrayBuffer.
481  /// This is an experimental feature.
482  #[inline(always)]
483  pub fn is_shared_array_buffer(&self) -> bool {
484    unsafe { v8__Value__IsSharedArrayBuffer(self) }
485  }
486
487  /// Returns true if this value is a JavaScript Proxy.
488  #[inline(always)]
489  pub fn is_proxy(&self) -> bool {
490    unsafe { v8__Value__IsProxy(self) }
491  }
492
493  /// Returns true if this value is a WasmMemoryObject.
494  #[inline(always)]
495  pub fn is_wasm_memory_object(&self) -> bool {
496    unsafe { v8__Value__IsWasmMemoryObject(self) }
497  }
498
499  /// Returns true if this value is a WasmModuleObject.
500  #[inline(always)]
501  pub fn is_wasm_module_object(&self) -> bool {
502    unsafe { v8__Value__IsWasmModuleObject(self) }
503  }
504
505  /// Returns true if the value is a Module Namespace Object.
506  #[inline(always)]
507  pub fn is_module_namespace_object(&self) -> bool {
508    unsafe { v8__Value__IsModuleNamespaceObject(self) }
509  }
510
511  #[inline(always)]
512  pub fn strict_equals(&self, that: Local<Value>) -> bool {
513    unsafe { v8__Value__StrictEquals(self, &*that) }
514  }
515
516  #[inline(always)]
517  pub fn same_value(&self, that: Local<Value>) -> bool {
518    unsafe { v8__Value__SameValue(self, &*that) }
519  }
520
521  /// Implements the the abstract operation `SameValueZero`, which is defined in
522  /// ECMA-262 6th edition ยง 7.2.10
523  /// (http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero).
524  ///
525  /// This operation is used to compare values for the purpose of insertion into
526  /// a `Set`, or determining whether `Map` keys are equivalent. Its semantics
527  /// are almost the same as `strict_equals()` and `same_value()`, with the
528  /// following important distinctions:
529  ///   - It considers `NaN` equal to `NaN` (unlike `strict_equals()`).
530  ///   - It considers `-0` equal to `0` (unlike `same_value()`).
531  #[inline(always)]
532  pub fn same_value_zero(&self, that: Local<Value>) -> bool {
533    // The SMI representation of zero is also zero. In debug builds, double
534    // check this, so in the unlikely event that V8 changes its internal
535    // representation of SMIs such that this invariant no longer holds, we'd
536    // catch it.
537    self.same_value(that) || {
538      let zero = Integer::zero().into();
539      self.strict_equals(zero) && that.strict_equals(zero)
540    }
541  }
542
543  #[inline(always)]
544  pub fn to_big_int<'s>(
545    &self,
546    scope: &PinScope<'s, '_>,
547  ) -> Option<Local<'s, BigInt>> {
548    unsafe {
549      scope
550        .cast_local(|sd| v8__Value__ToBigInt(self, &*sd.get_current_context()))
551    }
552  }
553
554  #[inline(always)]
555  pub fn to_number<'s>(
556    &self,
557    scope: &PinScope<'s, '_>,
558  ) -> Option<Local<'s, Number>> {
559    unsafe {
560      scope
561        .cast_local(|sd| v8__Value__ToNumber(self, &*sd.get_current_context()))
562    }
563  }
564
565  #[inline(always)]
566  pub fn to_string<'s>(
567    &self,
568    scope: &PinScope<'s, '_>,
569  ) -> Option<Local<'s, String>> {
570    unsafe {
571      scope
572        .cast_local(|sd| v8__Value__ToString(self, &*sd.get_current_context()))
573    }
574  }
575
576  /// Convenience function not present in the original V8 API.
577  #[inline(always)]
578  pub fn to_rust_string_lossy(
579    &self,
580    scope: &PinScope<'_, '_>,
581  ) -> std::string::String {
582    self
583      .to_string(scope)
584      .map_or_else(std::string::String::new, |s| s.to_rust_string_lossy(scope))
585  }
586
587  #[inline(always)]
588  pub fn to_detail_string<'s>(
589    &self,
590    scope: &PinScope<'s, '_>,
591  ) -> Option<Local<'s, String>> {
592    unsafe {
593      scope.cast_local(|sd| {
594        v8__Value__ToDetailString(self, &*sd.get_current_context())
595      })
596    }
597  }
598
599  #[inline(always)]
600  pub fn to_object<'s>(
601    &self,
602    scope: &PinScope<'s, '_>,
603  ) -> Option<Local<'s, Object>> {
604    unsafe {
605      scope
606        .cast_local(|sd| v8__Value__ToObject(self, &*sd.get_current_context()))
607    }
608  }
609
610  #[inline(always)]
611  pub fn to_integer<'s>(
612    &self,
613    scope: &PinScope<'s, '_>,
614  ) -> Option<Local<'s, Integer>> {
615    unsafe {
616      scope
617        .cast_local(|sd| v8__Value__ToInteger(self, &*sd.get_current_context()))
618    }
619  }
620
621  #[inline(always)]
622  pub fn to_uint32<'s>(
623    &self,
624    scope: &PinScope<'s, '_>,
625  ) -> Option<Local<'s, Uint32>> {
626    unsafe {
627      scope
628        .cast_local(|sd| v8__Value__ToUint32(self, &*sd.get_current_context()))
629    }
630  }
631
632  #[inline(always)]
633  pub fn to_int32<'s>(
634    &self,
635    scope: &PinScope<'s, '_>,
636  ) -> Option<Local<'s, Int32>> {
637    unsafe {
638      scope
639        .cast_local(|sd| v8__Value__ToInt32(self, &*sd.get_current_context()))
640    }
641  }
642
643  /// Perform the equivalent of Boolean(value) in JS. This can never fail.
644  #[inline(always)]
645  pub fn to_boolean<'s>(&self, scope: &PinScope<'s, '_>) -> Local<'s, Boolean> {
646    unsafe {
647      scope.cast_local(|sd| v8__Value__ToBoolean(self, sd.get_isolate_ptr()))
648    }
649    .unwrap()
650  }
651
652  #[inline(always)]
653  pub fn instance_of(
654    &self,
655    scope: &PinScope<'_, '_>,
656    object: Local<Object>,
657  ) -> Option<bool> {
658    let mut out = Maybe::<bool>::default();
659    unsafe {
660      v8__Value__InstanceOf(
661        self,
662        &*scope.get_current_context(),
663        &*object,
664        &mut out,
665      );
666    }
667    out.into()
668  }
669
670  #[inline(always)]
671  pub fn number_value(&self, scope: &PinScope<'_, '_>) -> Option<f64> {
672    let mut out = Maybe::<f64>::default();
673    unsafe {
674      v8__Value__NumberValue(self, &*scope.get_current_context(), &mut out);
675    };
676    out.into()
677  }
678
679  #[inline(always)]
680  pub fn integer_value(&self, scope: &PinScope<'_, '_>) -> Option<i64> {
681    let mut out = Maybe::<i64>::default();
682    unsafe {
683      v8__Value__IntegerValue(self, &*scope.get_current_context(), &mut out);
684    };
685    out.into()
686  }
687
688  #[inline(always)]
689  pub fn uint32_value(&self, scope: &PinScope<'_, '_>) -> Option<u32> {
690    let mut out = Maybe::<u32>::default();
691    unsafe {
692      v8__Value__Uint32Value(self, &*scope.get_current_context(), &mut out);
693    };
694    out.into()
695  }
696
697  #[inline(always)]
698  pub fn int32_value(&self, scope: &PinScope<'_, '_>) -> Option<i32> {
699    let mut out = Maybe::<i32>::default();
700    unsafe {
701      v8__Value__Int32Value(self, &*scope.get_current_context(), &mut out);
702    };
703    out.into()
704  }
705
706  #[inline(always)]
707  pub fn boolean_value(&self, scope: &PinScope<'_, '_>) -> bool {
708    unsafe { v8__Value__BooleanValue(self, scope.get_isolate_ptr()) }
709  }
710
711  /// Get the hash of this value. The hash is not guaranteed to be
712  /// unique. For |Object| and |Name| instances the result is equal to
713  /// |GetIdentityHash|. Hashes are not guaranteed to be stable across
714  /// different isolates or processes.
715  #[inline(always)]
716  pub fn get_hash(&self) -> u32 {
717    unsafe { v8__Value__GetHash(self) }
718  }
719
720  #[inline(always)]
721  pub fn type_of<'s>(&self, scope: &PinScope<'s, '_>) -> Local<'s, String> {
722    unsafe {
723      scope.cast_local(|sd| v8__Value__TypeOf(self, sd.get_isolate_ptr()))
724    }
725    .unwrap()
726  }
727
728  /// Utility method that returns human readable representation of the
729  /// underlying value.
730  pub fn type_repr(&self) -> &'static str {
731    if self.is_module_namespace_object() {
732      "Module"
733    } else if self.is_wasm_module_object() {
734      "WASM module"
735    } else if self.is_wasm_memory_object() {
736      "WASM memory object"
737    } else if self.is_proxy() {
738      "Proxy"
739    } else if self.is_shared_array_buffer() {
740      "SharedArrayBuffer"
741    } else if self.is_data_view() {
742      "DataView"
743    } else if self.is_big_uint64_array() {
744      "BigUint64Array"
745    } else if self.is_big_int64_array() {
746      "BigInt64Array"
747    } else if self.is_float64_array() {
748      "Float64Array"
749    } else if self.is_float32_array() {
750      "Float32Array"
751    } else if self.is_int32_array() {
752      "Int32Array"
753    } else if self.is_uint32_array() {
754      "Uint32Array"
755    } else if self.is_int16_array() {
756      "Int16Array"
757    } else if self.is_uint16_array() {
758      "Uint16Array"
759    } else if self.is_int8_array() {
760      "Int8Array"
761    } else if self.is_uint8_clamped_array() {
762      "Uint8ClampedArray"
763    } else if self.is_uint8_array() {
764      "Uint8Array"
765    } else if self.is_typed_array() {
766      "TypedArray"
767    } else if self.is_array_buffer_view() {
768      "ArrayBufferView"
769    } else if self.is_array_buffer() {
770      "ArrayBuffer"
771    } else if self.is_weak_set() {
772      "WeakSet"
773    } else if self.is_weak_map() {
774      "WeakMap"
775    } else if self.is_set_iterator() {
776      "Set Iterator"
777    } else if self.is_map_iterator() {
778      "Map Iterator"
779    } else if self.is_set() {
780      "Set"
781    } else if self.is_map() {
782      "Map"
783    } else if self.is_promise() {
784      "Promise"
785    } else if self.is_generator_function() {
786      "Generator function"
787    } else if self.is_async_function() {
788      "Async function"
789    } else if self.is_reg_exp() {
790      "RegExp"
791    } else if self.is_date() {
792      "Date"
793    } else if self.is_number() {
794      "Number"
795    } else if self.is_boolean() {
796      "Boolean"
797    } else if self.is_big_int() {
798      "bigint"
799    } else if self.is_array() {
800      "array"
801    } else if self.is_function() {
802      "function"
803    } else if self.is_symbol() {
804      "symbol"
805    } else if self.is_string() {
806      "string"
807    } else if self.is_null() {
808      "null"
809    } else if self.is_undefined() {
810      "undefined"
811    } else {
812      "unknown"
813    }
814  }
815}