| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // the different IC states and that both the runtime system and the generated | 32 // the different IC states and that both the runtime system and the generated |
| 33 // IC code is tested. | 33 // IC code is tested. |
| 34 function RunTests() { | 34 function RunTests() { |
| 35 for (var i = 0; i < 10; i++) { | 35 for (var i = 0; i < 10; i++) { |
| 36 assertEquals('object', 'xxx'.TypeOfThis()); | 36 assertEquals('object', 'xxx'.TypeOfThis()); |
| 37 assertEquals('object', true.TypeOfThis(2,3)); | 37 assertEquals('object', true.TypeOfThis(2,3)); |
| 38 assertEquals('object', false.TypeOfThis()); | 38 assertEquals('object', false.TypeOfThis()); |
| 39 assertEquals('object', (42).TypeOfThis()); | 39 assertEquals('object', (42).TypeOfThis()); |
| 40 assertEquals('object', (3.14).TypeOfThis()); | 40 assertEquals('object', (3.14).TypeOfThis()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 for (var i = 0; i < 10; i++) { | 43 for (var i = 0; i < 10; i++) { |
| 44 assertEquals('object', 'xxx'['TypeOfThis']()); | 44 assertEquals('object', 'xxx'['TypeOfThis']()); |
| 45 assertEquals('object', true['TypeOfThis']()); | 45 assertEquals('object', true['TypeOfThis']()); |
| 46 assertEquals('object', false['TypeOfThis']()); | 46 assertEquals('object', false['TypeOfThis']()); |
| 47 assertEquals('object', (42)['TypeOfThis']()); | 47 assertEquals('object', (42)['TypeOfThis']()); |
| 48 assertEquals('object', (3.14)['TypeOfThis']()); | 48 assertEquals('object', (3.14)['TypeOfThis']()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 function CallTypeOfThis(obj) { | 51 function CallTypeOfThis(obj) { |
| 52 assertEquals('object', obj.TypeOfThis()); | 52 assertEquals('object', obj.TypeOfThis()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 for (var i = 0; i < 10; i++) { | 55 for (var i = 0; i < 10; i++) { |
| 56 CallTypeOfThis('xxx'); | 56 CallTypeOfThis('xxx'); |
| 57 CallTypeOfThis(true); | 57 CallTypeOfThis(true); |
| 58 CallTypeOfThis(false); | 58 CallTypeOfThis(false); |
| 59 CallTypeOfThis(42); | 59 CallTypeOfThis(42); |
| 60 CallTypeOfThis(3.14); | 60 CallTypeOfThis(3.14); |
| 61 } | 61 } |
| 62 | 62 |
| 63 function TestWithWith(obj) { | 63 function TestWithWith(obj) { |
| 64 with (obj) { | 64 with (obj) { |
| 65 for (var i = 0; i < 10; i++) { | 65 for (var i = 0; i < 10; i++) { |
| 66 assertEquals('object', TypeOfThis()); | 66 assertEquals('object', TypeOfThis()); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 TestWithWith('xxx'); | 71 TestWithWith('xxx'); |
| 72 TestWithWith(true); | 72 TestWithWith(true); |
| 73 TestWithWith(false); | 73 TestWithWith(false); |
| 74 TestWithWith(42); | 74 TestWithWith(42); |
| 75 TestWithWith(3.14); | 75 TestWithWith(3.14); |
| 76 | 76 |
| 77 for (var i = 0; i < 10; i++) { | 77 for (var i = 0; i < 10; i++) { |
| 78 assertEquals('object', true[7]()); | 78 assertEquals('object', true[7]()); |
| 79 assertEquals('object', false[7]()); | 79 assertEquals('object', false[7]()); |
| 80 assertEquals('object', (42)[7]()); | 80 assertEquals('object', (42)[7]()); |
| 81 assertEquals('object', (3.14)[7]()); | 81 assertEquals('object', (3.14)[7]()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 for (var i = 0; i < 10; i++) { | 84 for (var i = 0; i < 10; i++) { |
| 85 assertEquals('object', typeof 'xxx'.ObjectValueOf()); | 85 assertEquals('object', typeof 'xxx'.ObjectValueOf()); |
| 86 assertEquals('object', typeof true.ObjectValueOf()); | 86 assertEquals('object', typeof true.ObjectValueOf()); |
| 87 assertEquals('object', typeof false.ObjectValueOf()); | 87 assertEquals('object', typeof false.ObjectValueOf()); |
| 88 assertEquals('object', typeof (42).ObjectValueOf()); | 88 assertEquals('object', typeof (42).ObjectValueOf()); |
| 89 assertEquals('object', typeof (3.14).ObjectValueOf()); | 89 assertEquals('object', typeof (3.14).ObjectValueOf()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 for (var i = 0; i < 10; i++) { | 92 for (var i = 0; i < 10; i++) { |
| 93 assertEquals('[object String]', 'xxx'.ObjectToString()); | 93 assertEquals('[object String]', 'xxx'.ObjectToString()); |
| 94 assertEquals('[object Boolean]', true.ObjectToString()); | 94 assertEquals('[object Boolean]', true.ObjectToString()); |
| 95 assertEquals('[object Boolean]', false.ObjectToString()); | 95 assertEquals('[object Boolean]', false.ObjectToString()); |
| 96 assertEquals('[object Number]', (42).ObjectToString()); | 96 assertEquals('[object Number]', (42).ObjectToString()); |
| 97 assertEquals('[object Number]', (3.14).ObjectToString()); | 97 assertEquals('[object Number]', (3.14).ObjectToString()); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 function TypeOfThis() { return typeof this; } | 101 function TypeOfThis() { return typeof this; } |
| 102 | 102 |
| 103 // Test with normal setup of prototype. | 103 // Test with normal setup of prototype. |
| 104 String.prototype.TypeOfThis = TypeOfThis; | 104 String.prototype.TypeOfThis = TypeOfThis; |
| 105 Boolean.prototype.TypeOfThis = TypeOfThis; | 105 Boolean.prototype.TypeOfThis = TypeOfThis; |
| 106 Number.prototype.TypeOfThis = TypeOfThis; | 106 Number.prototype.TypeOfThis = TypeOfThis; |
| 107 Boolean.prototype[7] = TypeOfThis; | 107 Boolean.prototype[7] = TypeOfThis; |
| 108 Number.prototype[7] = TypeOfThis; | 108 Number.prototype[7] = TypeOfThis; |
| 109 | 109 |
| 110 String.prototype.ObjectValueOf = Object.prototype.valueOf; | 110 String.prototype.ObjectValueOf = Object.prototype.valueOf; |
| 111 Boolean.prototype.ObjectValueOf = Object.prototype.valueOf; | 111 Boolean.prototype.ObjectValueOf = Object.prototype.valueOf; |
| 112 Number.prototype.ObjectValueOf = Object.prototype.valueOf; | 112 Number.prototype.ObjectValueOf = Object.prototype.valueOf; |
| 113 | 113 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 assertEquals('object', TypeOfThis.apply(42, [])); | 155 assertEquals('object', TypeOfThis.apply(42, [])); |
| 156 assertEquals('object', TypeOfThis.apply(3.14, [])); | 156 assertEquals('object', TypeOfThis.apply(3.14, [])); |
| 157 | 157 |
| 158 // According to ES3 15.3.4.3 the this value passed to Function.prototyle.call | 158 // According to ES3 15.3.4.3 the this value passed to Function.prototyle.call |
| 159 // should wrapped. According to ES5 it should not. | 159 // should wrapped. According to ES5 it should not. |
| 160 assertEquals('object', TypeOfThis.call('xxx')); | 160 assertEquals('object', TypeOfThis.call('xxx')); |
| 161 assertEquals('object', TypeOfThis.call(true)); | 161 assertEquals('object', TypeOfThis.call(true)); |
| 162 assertEquals('object', TypeOfThis.call(false)); | 162 assertEquals('object', TypeOfThis.call(false)); |
| 163 assertEquals('object', TypeOfThis.call(42)); | 163 assertEquals('object', TypeOfThis.call(42)); |
| 164 assertEquals('object', TypeOfThis.call(3.14)); | 164 assertEquals('object', TypeOfThis.call(3.14)); |
| OLD | NEW |