summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/compiler/receiver-conversion.js
blob: c4f8bf9c4ade132fe61d91566c5a5ef2f6290645 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax

// This test suite checks that the receiver value (i.e. the 'this' binding) is
// correctly converted even when the callee function is inlined. This behavior
// is specified by ES6, section 9.2.1.2 "OrdinaryCallBindThis".

var global = this;
function test(outer, inner, check) {
  %PrepareFunctionForOptimization(outer);
  check(outer());
  check(outer());
  %OptimizeFunctionOnNextCall(outer);
  check(outer());
}


// -----------------------------------------------------------------------------
// Test undefined in sloppy mode.
(function UndefinedSloppy() {
  function check(x) {
    assertEquals("object", typeof x);
    assertSame(global, x);
  }
  function inner(x) {
    return this;
  }
  function outer() {
    return sloppy();
  }
  global.sloppy = inner;
  test(outer, inner, check);
})();


// -----------------------------------------------------------------------------
// Test undefined in strict mode.
(function UndefinedStrict() {
  function check(x) {
    assertEquals("undefined", typeof x);
    assertSame(undefined, x);
  }
  function inner(x) {
    "use strict";
    return this;
  }
  function outer() {
    return strict();
  }
  global.strict = inner;
  test(outer, inner, check);
})();


// -----------------------------------------------------------------------------
// Test primitive number in sloppy mode.
(function NumberSloppy() {
  function check(x) {
    assertEquals("object", typeof x);
    assertInstanceof(x, Number);
  }
  function inner(x) {
    return this;
  }
  function outer() {
    return (0).sloppy();
  }
  Number.prototype.sloppy = inner;
  test(outer, inner, check);
})();


// -----------------------------------------------------------------------------
// Test primitive number in strict mode.
(function NumberStrict() {
  function check(x) {
    assertEquals("number", typeof x);
    assertSame(0, x);
  }
  function inner(x) {
    "use strict";
    return this;
  }
  function outer() {
    return (0).strict();
  }
  Number.prototype.strict = inner;
  test(outer, inner, check);
})();


// -----------------------------------------------------------------------------
// Test primitive string in sloppy mode.
(function StringSloppy() {
  function check(x) {
    assertEquals("object", typeof x);
    assertInstanceof(x, String);
  }
  function inner(x) {
    return this;
  }
  function outer() {
    return ("s").sloppy();
  }
  String.prototype.sloppy = inner;
  test(outer, inner, check);
})();


// -----------------------------------------------------------------------------
// Test primitive string in strict mode.
(function StringStrict() {
  function check(x) {
    assertEquals("string", typeof x);
    assertSame("s", x);
  }
  function inner(x) {
    "use strict";
    return this;
  }
  function outer() {
    return ("s").strict();
  }
  String.prototype.strict = inner;
  test(outer, inner, check);
})();