OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --allow-natives-syntax | 28 // Mimics assert module in node. |
29 | 29 |
30 (function DeoptimizeArgCallFunctionGeneric() { | 30 function compose(message1, message2) { |
31 var a = []; | 31 return message2 ? message1 + ': ' + message2 : message1 |
| 32 } |
32 | 33 |
33 function f1(method, array, elem, deopt) { | 34 function fail(actual, expected, message, operator) { |
34 assertEquals('push', method); | 35 var e = Error(compose('FAIL', message) + |
| 36 ': (' + actual + ' ' + operator + ' ' + expected + ') should hold'); |
| 37 fails.push(e); |
| 38 throw e; |
| 39 } |
| 40 |
| 41 function ok(value, message) { |
| 42 if (!value) { |
| 43 throw Error(compose('FAIL', + message) + ': value = ' + value); |
35 } | 44 } |
| 45 } |
36 | 46 |
37 function f2() { } | 47 function equal(actual, expected, message) { |
| 48 if (!(expected == actual)) { |
| 49 fail(actual, expected, message, '=='); |
| 50 } |
| 51 } |
38 | 52 |
39 function bar(x, deopt, f) { | 53 function notEqual(actual, expected, message) { |
40 f('push', a, [x], deopt + 0); | 54 if (!(expected != actual)) { |
| 55 fail(actual, expected, message, '!='); |
41 } | 56 } |
| 57 } |
42 | 58 |
43 function foo() { return bar(arguments[0], arguments[1], arguments[2]); } | 59 function strictEqual(actual, expected, message) { |
44 function baz(f, deopt) { return foo("x", deopt, f); } | 60 if (!(expected === actual)) { |
| 61 fail(actual, expected, message, '==='); |
| 62 } |
| 63 } |
45 | 64 |
46 baz(f1, 0); | 65 function notStrictEqual(actual, expected, message) { |
47 baz(f2, 0); | 66 if (!(expected !== actual)) { |
48 %OptimizeFunctionOnNextCall(baz); | 67 fail(actual, expected, message, '!=='); |
49 baz(f1, "deopt"); | 68 } |
50 })(); | 69 } |
51 | 70 |
| 71 function assert(value, message) { |
| 72 return ok(value, message); |
| 73 } |
52 | 74 |
53 (function DeoptimizeArgGlobalFunctionGeneric() { | 75 function notImplemented() { |
54 var a = []; | 76 throw Error('FAIL: This assertion function is not yet implemented.'); |
| 77 } |
55 | 78 |
56 var f1; | 79 function clear() { |
| 80 this.fails = []; |
| 81 } |
57 | 82 |
58 f1 = function(method, array, elem, deopt) { | 83 assert.fail = fail; |
59 assertEquals('push', method); | 84 assert.ok = ok; |
60 } | 85 assert.equal = equal; |
| 86 assert.notEqual = notEqual; |
| 87 assert.deepEqual = notImplemented; |
| 88 assert.notDeepEqual = notImplemented; |
| 89 assert.strictEqual = strictEqual; |
| 90 assert.notStrictEqual = notStrictEqual; |
| 91 assert.throws = notImplemented; |
| 92 assert.doesNotThrow = notImplemented; |
| 93 assert.ifError = notImplemented; |
61 | 94 |
62 function bar(x, deopt, f) { | 95 assert.clear = clear; |
63 f1('push', a, [x], deopt + 0); | |
64 } | |
65 | 96 |
66 function foo() { return bar(arguments[0], arguments[1]); } | 97 exports = assert; |
67 function baz(deopt) { return foo("x", deopt); } | |
68 | |
69 baz(0); | |
70 baz(0); | |
71 %OptimizeFunctionOnNextCall(baz); | |
72 baz("deopt"); | |
73 })(); | |
74 | |
75 | |
76 (function DeoptimizeArgCallFunctionRuntime() { | |
77 var a = []; | |
78 | |
79 var f1; | |
80 | |
81 f1 = function(method, array, elem, deopt) { | |
82 assertEquals('push', method); | |
83 } | |
84 | |
85 function bar(x, deopt) { | |
86 %_CallFunction(null, 'push', [x][0], ((deopt + 0), 1), f1); | |
87 } | |
88 | |
89 function foo() { return bar(arguments[0], arguments[1]); } | |
90 function baz(deopt) { return foo(0, deopt); } | |
91 | |
92 baz(0); | |
93 baz(0); | |
94 %OptimizeFunctionOnNextCall(baz); | |
95 baz("deopt"); | |
96 })(); | |
OLD | NEW |