1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
// Rational, BigRational
pub use num::{ BigInt, BigUint, complex::Complex32, complex::Complex64, };
use num::{ Zero, One, Float, ToPrimitive, FromPrimitive, bigint::ToBigInt, bigint::ToBigUint, };


use crate::rc_ref::RcRef;

use std::fmt;
use std::ptr::NonNull;
use std::collections::HashMap;


// #[derive(Clone, PartialEq, PartialOrd, Copy)]
// pub struct Float<T>(T);

// impl<T: fmt::Debug> fmt::Debug for Float<T> {
//     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//         write!(f, "{:?}", self.0)
//     }
// }
// impl<T: fmt::Display> fmt::Display for Float<T> {
//     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//         write!(f, "{}", self.0)
//     }
// }
// impl Eq for Float<f32> { }
// impl Eq for Float<f64> { }


// pub type F32 = Float<f32>;
// pub type F64 = Float<f64>;
pub type StringRef = RcRef<String>;
pub type SymbolRef = RcRef<Symbol>;
pub type BigIntRef = RcRef<BigInt>;
pub type BigUintRef = RcRef<BigUint>;
pub type Complex32Ref = RcRef<Complex32>;
pub type Complex64Ref = RcRef<Complex64>;




impl PartialEq for StringRef {
    fn eq(&self, other: &StringRef) -> bool {
        *self.borrow() == *other.borrow()
    }
}
impl fmt::Display for StringRef {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.borrow())
    }
}

impl PartialEq for SymbolRef {
    fn eq(&self, other: &SymbolRef) -> bool {
        *self.borrow() == *other.borrow()
    }
}
impl fmt::Display for SymbolRef {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{:?}", self.borrow())
    }
}

impl PartialEq for BigIntRef {
    fn eq(&self, other: &BigIntRef) -> bool {
        *self.borrow() == *other.borrow()
    }
}
impl fmt::Display for BigIntRef {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.borrow())
    }
}

impl PartialEq for BigUintRef {
    fn eq(&self, other: &BigUintRef) -> bool {
        *self.borrow() == *other.borrow()
    }
}
impl fmt::Display for BigUintRef {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.borrow())
    }
}

impl PartialEq for Complex32Ref {
    fn eq(&self, other: &Complex32Ref) -> bool {
        *self.borrow() == *other.borrow()
    }
}
impl fmt::Display for Complex32Ref {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.borrow())
    }
}

impl PartialEq for Complex64Ref {
    fn eq(&self, other: &Complex64Ref) -> bool {
        *self.borrow() == *other.borrow()
    }
}
impl fmt::Display for Complex64Ref {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.borrow())
    }
}


#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct Symbol {
    is_public: bool,
    id: usize,
}

impl Symbol {
    #[inline]
    pub fn new(is_public: bool, id: usize) -> Self {
        Self { is_public, id }
    }

    #[inline]
    pub fn id(&self) -> usize {
        self.id
    }

    #[inline]
    pub fn is_public(&self) -> bool {
        self.is_public
    }
}



/*
Prop:
    filename: String,
    line_number: usize,
    column_number: usize,

Prototype:
    name: String
    message: String
    toString: Function
*/
// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors
// https://www.ecma-international.org/ecma-262/9.0/index.html#sec-native-error-types-used-in-this-standard
pub enum NativeError {
    Error(String),
    SyntaxError(String),
    /// This exception is not currently used within this specification.
    /// This object remains for compatibility with previous editions of this specification.
    EvalError {
        line_number: usize,
        column_number: usize,
        native_error: Box<NativeError>,
    },
    RangeError(String),
    ReferenceError(String),
    TypeError(String),
    URIError(String),

    // non-standard
    InternalError(String),
}

impl fmt::Debug for NativeError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self)
    }
}

impl fmt::Display for NativeError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        use self::NativeError::*;

        match self {
            Error(message) => write!(f, "Error: {}", message),
            SyntaxError(message) => write!(f, "SyntaxError: {}", message),
            EvalError { line_number, column_number, native_error } => write!(f, "EvalError: {}", native_error),
            RangeError(message) => write!(f, "RangeError: {}", message),
            ReferenceError(message) => write!(f, "ReferenceError: {}", message),
            TypeError(message) => write!(f, "TypeError: {}", message),
            URIError(message) => write!(f, "URIError: {}", message),
            InternalError(message) => write!(f, "InternalError: {}", message),
        }
    }
}

impl NativeError {
    pub fn error<T: Into<String>>(message: T) -> Self {
        NativeError::Error(message.into())
    }

    pub fn syntax_error<T: Into<String>>(message: T) -> Self {
        NativeError::SyntaxError(message.into())
    }

    pub fn eval_error<T: Into<String>>(message: T) -> Self {
        // NativeError::EvalError(message.into())
        unimplemented!()
    }

    pub fn range_error<T: Into<String>>(message: T) -> Self {
        NativeError::RangeError(message.into())
    }

    pub fn reference_error<T: Into<String>>(message: T) -> Self {
        NativeError::ReferenceError(message.into())
    }
    
    pub fn type_error<T: Into<String>>(message: T) -> Self {
        NativeError::TypeError(message.into())
    }

    pub fn uri_error<T: Into<String>>(message: T) -> Self {
        NativeError::URIError(message.into())
    }

    pub fn internal_error<T: Into<String>>(message: T) -> Self {
        NativeError::InternalError(message.into())
    }
}


// 16 Bytes
// Kind: 8 Bytes , Data: 8 Bytes
#[derive(PartialEq, Clone)]
pub enum Value {
    Undefined,
    Null,
    String(StringRef),
    Object(ObjectRef),
    Boolean(bool),
    I64(i64),
    F64(f64),
    // https://github.com/jkarns275/f128
    // F128(f128),
    // decimal floating: https://docs.rs/decimal
    // D64(d64),
    // D128(d128),
    // Rational(BigRational),
    J64(Complex64Ref),
    BigInt(BigIntRef),
    Symbol(SymbolRef),
}

impl fmt::Debug for Value {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        use self::Value::*;

        match *self {
            Undefined => write!(f, "undefined"),
            Null => write!(f, "null"),
            String(ref inner) => fmt::Debug::fmt(inner, f),
            Object(ref inner) => fmt::Debug::fmt(inner, f),
            Boolean(ref inner) => fmt::Debug::fmt(inner, f),
            I64(ref inner) => fmt::Debug::fmt(inner, f),
            F64(ref inner) => fmt::Debug::fmt(inner, f),
            J64(ref inner) => fmt::Debug::fmt(inner, f),
            BigInt(ref inner) => fmt::Debug::fmt(inner, f),
            Symbol(ref inner) => fmt::Debug::fmt(inner, f),
        }
    }
}

impl fmt::Display for Value {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        use self::Value::*;

        match *self {
            Undefined => write!(f, "undefined"),
            Null => write!(f, "null"),
            String(ref inner) => fmt::Display::fmt(inner, f),
            Object(ref inner) => fmt::Display::fmt(inner, f),
            Boolean(ref inner) => fmt::Display::fmt(inner, f),
            I64(ref inner) => fmt::Display::fmt(inner, f),
            F64(ref inner) => fmt::Display::fmt(inner, f),
            J64(ref inner) => fmt::Display::fmt(inner, f),
            BigInt(ref inner) => fmt::Display::fmt(inner, f),
            Symbol(ref inner) => fmt::Display::fmt(inner, f),
        }
    }
}

impl Value {
    pub const ZERO: Value = Value::I64(0i64);
    pub const ONE: Value  = Value::I64(1i64);
    pub const NAN: Value  = Value::F64(std::f64::NAN);
    pub const INFINITY: Value     = Value::F64(std::f64::INFINITY);
    pub const NEG_INFINITY: Value = Value::F64(std::f64::NEG_INFINITY);
    pub const NEG_ZERO: Value     = Value::F64(-0f64);

    #[inline]
    pub fn typeof_(&self) -> &'static str {
        use self::Value::*;

        match *self {
            Undefined => "undefined",
            Null => "null",
            String(_) => "string",
            Object(_) => "object",
            Boolean(_) => "boolean",
            I64(_) => "number",
            F64(_) => "number",
            J64(_) => "complex",
            BigInt(_) => "bigint",
            Symbol(_) => "symbol",
        }
    }
    
    #[inline]
    pub fn zero<T: Zero + Into<Value>>() -> T {
        T::zero()
    }

    #[inline]
    pub fn one<T: One + Into<Value>>() -> T {
        T::one()
    }

    #[inline]
    pub fn nan<T: Float + Into<Value>>() -> T {
        T::nan()
    }

    #[inline]
    pub fn infinity<T: Float + Into<Value>>() -> T {
        T::infinity()
    }

    #[inline]
    pub fn neg_infinity<T: Float + Into<Value>>() -> T {
        T::neg_infinity()
    }

    #[inline]
    pub fn neg_zero<T: Float + Into<Value>>() -> T {
        T::neg_zero()
    }

    #[inline]
    pub fn is_zero(&self) -> bool {
        use self::Value::*;

        match self {
            Undefined => false,
            Null => false,
            String(_) => false,
            Object(_) => false,
            Boolean(_) => false,
            I64(inner) => inner.is_zero(),
            F64(inner) => inner.is_zero(),
            J64(inner) => inner.borrow().is_zero(),
            BigInt(inner) => inner.borrow().is_zero(),
            Symbol(_) => false,
        }
    }

    #[inline]
    pub fn is_one(&self) -> bool {
        use self::Value::*;
        
        match self {
            Undefined => false,
            Null => false,
            String(_) => false,
            Object(_) => false,
            Boolean(_) => false,
            I64(inner) => inner.is_one(),
            F64(inner) => inner.is_one(),
            J64(inner) => inner.borrow().is_one(),
            BigInt(inner) => inner.borrow().is_one(),
            Symbol(_) => false,
        }
    }

    /// Returns true if this value is NaN and false otherwise.
    #[inline]
    pub fn is_nan(&self) -> bool {
        use self::Value::*;
        
        match self {
            Undefined => false,
            Null => false,
            String(_) => false,
            Object(_) => false,
            Boolean(_) => false,
            I64(inner) => false,
            F64(inner) => inner.is_nan(),
            J64(inner) => inner.borrow().is_nan(),
            BigInt(inner) => false,
            Symbol(_) => false,
        }
    }

    /// Returns true if this value is positive infinity or negative infinity and false otherwise.
    #[inline]
    pub fn is_infinite(&self) -> bool {
        use self::Value::*;
        
        match self {
            Undefined => false,
            Null => false,
            String(_) => false,
            Object(_) => false,
            Boolean(_) => false,
            I64(inner) => false,
            F64(inner) => inner.is_infinite(),
            J64(inner) => inner.borrow().is_infinite(),
            BigInt(inner) => false,
            Symbol(_) => false,
        }
    }

    /// Returns true if this number is neither infinite nor NaN.
    #[inline]
    pub fn is_finite(&self) -> bool {
        use self::Value::*;
        
        match self {
            Undefined => false,
            Null => false,
            String(_) => false,
            Object(_) => false,
            Boolean(_) => false,
            I64(inner) => false,
            F64(inner) => inner.is_finite(),
            J64(inner) => inner.borrow().is_finite(),
            BigInt(inner) => false,
            Symbol(_) => false,
        }
    }

    

    // NOTE: 
    //      .clone()      值或引用值拷贝
    //      .copy()       值或引用拷贝
    //      .deepcopy()   同 .copy() 的区别在于针对 Object 深拷贝时,会拷贝 Object 内部的元素。
    #[inline]
    pub fn copy(&self) -> Value {
        match *self {
            // Native Copy
            Value::Undefined => Value::Undefined,
            Value::Null => Value::Null,
            Value::Boolean(inner) => inner.into(),
            Value::I64(inner) => inner.into(),
            Value::F64(inner) => inner.into(),

            // 堆拷贝
            Value::String(ref inner) => inner.borrow().clone().into(),
            Value::Symbol(ref inner) => inner.borrow().clone().into(),
            Value::J64(ref inner) => inner.borrow().clone().into(),
            Value::BigInt(ref inner) => inner.borrow().clone().into(),
            // TODO: 需要手动实现 copy 和 deepcopy 方法
            Value::Object(ref inner) => inner.borrow().clone().into(),
        }
    }

    #[inline]
    pub fn deepcopy(&self) -> Value {
        match *self {
            Value::Undefined
            | Value::Null
            | Value::String(_)
            | Value::Boolean(_)
            | Value::I64(_)
            | Value::F64(_)
            | Value::J64(_)
            | Value::BigInt(_)
            | Value::Symbol(_) => self.copy(),
            // TODO: 需要手动实现 deepcopy 方法
            Value::Object(ref inner) => inner.borrow().clone().into(),
        }
    }

    #[inline]
    pub fn is_undefined(&self) -> bool {
        use self::Value::*;

        match *self {
            Undefined => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_null(&self) -> bool {
        use self::Value::*;

        match *self {
            Null => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_string(&self) -> bool {
        use self::Value::*;

        match *self {
            String(_) => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_object(&self) -> bool {
        use self::Value::*;

        match *self {
            Object(_) => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_boolean(&self) -> bool {
        use self::Value::*;

        match *self {
            Boolean(_) => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_number(&self) -> bool {
        use self::Value::*;

        match *self {
            I64(_) => true,
            F64(_) => true,
            J64(_) => true,
            BigInt(_) => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_int(&self) -> bool {
        use self::Value::*;

        match *self {
            I64(_) => true,
            BigInt(_) => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_float(&self) -> bool {
        use self::Value::*;

        match *self {
            F64(_) => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_symbol(&self) -> bool {
        use self::Value::*;

        match *self {
            Symbol(_) => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_bigint(&self) -> bool {
        use self::Value::*;

        match *self {
            BigInt(_) => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_complex(&self) -> bool {
        use self::Value::*;

        match *self {
            J64(_) => true,
            _ => false,
        }
    }
}


impl From<String> for Value {
    fn from(s: String) -> Self {
        Value::String(RcRef::new(s))
    }
}
impl From<&str> for Value {
    fn from(s: &str) -> Self {
        Value::String(RcRef::new(s.to_string()))
    }
}


impl From<Object> for Value {
    fn from(s: Object) -> Self {
        Value::Object(RcRef::new(s))
    }
}

impl From<bool> for Value {
    fn from(s: bool) -> Self {
        Value::Boolean(s)
    }
}

impl From<u8> for Value {
    fn from(s: u8) -> Self {
        Value::I64(s as i64)
    }
}
impl From<u16> for Value {
    fn from(s: u16) -> Self {
        Value::I64(s as i64)
    }
}
impl From<u32> for Value {
    fn from(s: u32) -> Self {
        Value::I64(s as i64)
    }
}
impl From<u64> for Value {
    fn from(s: u64) -> Self {
        if s > std::i64::MAX as u64 {
            BigInt::from_u64(s).unwrap().into()
        } else {
            Value::I64(s as i64)
        }
    }
}
impl From<usize> for Value {
    fn from(s: usize) -> Self {
        if s as i128 > std::i64::MAX as i128 {
            BigInt::from_usize(s).unwrap().into()
        } else {
            Value::I64(s as i64)
        }
    }
}

impl From<i8> for Value {
    fn from(s: i8) -> Self {
        Value::I64(s as i64)
    }
}
impl From<i16> for Value {
    fn from(s: i16) -> Self {
        Value::I64(s as i64)
    }
}
impl From<i32> for Value {
    fn from(s: i32) -> Self {
        Value::I64(s as i64)
    }
}
impl From<i64> for Value {
    fn from(s: i64) -> Self {
        Value::I64(s)
    }
}
impl From<isize> for Value {
    fn from(s: isize) -> Self {
        Value::I64(s as i64)
    }
}

impl From<f32> for Value {
    fn from(s: f32) -> Self {
        Value::F64(s as f64)
    }
}
impl From<f64> for Value {
    fn from(s: f64) -> Self {
        Value::F64(s)
    }
}

impl From<Symbol> for Value {
    fn from(s: Symbol) -> Self {
        Value::Symbol(RcRef::new(s))
    }
}

impl From<BigInt> for Value {
    fn from(s: BigInt) -> Self {
        Value::BigInt(RcRef::new(s))
    }
}
impl From<BigUint> for Value {
    fn from(s: BigUint) -> Self {
        s.to_bigint().unwrap().into()
    }
}

impl From<Complex64> for Value {
    fn from(s: Complex64) -> Self {
        Value::J64(RcRef::new(s))
    }
}




pub type NativeFunction = fn() -> Value;





pub type ObjectRef = RcRef<Object>;

impl fmt::Display for ObjectRef {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{:?}", self)
    }
}


#[derive(Debug, Clone)]
pub enum ObjectKind {
    // Normal,     // hasConstructor() == false && isCallable() == false
    Function,      // isCallable() == true && hasConstructor() == true || false
    ArrowFunction, // isCallable() == true && hasConstructor() == false
    Instance,      // hasConstructor() == true
}




pub struct Function {
    inner: ObjectRef,
}

// hasConstructor == true
pub struct Class {
    inner: ObjectRef,
}

// hasConstructor
pub struct Instance {
    inner: ObjectRef,
}

const PROP_PROTOTYPE: &'static str = "prototype";
const PROP_NAME: &'static str      = "name";
const PROP_LENGTH: &'static str    = "length";

// IsConstructor
// IsCallable

#[derive(Debug, Clone)]
pub struct BaseObject {
    pub properties: HashMap<PropertyKey, Property>,
    pub is_frozen: bool,
    pub is_sealed: bool,
    pub is_extensible: bool,
    pub kind: ObjectKind,
}


#[derive(Debug, Clone)]
pub struct Object {
    pub properties: HashMap<PropertyKey, Property>,
    pub is_frozen: bool,
    pub is_sealed: bool,
    pub is_extensible: bool,
    pub kind: ObjectKind,
}

impl PartialEq for Object {
    fn eq(&self, other: &Object) -> bool {
        false
    }
}
impl PartialEq for ObjectRef {
    fn eq(&self, other: &ObjectRef) -> bool {
        false
    }
}
impl Eq for Object { }
impl Eq for ObjectRef { }


#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum PropertyKey {
    String(String),
    Symbol(Symbol),
}


#[derive(Debug, Clone)]
pub struct Property {
    pub descriptor: PropertyDescriptor,
    pub enumerable: bool,
    pub configurable: bool,
}

#[derive(Debug, Clone)]
pub enum PropertyDescriptor {
    Data(DataPropertyDescriptor),
    Accessor(AccessorPropertyDescriptor),
}

#[derive(Debug, Clone)]
pub struct DataPropertyDescriptor {
    pub value: Value, // NOTE: Any ECMAScript Value
    pub writable: bool,
}

#[derive(Debug, Clone)]
pub struct AccessorPropertyDescriptor {
    pub get: Value,  // WARN: Value::Undefined || Value::Object<+ Callable>
    pub set: Value,  // WARN: Value::Undefined || Value::Object<+ Callable>
}

impl Object {
    pub fn isCallable(&self) -> bool {
        unimplemented!()
    }

    pub fn IsConstructor(&self) -> bool {
        unimplemented!()
    }

    pub fn call(&mut self) -> Result<(), ()> {
        unimplemented!()
    }

    pub fn new(&mut self) -> Result<(), ()> {
        unimplemented!()
    }

}