rusty_v8/
data.rs

1// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
2
3use std::any::type_name;
4use std::convert::From;
5use std::convert::TryFrom;
6use std::error::Error;
7use std::fmt;
8use std::fmt::Display;
9use std::fmt::Formatter;
10use std::hash::Hash;
11use std::hash::Hasher;
12use std::mem::transmute;
13use std::ops::Deref;
14
15use crate::support::int;
16use crate::support::Opaque;
17use crate::Local;
18
19extern "C" {
20  fn v8__Data__EQ(this: *const Data, other: *const Data) -> bool;
21  fn v8__Data__IsValue(this: *const Data) -> bool;
22  fn v8__Data__IsModule(this: *const Data) -> bool;
23  fn v8__Data__IsPrivate(this: *const Data) -> bool;
24  fn v8__Data__IsObjectTemplate(this: *const Data) -> bool;
25  fn v8__Data__IsFunctionTemplate(this: *const Data) -> bool;
26
27  fn v8__internal__Object__GetHash(this: *const Data) -> int;
28
29  fn v8__Value__SameValue(this: *const Value, other: *const Value) -> bool;
30  fn v8__Value__StrictEquals(this: *const Value, other: *const Value) -> bool;
31}
32
33impl Data {
34  /// Returns the V8 hash value for this value. The current implementation
35  /// uses a hidden property to store the identity hash on some object types.
36  ///
37  /// The return value will never be 0. Also, it is not guaranteed to be
38  /// unique.
39  pub fn get_hash(&self) -> int {
40    unsafe { v8__internal__Object__GetHash(self) }
41  }
42
43  /// Returns true if this data is a `Value`.
44  pub fn is_value(&self) -> bool {
45    unsafe { v8__Data__IsValue(self) }
46  }
47
48  /// Returns true if this data is a `Module`.
49  pub fn is_module(&self) -> bool {
50    unsafe { v8__Data__IsModule(self) }
51  }
52
53  /// Returns true if this data is a `Private`.
54  pub fn is_private(&self) -> bool {
55    unsafe { v8__Data__IsPrivate(self) }
56  }
57
58  /// Returns true if this data is an `ObjectTemplate`
59  pub fn is_object_template(&self) -> bool {
60    unsafe { v8__Data__IsObjectTemplate(self) }
61  }
62
63  /// Returns true if this data is a `FunctionTemplate.`
64  pub fn is_function_template(&self) -> bool {
65    unsafe { v8__Data__IsFunctionTemplate(self) }
66  }
67}
68
69macro_rules! impl_deref {
70  { $target:ident for $type:ident } => {
71    impl Deref for $type {
72      type Target = $target;
73      fn deref(&self) -> &Self::Target {
74        unsafe { &*(self as *const _ as *const Self::Target) }
75      }
76    }
77  };
78}
79
80macro_rules! impl_from {
81  { $source:ident for $type:ident } => {
82    impl<'s> From<Local<'s, $source>> for Local<'s, $type> {
83      fn from(l: Local<'s, $source>) -> Self {
84        unsafe { transmute(l) }
85      }
86    }
87  };
88}
89
90macro_rules! impl_try_from {
91  { $source:ident for $target:ident if $value:pat => $check:expr } => {
92    impl<'s> TryFrom<Local<'s, $source>> for Local<'s, $target> {
93      type Error = DataError;
94      fn try_from(l: Local<'s, $source>) -> Result<Self, Self::Error> {
95        match l {
96          $value if $check => Ok(unsafe { transmute(l) }),
97          _ => Err(DataError::bad_type::<$target, $source>())
98        }
99      }
100    }
101  };
102}
103
104macro_rules! impl_eq {
105  { for $type:ident } => {
106    impl Eq for $type {}
107  };
108}
109
110macro_rules! impl_hash {
111  { for $type:ident } => {
112    impl Hash for $type {
113      fn hash<H: Hasher>(&self, state: &mut H) {
114        self.get_hash().hash(state)
115      }
116    }
117  };
118}
119
120macro_rules! impl_partial_eq {
121  { $rhs:ident for $type:ident use identity } => {
122    impl<'s> PartialEq<$rhs> for $type {
123      fn eq(&self, other: &$rhs) -> bool {
124        let a = self as *const _ as *const Data;
125        let b = other as *const _ as *const Data;
126        unsafe { v8__Data__EQ(a, b) }
127      }
128    }
129  };
130  { $rhs:ident for $type:ident use strict_equals } => {
131    impl<'s> PartialEq<$rhs> for $type {
132      fn eq(&self, other: &$rhs) -> bool {
133        let a = self as *const _ as *const Value;
134        let b = other as *const _ as *const Value;
135        unsafe { v8__Value__StrictEquals(a, b) }
136      }
137    }
138  };
139  { $rhs:ident for $type:ident use same_value_zero } => {
140    impl<'s> PartialEq<$rhs> for $type {
141      fn eq(&self, other: &$rhs) -> bool {
142        let a = self as *const _ as *const Value;
143        let b = other as *const _ as *const Value;
144        unsafe {
145          v8__Value__SameValue(a, b) || {
146            let zero = &*Local::<Value>::from(Integer::zero());
147            v8__Value__StrictEquals(a, zero) && v8__Value__StrictEquals(b, zero)
148          }
149        }
150      }
151    }
152  };
153}
154
155#[derive(Clone, Copy, Debug)]
156pub enum DataError {
157  BadType {
158    actual: &'static str,
159    expected: &'static str,
160  },
161  NoData {
162    expected: &'static str,
163  },
164}
165
166impl DataError {
167  pub(crate) fn bad_type<E: 'static, A: 'static>() -> Self {
168    Self::BadType {
169      expected: type_name::<E>(),
170      actual: type_name::<A>(),
171    }
172  }
173
174  pub(crate) fn no_data<E: 'static>() -> Self {
175    Self::NoData {
176      expected: type_name::<E>(),
177    }
178  }
179}
180
181impl Display for DataError {
182  fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
183    match self {
184      Self::BadType { expected, actual } => {
185        write!(f, "expected type `{}`, got `{}`", expected, actual)
186      }
187      Self::NoData { expected } => {
188        write!(f, "expected `Some({})`, found `None`", expected)
189      }
190    }
191  }
192}
193
194impl Error for DataError {}
195
196/// The superclass of objects that can reside on V8's heap.
197#[repr(C)]
198#[derive(Debug)]
199pub struct Data(Opaque);
200
201impl_from! { AccessorSignature for Data }
202impl_from! { Context for Data }
203impl_from! { Message for Data }
204impl_from! { Module for Data }
205impl_from! { ModuleRequest for Data }
206impl_from! { PrimitiveArray for Data }
207impl_from! { Private for Data }
208impl_from! { Script for Data }
209impl_from! { ScriptOrModule for Data }
210impl_from! { Signature for Data }
211impl_from! { StackFrame for Data }
212impl_from! { StackTrace for Data }
213impl_from! { Template for Data }
214impl_from! { FunctionTemplate for Data }
215impl_from! { ObjectTemplate for Data }
216impl_from! { UnboundModuleScript for Data }
217impl_from! { UnboundScript for Data }
218impl_from! { Value for Data }
219impl_from! { External for Data }
220impl_from! { Object for Data }
221impl_from! { Array for Data }
222impl_from! { ArrayBuffer for Data }
223impl_from! { ArrayBufferView for Data }
224impl_from! { DataView for Data }
225impl_from! { TypedArray for Data }
226impl_from! { BigInt64Array for Data }
227impl_from! { BigUint64Array for Data }
228impl_from! { Float32Array for Data }
229impl_from! { Float64Array for Data }
230impl_from! { Int16Array for Data }
231impl_from! { Int32Array for Data }
232impl_from! { Int8Array for Data }
233impl_from! { Uint16Array for Data }
234impl_from! { Uint32Array for Data }
235impl_from! { Uint8Array for Data }
236impl_from! { Uint8ClampedArray for Data }
237impl_from! { BigIntObject for Data }
238impl_from! { BooleanObject for Data }
239impl_from! { Date for Data }
240impl_from! { Function for Data }
241impl_from! { Map for Data }
242impl_from! { NumberObject for Data }
243impl_from! { Promise for Data }
244impl_from! { PromiseResolver for Data }
245impl_from! { Proxy for Data }
246impl_from! { RegExp for Data }
247impl_from! { Set for Data }
248impl_from! { SharedArrayBuffer for Data }
249impl_from! { StringObject for Data }
250impl_from! { SymbolObject for Data }
251impl_from! { WasmModuleObject for Data }
252impl_from! { Primitive for Data }
253impl_from! { BigInt for Data }
254impl_from! { Boolean for Data }
255impl_from! { Name for Data }
256impl_from! { String for Data }
257impl_from! { Symbol for Data }
258impl_from! { Number for Data }
259impl_from! { Integer for Data }
260impl_from! { Int32 for Data }
261impl_from! { Uint32 for Data }
262impl_partial_eq! { AccessorSignature for Data use identity }
263impl_partial_eq! { Context for Data use identity }
264impl_partial_eq! { Message for Data use identity }
265impl_partial_eq! { Module for Data use identity }
266impl_partial_eq! { PrimitiveArray for Data use identity }
267impl_partial_eq! { Private for Data use identity }
268impl_partial_eq! { Script for Data use identity }
269impl_partial_eq! { ScriptOrModule for Data use identity }
270impl_partial_eq! { Signature for Data use identity }
271impl_partial_eq! { StackFrame for Data use identity }
272impl_partial_eq! { StackTrace for Data use identity }
273impl_partial_eq! { Template for Data use identity }
274impl_partial_eq! { FunctionTemplate for Data use identity }
275impl_partial_eq! { ObjectTemplate for Data use identity }
276impl_partial_eq! { UnboundModuleScript for Data use identity }
277impl_partial_eq! { UnboundScript for Data use identity }
278impl_partial_eq! { External for Data use identity }
279impl_partial_eq! { Object for Data use identity }
280impl_partial_eq! { Array for Data use identity }
281impl_partial_eq! { ArrayBuffer for Data use identity }
282impl_partial_eq! { ArrayBufferView for Data use identity }
283impl_partial_eq! { DataView for Data use identity }
284impl_partial_eq! { TypedArray for Data use identity }
285impl_partial_eq! { BigInt64Array for Data use identity }
286impl_partial_eq! { BigUint64Array for Data use identity }
287impl_partial_eq! { Float32Array for Data use identity }
288impl_partial_eq! { Float64Array for Data use identity }
289impl_partial_eq! { Int16Array for Data use identity }
290impl_partial_eq! { Int32Array for Data use identity }
291impl_partial_eq! { Int8Array for Data use identity }
292impl_partial_eq! { Uint16Array for Data use identity }
293impl_partial_eq! { Uint32Array for Data use identity }
294impl_partial_eq! { Uint8Array for Data use identity }
295impl_partial_eq! { Uint8ClampedArray for Data use identity }
296impl_partial_eq! { BigIntObject for Data use identity }
297impl_partial_eq! { BooleanObject for Data use identity }
298impl_partial_eq! { Date for Data use identity }
299impl_partial_eq! { Function for Data use identity }
300impl_partial_eq! { Map for Data use identity }
301impl_partial_eq! { NumberObject for Data use identity }
302impl_partial_eq! { Promise for Data use identity }
303impl_partial_eq! { PromiseResolver for Data use identity }
304impl_partial_eq! { Proxy for Data use identity }
305impl_partial_eq! { RegExp for Data use identity }
306impl_partial_eq! { Set for Data use identity }
307impl_partial_eq! { SharedArrayBuffer for Data use identity }
308impl_partial_eq! { StringObject for Data use identity }
309impl_partial_eq! { SymbolObject for Data use identity }
310impl_partial_eq! { WasmModuleObject for Data use identity }
311impl_partial_eq! { Boolean for Data use identity }
312impl_partial_eq! { Symbol for Data use identity }
313
314/// An AccessorSignature specifies which receivers are valid parameters
315/// to an accessor callback.
316#[repr(C)]
317#[derive(Debug)]
318pub struct AccessorSignature(Opaque);
319
320impl_deref! { Data for AccessorSignature }
321impl_eq! { for AccessorSignature }
322impl_hash! { for AccessorSignature }
323impl_partial_eq! { Data for AccessorSignature use identity }
324impl_partial_eq! { AccessorSignature for AccessorSignature use identity }
325
326/// A sandboxed execution context with its own set of built-in objects
327/// and functions.
328#[repr(C)]
329#[derive(Debug)]
330pub struct Context(Opaque);
331
332impl_deref! { Data for Context }
333impl_eq! { for Context }
334impl_hash! { for Context }
335impl_partial_eq! { Data for Context use identity }
336impl_partial_eq! { Context for Context use identity }
337
338/// An error message.
339#[repr(C)]
340#[derive(Debug)]
341pub struct Message(Opaque);
342
343impl_deref! { Data for Message }
344impl_eq! { for Message }
345impl_hash! { for Message }
346impl_partial_eq! { Data for Message use identity }
347impl_partial_eq! { Message for Message use identity }
348
349/// A compiled JavaScript module.
350#[repr(C)]
351#[derive(Debug)]
352pub struct Module(Opaque);
353
354impl_deref! { Data for Module }
355impl_try_from! { Data for Module if d => d.is_module() }
356impl_eq! { for Module }
357impl_partial_eq! { Data for Module use identity }
358impl_partial_eq! { Module for Module use identity }
359
360/// A fixed-sized array with elements of type Data.
361#[repr(C)]
362#[derive(Debug)]
363pub struct FixedArray(Opaque);
364
365impl_deref! { Data for FixedArray }
366impl_eq! { for FixedArray }
367impl_hash! { for FixedArray }
368impl_partial_eq! { Data for FixedArray use identity }
369impl_partial_eq! { FixedArray for FixedArray use identity }
370
371#[repr(C)]
372#[derive(Debug)]
373pub struct ModuleRequest(Opaque);
374
375impl_deref! { Data for ModuleRequest }
376impl_from! { Data for ModuleRequest }
377impl_eq! { for ModuleRequest }
378impl_hash! { for ModuleRequest }
379impl_partial_eq! { Data for ModuleRequest use identity }
380impl_partial_eq! { ModuleRequest for ModuleRequest use identity }
381
382/// An array to hold Primitive values. This is used by the embedder to
383/// pass host defined options to the ScriptOptions during compilation.
384///
385/// This is passed back to the embedder as part of
386/// HostImportModuleDynamicallyCallback for module loading.
387#[repr(C)]
388#[derive(Debug)]
389pub struct PrimitiveArray(Opaque);
390
391impl_deref! { Data for PrimitiveArray }
392impl_eq! { for PrimitiveArray }
393impl_hash! { for PrimitiveArray }
394impl_partial_eq! { Data for PrimitiveArray use identity }
395impl_partial_eq! { PrimitiveArray for PrimitiveArray use identity }
396
397/// A private symbol
398///
399/// This is an experimental feature. Use at your own risk.
400#[repr(C)]
401#[derive(Debug)]
402pub struct Private(Opaque);
403
404impl_deref! { Data for Private }
405impl_try_from! { Data for Private if d => d.is_private() }
406impl_eq! { for Private }
407impl_hash! { for Private }
408impl_partial_eq! { Data for Private use identity }
409impl_partial_eq! { Private for Private use identity }
410
411/// A compiled JavaScript script, tied to a Context which was active when the
412/// script was compiled.
413#[repr(C)]
414#[derive(Debug)]
415pub struct Script(Opaque);
416
417impl_deref! { Data for Script }
418impl_eq! { for Script }
419impl_hash! { for Script }
420impl_partial_eq! { Data for Script use identity }
421impl_partial_eq! { Script for Script use identity }
422
423/// A container type that holds relevant metadata for module loading.
424///
425/// This is passed back to the embedder as part of
426/// HostImportModuleDynamicallyCallback for module loading.
427#[repr(C)]
428#[derive(Debug)]
429pub struct ScriptOrModule(Opaque);
430
431impl_deref! { Data for ScriptOrModule }
432impl_eq! { for ScriptOrModule }
433impl_hash! { for ScriptOrModule }
434impl_partial_eq! { Data for ScriptOrModule use identity }
435impl_partial_eq! { ScriptOrModule for ScriptOrModule use identity }
436
437/// A Signature specifies which receiver is valid for a function.
438///
439/// A receiver matches a given signature if the receiver (or any of its
440/// hidden prototypes) was created from the signature's FunctionTemplate, or
441/// from a FunctionTemplate that inherits directly or indirectly from the
442/// signature's FunctionTemplate.
443#[repr(C)]
444#[derive(Debug)]
445pub struct Signature(Opaque);
446
447impl_deref! { Data for Signature }
448impl_eq! { for Signature }
449impl_hash! { for Signature }
450impl_partial_eq! { Data for Signature use identity }
451impl_partial_eq! { Signature for Signature use identity }
452
453/// A single JavaScript stack frame.
454#[repr(C)]
455#[derive(Debug)]
456pub struct StackFrame(Opaque);
457
458impl_deref! { Data for StackFrame }
459impl_eq! { for StackFrame }
460impl_hash! { for StackFrame }
461impl_partial_eq! { Data for StackFrame use identity }
462impl_partial_eq! { StackFrame for StackFrame use identity }
463
464/// Representation of a JavaScript stack trace. The information collected is a
465/// snapshot of the execution stack and the information remains valid after
466/// execution continues.
467#[repr(C)]
468#[derive(Debug)]
469pub struct StackTrace(Opaque);
470
471impl_deref! { Data for StackTrace }
472impl_eq! { for StackTrace }
473impl_hash! { for StackTrace }
474impl_partial_eq! { Data for StackTrace use identity }
475impl_partial_eq! { StackTrace for StackTrace use identity }
476
477/// The superclass of object and function templates.
478#[repr(C)]
479#[derive(Debug)]
480pub struct Template(Opaque);
481
482impl_deref! { Data for Template }
483impl_from! { FunctionTemplate for Template }
484impl_from! { ObjectTemplate for Template }
485impl_eq! { for Template }
486impl_hash! { for Template }
487impl_partial_eq! { Data for Template use identity }
488impl_partial_eq! { Template for Template use identity }
489impl_partial_eq! { FunctionTemplate for Template use identity }
490impl_partial_eq! { ObjectTemplate for Template use identity }
491
492/// A FunctionTemplate is used to create functions at runtime. There
493/// can only be one function created from a FunctionTemplate in a
494/// context. The lifetime of the created function is equal to the
495/// lifetime of the context. So in case the embedder needs to create
496/// temporary functions that can be collected using Scripts is
497/// preferred.
498///
499/// Any modification of a FunctionTemplate after first instantiation will
500/// trigger a crash.
501///
502/// A FunctionTemplate can have properties, these properties are added to the
503/// function object when it is created.
504///
505/// A FunctionTemplate has a corresponding instance template which is
506/// used to create object instances when the function is used as a
507/// constructor. Properties added to the instance template are added to
508/// each object instance.
509///
510/// A FunctionTemplate can have a prototype template. The prototype template
511/// is used to create the prototype object of the function.
512///
513/// The following example shows how to use a FunctionTemplate:
514///
515/// ```ignore
516///    v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
517///    t->Set(isolate, "func_property", v8::Number::New(isolate, 1));
518///
519///    v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
520///    proto_t->Set(isolate,
521///                 "proto_method",
522///                 v8::FunctionTemplate::New(isolate, InvokeCallback));
523///    proto_t->Set(isolate, "proto_const", v8::Number::New(isolate, 2));
524///
525///    v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
526///    instance_t->SetAccessor(
527///        String::NewFromUtf8Literal(isolate, "instance_accessor"),
528///        InstanceAccessorCallback);
529///    instance_t->SetHandler(
530///        NamedPropertyHandlerConfiguration(PropertyHandlerCallback));
531///    instance_t->Set(String::NewFromUtf8Literal(isolate, "instance_property"),
532///                    Number::New(isolate, 3));
533///
534///    v8::Local<v8::Function> function = t->GetFunction();
535///    v8::Local<v8::Object> instance = function->NewInstance();
536/// ```
537///
538/// Let's use "function" as the JS variable name of the function object
539/// and "instance" for the instance object created above. The function
540/// and the instance will have the following properties:
541///
542/// ```ignore
543///   func_property in function == true;
544///   function.func_property == 1;
545///
546///   function.prototype.proto_method() invokes 'InvokeCallback'
547///   function.prototype.proto_const == 2;
548///
549///   instance instanceof function == true;
550///   instance.instance_accessor calls 'InstanceAccessorCallback'
551///   instance.instance_property == 3;
552/// ```
553///
554/// A FunctionTemplate can inherit from another one by calling the
555/// FunctionTemplate::Inherit method. The following graph illustrates
556/// the semantics of inheritance:
557///
558/// ```ignore
559///   FunctionTemplate Parent  -> Parent() . prototype -> { }
560///     ^                                                  ^
561///     | Inherit(Parent)                                  | .__proto__
562///     |                                                  |
563///   FunctionTemplate Child   -> Child()  . prototype -> { }
564/// ```
565///
566/// A FunctionTemplate 'Child' inherits from 'Parent', the prototype
567/// object of the Child() function has __proto__ pointing to the
568/// Parent() function's prototype object. An instance of the Child
569/// function has all properties on Parent's instance templates.
570///
571/// Let Parent be the FunctionTemplate initialized in the previous
572/// section and create a Child FunctionTemplate by:
573///
574/// ```ignore
575///   Local<FunctionTemplate> parent = t;
576///   Local<FunctionTemplate> child = FunctionTemplate::New();
577///   child->Inherit(parent);
578///
579///   Local<Function> child_function = child->GetFunction();
580///   Local<Object> child_instance = child_function->NewInstance();
581/// ```
582///
583/// The Child function and Child instance will have the following
584/// properties:
585///
586/// ```ignore
587///   child_func.prototype.__proto__ == function.prototype;
588///   child_instance.instance_accessor calls 'InstanceAccessorCallback'
589///   child_instance.instance_property == 3;
590/// ```
591///
592/// The additional 'c_function' parameter refers to a fast API call, which
593/// must not trigger GC or JavaScript execution, or call into V8 in other
594/// ways. For more information how to define them, see
595/// include/v8-fast-api-calls.h. Please note that this feature is still
596/// experimental.
597#[repr(C)]
598#[derive(Debug)]
599pub struct FunctionTemplate(Opaque);
600
601impl_deref! { Template for FunctionTemplate }
602impl_try_from! { Data for FunctionTemplate if d => d.is_function_template() }
603impl_eq! { for FunctionTemplate }
604impl_hash! { for FunctionTemplate }
605impl_partial_eq! { Data for FunctionTemplate use identity }
606impl_partial_eq! { Template for FunctionTemplate use identity }
607impl_partial_eq! { FunctionTemplate for FunctionTemplate use identity }
608
609/// An ObjectTemplate is used to create objects at runtime.
610///
611/// Properties added to an ObjectTemplate are added to each object
612/// created from the ObjectTemplate.
613#[repr(C)]
614#[derive(Debug)]
615pub struct ObjectTemplate(Opaque);
616
617impl_deref! { Template for ObjectTemplate }
618impl_try_from! { Data for ObjectTemplate if d => d.is_object_template() }
619impl_eq! { for ObjectTemplate }
620impl_hash! { for ObjectTemplate }
621impl_partial_eq! { Data for ObjectTemplate use identity }
622impl_partial_eq! { Template for ObjectTemplate use identity }
623impl_partial_eq! { ObjectTemplate for ObjectTemplate use identity }
624
625/// A compiled JavaScript module, not yet tied to a Context.
626#[repr(C)]
627#[derive(Debug)]
628pub struct UnboundModuleScript(Opaque);
629
630impl_deref! { Data for UnboundModuleScript }
631impl_eq! { for UnboundModuleScript }
632impl_hash! { for UnboundModuleScript }
633impl_partial_eq! { Data for UnboundModuleScript use identity }
634impl_partial_eq! { UnboundModuleScript for UnboundModuleScript use identity }
635
636/// A compiled JavaScript script, not yet tied to a Context.
637#[repr(C)]
638#[derive(Debug)]
639pub struct UnboundScript(Opaque);
640
641impl_deref! { Data for UnboundScript }
642impl_eq! { for UnboundScript }
643impl_hash! { for UnboundScript }
644impl_partial_eq! { Data for UnboundScript use identity }
645impl_partial_eq! { UnboundScript for UnboundScript use identity }
646
647/// The superclass of all JavaScript values and objects.
648#[repr(C)]
649#[derive(Debug)]
650pub struct Value(Opaque);
651
652impl_deref! { Data for Value }
653// TODO: Also implement `TryFrom<Data>` for all subtypes of `Value`,
654// so a `Local<Data>` can be directly cast to any `Local` with a JavaScript
655// value type in it. We need this to make certain APIs work, such as
656// `scope.get_context_data_from_snapshot_once::<v8::Number>()` and
657// `scope.get_isolate_data_from_snapshot_once::<v8::Number>()`.
658impl_try_from! { Data for Value if d => d.is_value() }
659impl_from! { External for Value }
660impl_from! { Object for Value }
661impl_from! { Array for Value }
662impl_from! { ArrayBuffer for Value }
663impl_from! { ArrayBufferView for Value }
664impl_from! { DataView for Value }
665impl_from! { TypedArray for Value }
666impl_from! { BigInt64Array for Value }
667impl_from! { BigUint64Array for Value }
668impl_from! { Float32Array for Value }
669impl_from! { Float64Array for Value }
670impl_from! { Int16Array for Value }
671impl_from! { Int32Array for Value }
672impl_from! { Int8Array for Value }
673impl_from! { Uint16Array for Value }
674impl_from! { Uint32Array for Value }
675impl_from! { Uint8Array for Value }
676impl_from! { Uint8ClampedArray for Value }
677impl_from! { BigIntObject for Value }
678impl_from! { BooleanObject for Value }
679impl_from! { Date for Value }
680impl_from! { Function for Value }
681impl_from! { Map for Value }
682impl_from! { NumberObject for Value }
683impl_from! { Promise for Value }
684impl_from! { PromiseResolver for Value }
685impl_from! { Proxy for Value }
686impl_from! { RegExp for Value }
687impl_from! { Set for Value }
688impl_from! { SharedArrayBuffer for Value }
689impl_from! { StringObject for Value }
690impl_from! { SymbolObject for Value }
691impl_from! { WasmModuleObject for Value }
692impl_from! { Primitive for Value }
693impl_from! { BigInt for Value }
694impl_from! { Boolean for Value }
695impl_from! { Name for Value }
696impl_from! { String for Value }
697impl_from! { Symbol for Value }
698impl_from! { Number for Value }
699impl_from! { Integer for Value }
700impl_from! { Int32 for Value }
701impl_from! { Uint32 for Value }
702impl_eq! { for Value }
703impl_hash! { for Value }
704impl_partial_eq! { Value for Value use same_value_zero }
705impl_partial_eq! { External for Value use identity }
706impl_partial_eq! { Object for Value use identity }
707impl_partial_eq! { Array for Value use identity }
708impl_partial_eq! { ArrayBuffer for Value use identity }
709impl_partial_eq! { ArrayBufferView for Value use identity }
710impl_partial_eq! { DataView for Value use identity }
711impl_partial_eq! { TypedArray for Value use identity }
712impl_partial_eq! { BigInt64Array for Value use identity }
713impl_partial_eq! { BigUint64Array for Value use identity }
714impl_partial_eq! { Float32Array for Value use identity }
715impl_partial_eq! { Float64Array for Value use identity }
716impl_partial_eq! { Int16Array for Value use identity }
717impl_partial_eq! { Int32Array for Value use identity }
718impl_partial_eq! { Int8Array for Value use identity }
719impl_partial_eq! { Uint16Array for Value use identity }
720impl_partial_eq! { Uint32Array for Value use identity }
721impl_partial_eq! { Uint8Array for Value use identity }
722impl_partial_eq! { Uint8ClampedArray for Value use identity }
723impl_partial_eq! { BigIntObject for Value use identity }
724impl_partial_eq! { BooleanObject for Value use identity }
725impl_partial_eq! { Date for Value use identity }
726impl_partial_eq! { Function for Value use identity }
727impl_partial_eq! { Map for Value use identity }
728impl_partial_eq! { NumberObject for Value use identity }
729impl_partial_eq! { Promise for Value use identity }
730impl_partial_eq! { PromiseResolver for Value use identity }
731impl_partial_eq! { Proxy for Value use identity }
732impl_partial_eq! { RegExp for Value use identity }
733impl_partial_eq! { Set for Value use identity }
734impl_partial_eq! { SharedArrayBuffer for Value use identity }
735impl_partial_eq! { StringObject for Value use identity }
736impl_partial_eq! { SymbolObject for Value use identity }
737impl_partial_eq! { WasmModuleObject for Value use identity }
738impl_partial_eq! { Primitive for Value use same_value_zero }
739impl_partial_eq! { BigInt for Value use same_value_zero }
740impl_partial_eq! { Boolean for Value use identity }
741impl_partial_eq! { Name for Value use same_value_zero }
742impl_partial_eq! { String for Value use same_value_zero }
743impl_partial_eq! { Symbol for Value use identity }
744impl_partial_eq! { Number for Value use same_value_zero }
745impl_partial_eq! { Integer for Value use same_value_zero }
746impl_partial_eq! { Int32 for Value use same_value_zero }
747impl_partial_eq! { Uint32 for Value use same_value_zero }
748
749/// A JavaScript value that wraps a C++ void*. This type of value is mainly used
750/// to associate C++ data structures with JavaScript objects.
751#[repr(C)]
752#[derive(Debug)]
753pub struct External(Opaque);
754
755impl_deref! { Value for External }
756impl_try_from! { Value for External if v => v.is_external() }
757impl_eq! { for External }
758impl_hash! { for External }
759impl_partial_eq! { Data for External use identity }
760impl_partial_eq! { Value for External use identity }
761impl_partial_eq! { External for External use identity }
762
763/// A JavaScript object (ECMA-262, 4.3.3)
764#[repr(C)]
765#[derive(Debug)]
766pub struct Object(Opaque);
767
768impl_deref! { Value for Object }
769impl_try_from! { Value for Object if v => v.is_object() }
770impl_from! { Array for Object }
771impl_from! { ArrayBuffer for Object }
772impl_from! { ArrayBufferView for Object }
773impl_from! { DataView for Object }
774impl_from! { TypedArray for Object }
775impl_from! { BigInt64Array for Object }
776impl_from! { BigUint64Array for Object }
777impl_from! { Float32Array for Object }
778impl_from! { Float64Array for Object }
779impl_from! { Int16Array for Object }
780impl_from! { Int32Array for Object }
781impl_from! { Int8Array for Object }
782impl_from! { Uint16Array for Object }
783impl_from! { Uint32Array for Object }
784impl_from! { Uint8Array for Object }
785impl_from! { Uint8ClampedArray for Object }
786impl_from! { BigIntObject for Object }
787impl_from! { BooleanObject for Object }
788impl_from! { Date for Object }
789impl_from! { Function for Object }
790impl_from! { Map for Object }
791impl_from! { NumberObject for Object }
792impl_from! { Promise for Object }
793impl_from! { PromiseResolver for Object }
794impl_from! { Proxy for Object }
795impl_from! { RegExp for Object }
796impl_from! { Set for Object }
797impl_from! { SharedArrayBuffer for Object }
798impl_from! { StringObject for Object }
799impl_from! { SymbolObject for Object }
800impl_from! { WasmModuleObject for Object }
801impl_eq! { for Object }
802impl_hash! { for Object }
803impl_partial_eq! { Data for Object use identity }
804impl_partial_eq! { Value for Object use identity }
805impl_partial_eq! { Object for Object use identity }
806impl_partial_eq! { Array for Object use identity }
807impl_partial_eq! { ArrayBuffer for Object use identity }
808impl_partial_eq! { ArrayBufferView for Object use identity }
809impl_partial_eq! { DataView for Object use identity }
810impl_partial_eq! { TypedArray for Object use identity }
811impl_partial_eq! { BigInt64Array for Object use identity }
812impl_partial_eq! { BigUint64Array for Object use identity }
813impl_partial_eq! { Float32Array for Object use identity }
814impl_partial_eq! { Float64Array for Object use identity }
815impl_partial_eq! { Int16Array for Object use identity }
816impl_partial_eq! { Int32Array for Object use identity }
817impl_partial_eq! { Int8Array for Object use identity }
818impl_partial_eq! { Uint16Array for Object use identity }
819impl_partial_eq! { Uint32Array for Object use identity }
820impl_partial_eq! { Uint8Array for Object use identity }
821impl_partial_eq! { Uint8ClampedArray for Object use identity }
822impl_partial_eq! { BigIntObject for Object use identity }
823impl_partial_eq! { BooleanObject for Object use identity }
824impl_partial_eq! { Date for Object use identity }
825impl_partial_eq! { Function for Object use identity }
826impl_partial_eq! { Map for Object use identity }
827impl_partial_eq! { NumberObject for Object use identity }
828impl_partial_eq! { Promise for Object use identity }
829impl_partial_eq! { PromiseResolver for Object use identity }
830impl_partial_eq! { Proxy for Object use identity }
831impl_partial_eq! { RegExp for Object use identity }
832impl_partial_eq! { Set for Object use identity }
833impl_partial_eq! { SharedArrayBuffer for Object use identity }
834impl_partial_eq! { StringObject for Object use identity }
835impl_partial_eq! { SymbolObject for Object use identity }
836impl_partial_eq! { WasmModuleObject for Object use identity }
837
838/// An instance of the built-in array constructor (ECMA-262, 15.4.2).
839#[repr(C)]
840#[derive(Debug)]
841pub struct Array(Opaque);
842
843impl_deref! { Object for Array }
844impl_try_from! { Value for Array if v => v.is_array() }
845impl_try_from! { Object for Array if v => v.is_array() }
846impl_eq! { for Array }
847impl_hash! { for Array }
848impl_partial_eq! { Data for Array use identity }
849impl_partial_eq! { Value for Array use identity }
850impl_partial_eq! { Object for Array use identity }
851impl_partial_eq! { Array for Array use identity }
852
853/// An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
854#[repr(C)]
855#[derive(Debug)]
856pub struct ArrayBuffer(Opaque);
857
858impl_deref! { Object for ArrayBuffer }
859impl_try_from! { Value for ArrayBuffer if v => v.is_array_buffer() }
860impl_try_from! { Object for ArrayBuffer if v => v.is_array_buffer() }
861impl_eq! { for ArrayBuffer }
862impl_hash! { for ArrayBuffer }
863impl_partial_eq! { Data for ArrayBuffer use identity }
864impl_partial_eq! { Value for ArrayBuffer use identity }
865impl_partial_eq! { Object for ArrayBuffer use identity }
866impl_partial_eq! { ArrayBuffer for ArrayBuffer use identity }
867
868/// A base class for an instance of one of "views" over ArrayBuffer,
869/// including TypedArrays and DataView (ES6 draft 15.13).
870#[repr(C)]
871#[derive(Debug)]
872pub struct ArrayBufferView(Opaque);
873
874impl_deref! { Object for ArrayBufferView }
875impl_try_from! { Value for ArrayBufferView if v => v.is_array_buffer_view() }
876impl_try_from! { Object for ArrayBufferView if v => v.is_array_buffer_view() }
877impl_from! { DataView for ArrayBufferView }
878impl_from! { TypedArray for ArrayBufferView }
879impl_from! { BigInt64Array for ArrayBufferView }
880impl_from! { BigUint64Array for ArrayBufferView }
881impl_from! { Float32Array for ArrayBufferView }
882impl_from! { Float64Array for ArrayBufferView }
883impl_from! { Int16Array for ArrayBufferView }
884impl_from! { Int32Array for ArrayBufferView }
885impl_from! { Int8Array for ArrayBufferView }
886impl_from! { Uint16Array for ArrayBufferView }
887impl_from! { Uint32Array for ArrayBufferView }
888impl_from! { Uint8Array for ArrayBufferView }
889impl_from! { Uint8ClampedArray for ArrayBufferView }
890impl_eq! { for ArrayBufferView }
891impl_hash! { for ArrayBufferView }
892impl_partial_eq! { Data for ArrayBufferView use identity }
893impl_partial_eq! { Value for ArrayBufferView use identity }
894impl_partial_eq! { Object for ArrayBufferView use identity }
895impl_partial_eq! { ArrayBufferView for ArrayBufferView use identity }
896impl_partial_eq! { DataView for ArrayBufferView use identity }
897impl_partial_eq! { TypedArray for ArrayBufferView use identity }
898impl_partial_eq! { BigInt64Array for ArrayBufferView use identity }
899impl_partial_eq! { BigUint64Array for ArrayBufferView use identity }
900impl_partial_eq! { Float32Array for ArrayBufferView use identity }
901impl_partial_eq! { Float64Array for ArrayBufferView use identity }
902impl_partial_eq! { Int16Array for ArrayBufferView use identity }
903impl_partial_eq! { Int32Array for ArrayBufferView use identity }
904impl_partial_eq! { Int8Array for ArrayBufferView use identity }
905impl_partial_eq! { Uint16Array for ArrayBufferView use identity }
906impl_partial_eq! { Uint32Array for ArrayBufferView use identity }
907impl_partial_eq! { Uint8Array for ArrayBufferView use identity }
908impl_partial_eq! { Uint8ClampedArray for ArrayBufferView use identity }
909
910/// An instance of DataView constructor (ES6 draft 15.13.7).
911#[repr(C)]
912#[derive(Debug)]
913pub struct DataView(Opaque);
914
915impl_deref! { ArrayBufferView for DataView }
916impl_try_from! { Value for DataView if v => v.is_data_view() }
917impl_try_from! { Object for DataView if v => v.is_data_view() }
918impl_try_from! { ArrayBufferView for DataView if v => v.is_data_view() }
919impl_eq! { for DataView }
920impl_hash! { for DataView }
921impl_partial_eq! { Data for DataView use identity }
922impl_partial_eq! { Value for DataView use identity }
923impl_partial_eq! { Object for DataView use identity }
924impl_partial_eq! { ArrayBufferView for DataView use identity }
925impl_partial_eq! { DataView for DataView use identity }
926
927/// A base class for an instance of TypedArray series of constructors
928/// (ES6 draft 15.13.6).
929#[repr(C)]
930#[derive(Debug)]
931pub struct TypedArray(Opaque);
932
933impl_deref! { ArrayBufferView for TypedArray }
934impl_try_from! { Value for TypedArray if v => v.is_typed_array() }
935impl_try_from! { Object for TypedArray if v => v.is_typed_array() }
936impl_try_from! { ArrayBufferView for TypedArray if v => v.is_typed_array() }
937impl_from! { BigInt64Array for TypedArray }
938impl_from! { BigUint64Array for TypedArray }
939impl_from! { Float32Array for TypedArray }
940impl_from! { Float64Array for TypedArray }
941impl_from! { Int16Array for TypedArray }
942impl_from! { Int32Array for TypedArray }
943impl_from! { Int8Array for TypedArray }
944impl_from! { Uint16Array for TypedArray }
945impl_from! { Uint32Array for TypedArray }
946impl_from! { Uint8Array for TypedArray }
947impl_from! { Uint8ClampedArray for TypedArray }
948impl_eq! { for TypedArray }
949impl_hash! { for TypedArray }
950impl_partial_eq! { Data for TypedArray use identity }
951impl_partial_eq! { Value for TypedArray use identity }
952impl_partial_eq! { Object for TypedArray use identity }
953impl_partial_eq! { ArrayBufferView for TypedArray use identity }
954impl_partial_eq! { TypedArray for TypedArray use identity }
955impl_partial_eq! { BigInt64Array for TypedArray use identity }
956impl_partial_eq! { BigUint64Array for TypedArray use identity }
957impl_partial_eq! { Float32Array for TypedArray use identity }
958impl_partial_eq! { Float64Array for TypedArray use identity }
959impl_partial_eq! { Int16Array for TypedArray use identity }
960impl_partial_eq! { Int32Array for TypedArray use identity }
961impl_partial_eq! { Int8Array for TypedArray use identity }
962impl_partial_eq! { Uint16Array for TypedArray use identity }
963impl_partial_eq! { Uint32Array for TypedArray use identity }
964impl_partial_eq! { Uint8Array for TypedArray use identity }
965impl_partial_eq! { Uint8ClampedArray for TypedArray use identity }
966
967/// An instance of BigInt64Array constructor.
968#[repr(C)]
969#[derive(Debug)]
970pub struct BigInt64Array(Opaque);
971
972impl_deref! { TypedArray for BigInt64Array }
973impl_try_from! { Value for BigInt64Array if v => v.is_big_int64_array() }
974impl_try_from! { Object for BigInt64Array if v => v.is_big_int64_array() }
975impl_try_from! { ArrayBufferView for BigInt64Array if v => v.is_big_int64_array() }
976impl_try_from! { TypedArray for BigInt64Array if v => v.is_big_int64_array() }
977impl_eq! { for BigInt64Array }
978impl_hash! { for BigInt64Array }
979impl_partial_eq! { Data for BigInt64Array use identity }
980impl_partial_eq! { Value for BigInt64Array use identity }
981impl_partial_eq! { Object for BigInt64Array use identity }
982impl_partial_eq! { ArrayBufferView for BigInt64Array use identity }
983impl_partial_eq! { TypedArray for BigInt64Array use identity }
984impl_partial_eq! { BigInt64Array for BigInt64Array use identity }
985
986/// An instance of BigUint64Array constructor.
987#[repr(C)]
988#[derive(Debug)]
989pub struct BigUint64Array(Opaque);
990
991impl_deref! { TypedArray for BigUint64Array }
992impl_try_from! { Value for BigUint64Array if v => v.is_big_uint64_array() }
993impl_try_from! { Object for BigUint64Array if v => v.is_big_uint64_array() }
994impl_try_from! { ArrayBufferView for BigUint64Array if v => v.is_big_uint64_array() }
995impl_try_from! { TypedArray for BigUint64Array if v => v.is_big_uint64_array() }
996impl_eq! { for BigUint64Array }
997impl_hash! { for BigUint64Array }
998impl_partial_eq! { Data for BigUint64Array use identity }
999impl_partial_eq! { Value for BigUint64Array use identity }
1000impl_partial_eq! { Object for BigUint64Array use identity }
1001impl_partial_eq! { ArrayBufferView for BigUint64Array use identity }
1002impl_partial_eq! { TypedArray for BigUint64Array use identity }
1003impl_partial_eq! { BigUint64Array for BigUint64Array use identity }
1004
1005/// An instance of Float32Array constructor (ES6 draft 15.13.6).
1006#[repr(C)]
1007#[derive(Debug)]
1008pub struct Float32Array(Opaque);
1009
1010impl_deref! { TypedArray for Float32Array }
1011impl_try_from! { Value for Float32Array if v => v.is_float32_array() }
1012impl_try_from! { Object for Float32Array if v => v.is_float32_array() }
1013impl_try_from! { ArrayBufferView for Float32Array if v => v.is_float32_array() }
1014impl_try_from! { TypedArray for Float32Array if v => v.is_float32_array() }
1015impl_eq! { for Float32Array }
1016impl_hash! { for Float32Array }
1017impl_partial_eq! { Data for Float32Array use identity }
1018impl_partial_eq! { Value for Float32Array use identity }
1019impl_partial_eq! { Object for Float32Array use identity }
1020impl_partial_eq! { ArrayBufferView for Float32Array use identity }
1021impl_partial_eq! { TypedArray for Float32Array use identity }
1022impl_partial_eq! { Float32Array for Float32Array use identity }
1023
1024/// An instance of Float64Array constructor (ES6 draft 15.13.6).
1025#[repr(C)]
1026#[derive(Debug)]
1027pub struct Float64Array(Opaque);
1028
1029impl_deref! { TypedArray for Float64Array }
1030impl_try_from! { Value for Float64Array if v => v.is_float64_array() }
1031impl_try_from! { Object for Float64Array if v => v.is_float64_array() }
1032impl_try_from! { ArrayBufferView for Float64Array if v => v.is_float64_array() }
1033impl_try_from! { TypedArray for Float64Array if v => v.is_float64_array() }
1034impl_eq! { for Float64Array }
1035impl_hash! { for Float64Array }
1036impl_partial_eq! { Data for Float64Array use identity }
1037impl_partial_eq! { Value for Float64Array use identity }
1038impl_partial_eq! { Object for Float64Array use identity }
1039impl_partial_eq! { ArrayBufferView for Float64Array use identity }
1040impl_partial_eq! { TypedArray for Float64Array use identity }
1041impl_partial_eq! { Float64Array for Float64Array use identity }
1042
1043/// An instance of Int16Array constructor (ES6 draft 15.13.6).
1044#[repr(C)]
1045#[derive(Debug)]
1046pub struct Int16Array(Opaque);
1047
1048impl_deref! { TypedArray for Int16Array }
1049impl_try_from! { Value for Int16Array if v => v.is_int16_array() }
1050impl_try_from! { Object for Int16Array if v => v.is_int16_array() }
1051impl_try_from! { ArrayBufferView for Int16Array if v => v.is_int16_array() }
1052impl_try_from! { TypedArray for Int16Array if v => v.is_int16_array() }
1053impl_eq! { for Int16Array }
1054impl_hash! { for Int16Array }
1055impl_partial_eq! { Data for Int16Array use identity }
1056impl_partial_eq! { Value for Int16Array use identity }
1057impl_partial_eq! { Object for Int16Array use identity }
1058impl_partial_eq! { ArrayBufferView for Int16Array use identity }
1059impl_partial_eq! { TypedArray for Int16Array use identity }
1060impl_partial_eq! { Int16Array for Int16Array use identity }
1061
1062/// An instance of Int32Array constructor (ES6 draft 15.13.6).
1063#[repr(C)]
1064#[derive(Debug)]
1065pub struct Int32Array(Opaque);
1066
1067impl_deref! { TypedArray for Int32Array }
1068impl_try_from! { Value for Int32Array if v => v.is_int32_array() }
1069impl_try_from! { Object for Int32Array if v => v.is_int32_array() }
1070impl_try_from! { ArrayBufferView for Int32Array if v => v.is_int32_array() }
1071impl_try_from! { TypedArray for Int32Array if v => v.is_int32_array() }
1072impl_eq! { for Int32Array }
1073impl_hash! { for Int32Array }
1074impl_partial_eq! { Data for Int32Array use identity }
1075impl_partial_eq! { Value for Int32Array use identity }
1076impl_partial_eq! { Object for Int32Array use identity }
1077impl_partial_eq! { ArrayBufferView for Int32Array use identity }
1078impl_partial_eq! { TypedArray for Int32Array use identity }
1079impl_partial_eq! { Int32Array for Int32Array use identity }
1080
1081/// An instance of Int8Array constructor (ES6 draft 15.13.6).
1082#[repr(C)]
1083#[derive(Debug)]
1084pub struct Int8Array(Opaque);
1085
1086impl_deref! { TypedArray for Int8Array }
1087impl_try_from! { Value for Int8Array if v => v.is_int8_array() }
1088impl_try_from! { Object for Int8Array if v => v.is_int8_array() }
1089impl_try_from! { ArrayBufferView for Int8Array if v => v.is_int8_array() }
1090impl_try_from! { TypedArray for Int8Array if v => v.is_int8_array() }
1091impl_eq! { for Int8Array }
1092impl_hash! { for Int8Array }
1093impl_partial_eq! { Data for Int8Array use identity }
1094impl_partial_eq! { Value for Int8Array use identity }
1095impl_partial_eq! { Object for Int8Array use identity }
1096impl_partial_eq! { ArrayBufferView for Int8Array use identity }
1097impl_partial_eq! { TypedArray for Int8Array use identity }
1098impl_partial_eq! { Int8Array for Int8Array use identity }
1099
1100/// An instance of Uint16Array constructor (ES6 draft 15.13.6).
1101#[repr(C)]
1102#[derive(Debug)]
1103pub struct Uint16Array(Opaque);
1104
1105impl_deref! { TypedArray for Uint16Array }
1106impl_try_from! { Value for Uint16Array if v => v.is_uint16_array() }
1107impl_try_from! { Object for Uint16Array if v => v.is_uint16_array() }
1108impl_try_from! { ArrayBufferView for Uint16Array if v => v.is_uint16_array() }
1109impl_try_from! { TypedArray for Uint16Array if v => v.is_uint16_array() }
1110impl_eq! { for Uint16Array }
1111impl_hash! { for Uint16Array }
1112impl_partial_eq! { Data for Uint16Array use identity }
1113impl_partial_eq! { Value for Uint16Array use identity }
1114impl_partial_eq! { Object for Uint16Array use identity }
1115impl_partial_eq! { ArrayBufferView for Uint16Array use identity }
1116impl_partial_eq! { TypedArray for Uint16Array use identity }
1117impl_partial_eq! { Uint16Array for Uint16Array use identity }
1118
1119/// An instance of Uint32Array constructor (ES6 draft 15.13.6).
1120#[repr(C)]
1121#[derive(Debug)]
1122pub struct Uint32Array(Opaque);
1123
1124impl_deref! { TypedArray for Uint32Array }
1125impl_try_from! { Value for Uint32Array if v => v.is_uint32_array() }
1126impl_try_from! { Object for Uint32Array if v => v.is_uint32_array() }
1127impl_try_from! { ArrayBufferView for Uint32Array if v => v.is_uint32_array() }
1128impl_try_from! { TypedArray for Uint32Array if v => v.is_uint32_array() }
1129impl_eq! { for Uint32Array }
1130impl_hash! { for Uint32Array }
1131impl_partial_eq! { Data for Uint32Array use identity }
1132impl_partial_eq! { Value for Uint32Array use identity }
1133impl_partial_eq! { Object for Uint32Array use identity }
1134impl_partial_eq! { ArrayBufferView for Uint32Array use identity }
1135impl_partial_eq! { TypedArray for Uint32Array use identity }
1136impl_partial_eq! { Uint32Array for Uint32Array use identity }
1137
1138/// An instance of Uint8Array constructor (ES6 draft 15.13.6).
1139#[repr(C)]
1140#[derive(Debug)]
1141pub struct Uint8Array(Opaque);
1142
1143impl_deref! { TypedArray for Uint8Array }
1144impl_try_from! { Value for Uint8Array if v => v.is_uint8_array() }
1145impl_try_from! { Object for Uint8Array if v => v.is_uint8_array() }
1146impl_try_from! { ArrayBufferView for Uint8Array if v => v.is_uint8_array() }
1147impl_try_from! { TypedArray for Uint8Array if v => v.is_uint8_array() }
1148impl_eq! { for Uint8Array }
1149impl_hash! { for Uint8Array }
1150impl_partial_eq! { Data for Uint8Array use identity }
1151impl_partial_eq! { Value for Uint8Array use identity }
1152impl_partial_eq! { Object for Uint8Array use identity }
1153impl_partial_eq! { ArrayBufferView for Uint8Array use identity }
1154impl_partial_eq! { TypedArray for Uint8Array use identity }
1155impl_partial_eq! { Uint8Array for Uint8Array use identity }
1156
1157/// An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
1158#[repr(C)]
1159#[derive(Debug)]
1160pub struct Uint8ClampedArray(Opaque);
1161
1162impl_deref! { TypedArray for Uint8ClampedArray }
1163impl_try_from! { Value for Uint8ClampedArray if v => v.is_uint8_clamped_array() }
1164impl_try_from! { Object for Uint8ClampedArray if v => v.is_uint8_clamped_array() }
1165impl_try_from! { ArrayBufferView for Uint8ClampedArray if v => v.is_uint8_clamped_array() }
1166impl_try_from! { TypedArray for Uint8ClampedArray if v => v.is_uint8_clamped_array() }
1167impl_eq! { for Uint8ClampedArray }
1168impl_hash! { for Uint8ClampedArray }
1169impl_partial_eq! { Data for Uint8ClampedArray use identity }
1170impl_partial_eq! { Value for Uint8ClampedArray use identity }
1171impl_partial_eq! { Object for Uint8ClampedArray use identity }
1172impl_partial_eq! { ArrayBufferView for Uint8ClampedArray use identity }
1173impl_partial_eq! { TypedArray for Uint8ClampedArray use identity }
1174impl_partial_eq! { Uint8ClampedArray for Uint8ClampedArray use identity }
1175
1176/// A BigInt object (https://tc39.github.io/proposal-bigint)
1177#[repr(C)]
1178#[derive(Debug)]
1179pub struct BigIntObject(Opaque);
1180
1181impl_deref! { Object for BigIntObject }
1182impl_try_from! { Value for BigIntObject if v => v.is_big_int_object() }
1183impl_try_from! { Object for BigIntObject if v => v.is_big_int_object() }
1184impl_eq! { for BigIntObject }
1185impl_hash! { for BigIntObject }
1186impl_partial_eq! { Data for BigIntObject use identity }
1187impl_partial_eq! { Value for BigIntObject use identity }
1188impl_partial_eq! { Object for BigIntObject use identity }
1189impl_partial_eq! { BigIntObject for BigIntObject use identity }
1190
1191/// A Boolean object (ECMA-262, 4.3.15).
1192#[repr(C)]
1193#[derive(Debug)]
1194pub struct BooleanObject(Opaque);
1195
1196impl_deref! { Object for BooleanObject }
1197impl_try_from! { Value for BooleanObject if v => v.is_boolean_object() }
1198impl_try_from! { Object for BooleanObject if v => v.is_boolean_object() }
1199impl_eq! { for BooleanObject }
1200impl_hash! { for BooleanObject }
1201impl_partial_eq! { Data for BooleanObject use identity }
1202impl_partial_eq! { Value for BooleanObject use identity }
1203impl_partial_eq! { Object for BooleanObject use identity }
1204impl_partial_eq! { BooleanObject for BooleanObject use identity }
1205
1206/// An instance of the built-in Date constructor (ECMA-262, 15.9).
1207#[repr(C)]
1208#[derive(Debug)]
1209pub struct Date(Opaque);
1210
1211impl_deref! { Object for Date }
1212impl_try_from! { Value for Date if v => v.is_date() }
1213impl_try_from! { Object for Date if v => v.is_date() }
1214impl_eq! { for Date }
1215impl_hash! { for Date }
1216impl_partial_eq! { Data for Date use identity }
1217impl_partial_eq! { Value for Date use identity }
1218impl_partial_eq! { Object for Date use identity }
1219impl_partial_eq! { Date for Date use identity }
1220
1221/// A JavaScript function object (ECMA-262, 15.3).
1222#[repr(C)]
1223#[derive(Debug)]
1224pub struct Function(Opaque);
1225
1226impl_deref! { Object for Function }
1227impl_try_from! { Value for Function if v => v.is_function() }
1228impl_try_from! { Object for Function if v => v.is_function() }
1229impl_eq! { for Function }
1230impl_hash! { for Function }
1231impl_partial_eq! { Data for Function use identity }
1232impl_partial_eq! { Value for Function use identity }
1233impl_partial_eq! { Object for Function use identity }
1234impl_partial_eq! { Function for Function use identity }
1235
1236/// An instance of the built-in Map constructor (ECMA-262, 6th Edition, 23.1.1).
1237#[repr(C)]
1238#[derive(Debug)]
1239pub struct Map(Opaque);
1240
1241impl_deref! { Object for Map }
1242impl_try_from! { Value for Map if v => v.is_map() }
1243impl_try_from! { Object for Map if v => v.is_map() }
1244impl_eq! { for Map }
1245impl_hash! { for Map }
1246impl_partial_eq! { Data for Map use identity }
1247impl_partial_eq! { Value for Map use identity }
1248impl_partial_eq! { Object for Map use identity }
1249impl_partial_eq! { Map for Map use identity }
1250
1251/// A Number object (ECMA-262, 4.3.21).
1252#[repr(C)]
1253#[derive(Debug)]
1254pub struct NumberObject(Opaque);
1255
1256impl_deref! { Object for NumberObject }
1257impl_try_from! { Value for NumberObject if v => v.is_number_object() }
1258impl_try_from! { Object for NumberObject if v => v.is_number_object() }
1259impl_eq! { for NumberObject }
1260impl_hash! { for NumberObject }
1261impl_partial_eq! { Data for NumberObject use identity }
1262impl_partial_eq! { Value for NumberObject use identity }
1263impl_partial_eq! { Object for NumberObject use identity }
1264impl_partial_eq! { NumberObject for NumberObject use identity }
1265
1266/// An instance of the built-in Promise constructor (ES6 draft).
1267#[repr(C)]
1268#[derive(Debug)]
1269pub struct Promise(Opaque);
1270
1271impl_deref! { Object for Promise }
1272impl_try_from! { Value for Promise if v => v.is_promise() }
1273impl_try_from! { Object for Promise if v => v.is_promise() }
1274impl_eq! { for Promise }
1275impl_hash! { for Promise }
1276impl_partial_eq! { Data for Promise use identity }
1277impl_partial_eq! { Value for Promise use identity }
1278impl_partial_eq! { Object for Promise use identity }
1279impl_partial_eq! { Promise for Promise use identity }
1280
1281#[repr(C)]
1282#[derive(Debug)]
1283pub struct PromiseResolver(Opaque);
1284
1285impl_deref! { Object for PromiseResolver }
1286impl_eq! { for PromiseResolver }
1287impl_hash! { for PromiseResolver }
1288impl_partial_eq! { Data for PromiseResolver use identity }
1289impl_partial_eq! { Value for PromiseResolver use identity }
1290impl_partial_eq! { Object for PromiseResolver use identity }
1291impl_partial_eq! { PromiseResolver for PromiseResolver use identity }
1292
1293/// An instance of the built-in Proxy constructor (ECMA-262, 6th Edition,
1294/// 26.2.1).
1295#[repr(C)]
1296#[derive(Debug)]
1297pub struct Proxy(Opaque);
1298
1299impl_deref! { Object for Proxy }
1300impl_try_from! { Value for Proxy if v => v.is_proxy() }
1301impl_try_from! { Object for Proxy if v => v.is_proxy() }
1302impl_eq! { for Proxy }
1303impl_hash! { for Proxy }
1304impl_partial_eq! { Data for Proxy use identity }
1305impl_partial_eq! { Value for Proxy use identity }
1306impl_partial_eq! { Object for Proxy use identity }
1307impl_partial_eq! { Proxy for Proxy use identity }
1308
1309/// An instance of the built-in RegExp constructor (ECMA-262, 15.10).
1310#[repr(C)]
1311#[derive(Debug)]
1312pub struct RegExp(Opaque);
1313
1314impl_deref! { Object for RegExp }
1315impl_try_from! { Value for RegExp if v => v.is_reg_exp() }
1316impl_try_from! { Object for RegExp if v => v.is_reg_exp() }
1317impl_eq! { for RegExp }
1318impl_hash! { for RegExp }
1319impl_partial_eq! { Data for RegExp use identity }
1320impl_partial_eq! { Value for RegExp use identity }
1321impl_partial_eq! { Object for RegExp use identity }
1322impl_partial_eq! { RegExp for RegExp use identity }
1323
1324/// An instance of the built-in Set constructor (ECMA-262, 6th Edition, 23.2.1).
1325#[repr(C)]
1326#[derive(Debug)]
1327pub struct Set(Opaque);
1328
1329impl_deref! { Object for Set }
1330impl_try_from! { Value for Set if v => v.is_set() }
1331impl_try_from! { Object for Set if v => v.is_set() }
1332impl_eq! { for Set }
1333impl_hash! { for Set }
1334impl_partial_eq! { Data for Set use identity }
1335impl_partial_eq! { Value for Set use identity }
1336impl_partial_eq! { Object for Set use identity }
1337impl_partial_eq! { Set for Set use identity }
1338
1339/// An instance of the built-in SharedArrayBuffer constructor.
1340#[repr(C)]
1341#[derive(Debug)]
1342pub struct SharedArrayBuffer(Opaque);
1343
1344impl_deref! { Object for SharedArrayBuffer }
1345impl_try_from! { Value for SharedArrayBuffer if v => v.is_shared_array_buffer() }
1346impl_try_from! { Object for SharedArrayBuffer if v => v.is_shared_array_buffer() }
1347impl_eq! { for SharedArrayBuffer }
1348impl_hash! { for SharedArrayBuffer }
1349impl_partial_eq! { Data for SharedArrayBuffer use identity }
1350impl_partial_eq! { Value for SharedArrayBuffer use identity }
1351impl_partial_eq! { Object for SharedArrayBuffer use identity }
1352impl_partial_eq! { SharedArrayBuffer for SharedArrayBuffer use identity }
1353
1354/// A String object (ECMA-262, 4.3.18).
1355#[repr(C)]
1356#[derive(Debug)]
1357pub struct StringObject(Opaque);
1358
1359impl_deref! { Object for StringObject }
1360impl_try_from! { Value for StringObject if v => v.is_string_object() }
1361impl_try_from! { Object for StringObject if v => v.is_string_object() }
1362impl_eq! { for StringObject }
1363impl_hash! { for StringObject }
1364impl_partial_eq! { Data for StringObject use identity }
1365impl_partial_eq! { Value for StringObject use identity }
1366impl_partial_eq! { Object for StringObject use identity }
1367impl_partial_eq! { StringObject for StringObject use identity }
1368
1369/// A Symbol object (ECMA-262 edition 6).
1370#[repr(C)]
1371#[derive(Debug)]
1372pub struct SymbolObject(Opaque);
1373
1374impl_deref! { Object for SymbolObject }
1375impl_try_from! { Value for SymbolObject if v => v.is_symbol_object() }
1376impl_try_from! { Object for SymbolObject if v => v.is_symbol_object() }
1377impl_eq! { for SymbolObject }
1378impl_hash! { for SymbolObject }
1379impl_partial_eq! { Data for SymbolObject use identity }
1380impl_partial_eq! { Value for SymbolObject use identity }
1381impl_partial_eq! { Object for SymbolObject use identity }
1382impl_partial_eq! { SymbolObject for SymbolObject use identity }
1383
1384/// An instance of WebAssembly.Module.
1385#[repr(C)]
1386#[derive(Debug)]
1387pub struct WasmModuleObject(Opaque);
1388
1389impl_deref! { Object for WasmModuleObject }
1390impl_try_from! { Value for WasmModuleObject if v => v.is_wasm_module_object() }
1391impl_try_from! { Object for WasmModuleObject if v => v.is_wasm_module_object() }
1392impl_eq! { for WasmModuleObject }
1393impl_hash! { for WasmModuleObject }
1394impl_partial_eq! { Data for WasmModuleObject use identity }
1395impl_partial_eq! { Value for WasmModuleObject use identity }
1396impl_partial_eq! { Object for WasmModuleObject use identity }
1397impl_partial_eq! { WasmModuleObject for WasmModuleObject use identity }
1398
1399/// The superclass of primitive values. See ECMA-262 4.3.2.
1400#[repr(C)]
1401#[derive(Debug)]
1402pub struct Primitive(Opaque);
1403
1404impl_deref! { Value for Primitive }
1405impl_try_from! { Value for Primitive if v => v.is_null_or_undefined() || v.is_boolean() || v.is_name() || v.is_number() || v.is_big_int() }
1406impl_from! { BigInt for Primitive }
1407impl_from! { Boolean for Primitive }
1408impl_from! { Name for Primitive }
1409impl_from! { String for Primitive }
1410impl_from! { Symbol for Primitive }
1411impl_from! { Number for Primitive }
1412impl_from! { Integer for Primitive }
1413impl_from! { Int32 for Primitive }
1414impl_from! { Uint32 for Primitive }
1415impl_eq! { for Primitive }
1416impl_hash! { for Primitive }
1417impl_partial_eq! { Value for Primitive use same_value_zero }
1418impl_partial_eq! { Primitive for Primitive use same_value_zero }
1419impl_partial_eq! { BigInt for Primitive use same_value_zero }
1420impl_partial_eq! { Boolean for Primitive use identity }
1421impl_partial_eq! { Name for Primitive use same_value_zero }
1422impl_partial_eq! { String for Primitive use same_value_zero }
1423impl_partial_eq! { Symbol for Primitive use identity }
1424impl_partial_eq! { Number for Primitive use same_value_zero }
1425impl_partial_eq! { Integer for Primitive use same_value_zero }
1426impl_partial_eq! { Int32 for Primitive use same_value_zero }
1427impl_partial_eq! { Uint32 for Primitive use same_value_zero }
1428
1429/// A JavaScript BigInt value (https://tc39.github.io/proposal-bigint)
1430#[repr(C)]
1431#[derive(Debug)]
1432pub struct BigInt(Opaque);
1433
1434impl_deref! { Primitive for BigInt }
1435impl_try_from! { Value for BigInt if v => v.is_big_int() }
1436impl_try_from! { Primitive for BigInt if v => v.is_big_int() }
1437impl_eq! { for BigInt }
1438impl_hash! { for BigInt }
1439impl_partial_eq! { Value for BigInt use same_value_zero }
1440impl_partial_eq! { Primitive for BigInt use same_value_zero }
1441impl_partial_eq! { BigInt for BigInt use strict_equals }
1442
1443/// A primitive boolean value (ECMA-262, 4.3.14). Either the true
1444/// or false value.
1445#[repr(C)]
1446#[derive(Debug)]
1447pub struct Boolean(Opaque);
1448
1449impl_deref! { Primitive for Boolean }
1450impl_try_from! { Value for Boolean if v => v.is_boolean() }
1451impl_try_from! { Primitive for Boolean if v => v.is_boolean() }
1452impl_eq! { for Boolean }
1453impl_hash! { for Boolean }
1454impl_partial_eq! { Data for Boolean use identity }
1455impl_partial_eq! { Value for Boolean use identity }
1456impl_partial_eq! { Primitive for Boolean use identity }
1457impl_partial_eq! { Boolean for Boolean use identity }
1458
1459/// A superclass for symbols and strings.
1460#[repr(C)]
1461#[derive(Debug)]
1462pub struct Name(Opaque);
1463
1464impl_deref! { Primitive for Name }
1465impl_try_from! { Value for Name if v => v.is_name() }
1466impl_try_from! { Primitive for Name if v => v.is_name() }
1467impl_from! { String for Name }
1468impl_from! { Symbol for Name }
1469impl_eq! { for Name }
1470impl_hash! { for Name }
1471impl_partial_eq! { Value for Name use same_value_zero }
1472impl_partial_eq! { Primitive for Name use same_value_zero }
1473impl_partial_eq! { Name for Name use strict_equals }
1474impl_partial_eq! { String for Name use strict_equals }
1475impl_partial_eq! { Symbol for Name use identity }
1476
1477/// A JavaScript string value (ECMA-262, 4.3.17).
1478#[repr(C)]
1479#[derive(Debug)]
1480pub struct String(Opaque);
1481
1482impl_deref! { Name for String }
1483impl_try_from! { Value for String if v => v.is_string() }
1484impl_try_from! { Primitive for String if v => v.is_string() }
1485impl_try_from! { Name for String if v => v.is_string() }
1486impl_eq! { for String }
1487impl_hash! { for String }
1488impl_partial_eq! { Value for String use same_value_zero }
1489impl_partial_eq! { Primitive for String use same_value_zero }
1490impl_partial_eq! { Name for String use strict_equals }
1491impl_partial_eq! { String for String use strict_equals }
1492
1493/// A JavaScript symbol (ECMA-262 edition 6)
1494#[repr(C)]
1495#[derive(Debug)]
1496pub struct Symbol(Opaque);
1497
1498impl_deref! { Name for Symbol }
1499impl_try_from! { Value for Symbol if v => v.is_symbol() }
1500impl_try_from! { Primitive for Symbol if v => v.is_symbol() }
1501impl_try_from! { Name for Symbol if v => v.is_symbol() }
1502impl_eq! { for Symbol }
1503impl_hash! { for Symbol }
1504impl_partial_eq! { Data for Symbol use identity }
1505impl_partial_eq! { Value for Symbol use identity }
1506impl_partial_eq! { Primitive for Symbol use identity }
1507impl_partial_eq! { Name for Symbol use identity }
1508impl_partial_eq! { Symbol for Symbol use identity }
1509
1510/// A JavaScript number value (ECMA-262, 4.3.20)
1511#[repr(C)]
1512#[derive(Debug)]
1513pub struct Number(Opaque);
1514
1515impl_deref! { Primitive for Number }
1516impl_try_from! { Value for Number if v => v.is_number() }
1517impl_try_from! { Primitive for Number if v => v.is_number() }
1518impl_from! { Integer for Number }
1519impl_from! { Int32 for Number }
1520impl_from! { Uint32 for Number }
1521impl_eq! { for Number }
1522impl_hash! { for Number }
1523impl_partial_eq! { Value for Number use same_value_zero }
1524impl_partial_eq! { Primitive for Number use same_value_zero }
1525impl_partial_eq! { Number for Number use same_value_zero }
1526impl_partial_eq! { Integer for Number use same_value_zero }
1527impl_partial_eq! { Int32 for Number use same_value_zero }
1528impl_partial_eq! { Uint32 for Number use same_value_zero }
1529
1530/// A JavaScript value representing a signed integer.
1531#[repr(C)]
1532#[derive(Debug)]
1533pub struct Integer(Opaque);
1534
1535impl_deref! { Number for Integer }
1536impl_try_from! { Value for Integer if v => v.is_int32() || v.is_uint32() }
1537impl_try_from! { Primitive for Integer if v => v.is_int32() || v.is_uint32() }
1538impl_try_from! { Number for Integer if v => v.is_int32() || v.is_uint32() }
1539impl_from! { Int32 for Integer }
1540impl_from! { Uint32 for Integer }
1541impl_eq! { for Integer }
1542impl_hash! { for Integer }
1543impl_partial_eq! { Value for Integer use same_value_zero }
1544impl_partial_eq! { Primitive for Integer use same_value_zero }
1545impl_partial_eq! { Number for Integer use same_value_zero }
1546impl_partial_eq! { Integer for Integer use strict_equals }
1547impl_partial_eq! { Int32 for Integer use strict_equals }
1548impl_partial_eq! { Uint32 for Integer use strict_equals }
1549
1550/// A JavaScript value representing a 32-bit signed integer.
1551#[repr(C)]
1552#[derive(Debug)]
1553pub struct Int32(Opaque);
1554
1555impl_deref! { Integer for Int32 }
1556impl_try_from! { Value for Int32 if v => v.is_int32() }
1557impl_try_from! { Primitive for Int32 if v => v.is_int32() }
1558impl_try_from! { Number for Int32 if v => v.is_int32() }
1559impl_try_from! { Integer for Int32 if v => v.is_int32() }
1560impl_eq! { for Int32 }
1561impl_hash! { for Int32 }
1562impl_partial_eq! { Value for Int32 use same_value_zero }
1563impl_partial_eq! { Primitive for Int32 use same_value_zero }
1564impl_partial_eq! { Number for Int32 use same_value_zero }
1565impl_partial_eq! { Integer for Int32 use strict_equals }
1566impl_partial_eq! { Int32 for Int32 use strict_equals }
1567
1568/// A JavaScript value representing a 32-bit unsigned integer.
1569#[repr(C)]
1570#[derive(Debug)]
1571pub struct Uint32(Opaque);
1572
1573impl_deref! { Integer for Uint32 }
1574impl_try_from! { Value for Uint32 if v => v.is_uint32() }
1575impl_try_from! { Primitive for Uint32 if v => v.is_uint32() }
1576impl_try_from! { Number for Uint32 if v => v.is_uint32() }
1577impl_try_from! { Integer for Uint32 if v => v.is_uint32() }
1578impl_eq! { for Uint32 }
1579impl_hash! { for Uint32 }
1580impl_partial_eq! { Value for Uint32 use same_value_zero }
1581impl_partial_eq! { Primitive for Uint32 use same_value_zero }
1582impl_partial_eq! { Number for Uint32 use same_value_zero }
1583impl_partial_eq! { Integer for Uint32 use strict_equals }
1584impl_partial_eq! { Uint32 for Uint32 use strict_equals }