summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js
blob: c2b1403d3095b9225f004f79a256d6a986a89056 (plain)
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
load(libdir + 'asserts.js');
load(libdir + 'iteration.js');

function f(v)
{
  if (v + "")
    ({} = v);
}

f(true);
f({});
assertThrowsInstanceOf(() => f(null), TypeError);
assertThrowsInstanceOf(() => f(undefined), TypeError);

function g(v)
{
  if (v + "")
    ({} = v);
}

g(true);
g({});
assertThrowsInstanceOf(() => g(undefined), TypeError);
assertThrowsInstanceOf(() => g(null), TypeError);

function h(v)
{
  if (v + "")
    ([] = v);
}

h([true]);
h("foo");
assertThrowsInstanceOf(() => h(undefined), TypeError);
assertThrowsInstanceOf(() => h(null), TypeError);

Object.defineProperty(Boolean.prototype, "v",
                      { get() { "use strict"; return typeof this; },
                        enumerable: true,
                        configurable: true });

Object.defineProperty(Number.prototype, "v",
                      { get() { "use strict"; return typeof this; },
                        enumerable: true,
                        configurable: true });

Object.defineProperty(String.prototype, "v",
                      { get() { "use strict"; return typeof this; },
                        enumerable: true,
                        configurable: true });

Object.defineProperty(Symbol.prototype, "v",
                      { get() { "use strict"; return typeof this; },
                        enumerable: true,
                        configurable: true });

function primitiveThisSupported()
{
  return 3.14.custom === "number";
}

function primitiveThisTests()
{
  function f(v)
  {
    var type = typeof v;

    ({ v } = v);

    assertEq(v, type);
  }

  f(true);
  f(3.14);
  f(72);
  f("ohai");
  f(Symbol.iterator);

  assertThrowsInstanceOf(() => f(undefined), TypeError);
  assertThrowsInstanceOf(() => f(null), TypeError);

  function g(v)
  {
    var type = typeof v;

    ({ v } = v);

    assertEq(v, type);
  }

  g(true);
  g(3.14);
  g(72);
  g("ohai");
  g(Symbol.iterator);

  assertThrowsInstanceOf(() => g(null), TypeError);
  assertThrowsInstanceOf(() => g(undefined), TypeError);
}
if (primitiveThisSupported())
  primitiveThisTests();

// Ensure the internal implementation of destructuring object pattern
// assignment -- using a self-hosted intrinsic function -- works even when lazy
// standard class initialization hasn't occurred.  Unfortunately we can't use
// |newGlobal()| because that method eagerly initializes standard classes.
evalcx("({} = 1);", evalcx("lazy"));