Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/mjsunit/value-wrapper.js

Issue 542112: Fix some usage of "this" in builtins (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x64/codegen-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
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 // When calling user-defined functions on strings, booleans or 28 // When calling user-defined functions on strings, booleans or
29 // numbers, we should create a wrapper object. 29 // numbers, we should create a wrapper object.
30 30
31 // When running the tests use loops to ensure that the call site moves through
32 // the different IC states and that both the runtime system and the generated
33 // IC code is tested.
31 function RunTests() { 34 function RunTests() {
32 for (var i = 0; i < 10; i++) { 35 for (var i = 0; i < 10; i++) {
33 assertEquals('object', 'xxx'.TypeOfThis()); 36 assertEquals('object', 'xxx'.TypeOfThis());
34 assertEquals('object', true.TypeOfThis(2,3)); 37 assertEquals('object', true.TypeOfThis(2,3));
35 assertEquals('object', false.TypeOfThis()); 38 assertEquals('object', false.TypeOfThis());
36 assertEquals('object', (42).TypeOfThis()); 39 assertEquals('object', (42).TypeOfThis());
37 assertEquals('object', (3.14).TypeOfThis()); 40 assertEquals('object', (3.14).TypeOfThis());
38 } 41 }
39 42
40 for (var i = 0; i < 10; i++) { 43 for (var i = 0; i < 10; i++) {
(...skipping 29 matching lines...) Expand all
70 TestWithWith(false); 73 TestWithWith(false);
71 TestWithWith(42); 74 TestWithWith(42);
72 TestWithWith(3.14); 75 TestWithWith(3.14);
73 76
74 for (var i = 0; i < 10; i++) { 77 for (var i = 0; i < 10; i++) {
75 assertEquals('object', true[7]()); 78 assertEquals('object', true[7]());
76 assertEquals('object', false[7]()); 79 assertEquals('object', false[7]());
77 assertEquals('object', (42)[7]()); 80 assertEquals('object', (42)[7]());
78 assertEquals('object', (3.14)[7]()); 81 assertEquals('object', (3.14)[7]());
79 } 82 }
83
84 for (var i = 0; i < 10; i++) {
85 assertEquals('object', typeof 'xxx'.ObjectValueOf());
86 assertEquals('object', typeof true.ObjectValueOf());
87 assertEquals('object', typeof false.ObjectValueOf());
88 assertEquals('object', typeof (42).ObjectValueOf());
89 assertEquals('object', typeof (3.14).ObjectValueOf());
90 }
91
92 for (var i = 0; i < 10; i++) {
93 assertEquals('[object String]', 'xxx'.ObjectToString());
94 assertEquals('[object Boolean]', true.ObjectToString());
95 assertEquals('[object Boolean]', false.ObjectToString());
96 assertEquals('[object Number]', (42).ObjectToString());
97 assertEquals('[object Number]', (3.14).ObjectToString());
98 }
80 } 99 }
81 100
82 function TypeOfThis() { return typeof this; } 101 function TypeOfThis() { return typeof this; }
83 102
84 // Test with normal setup of prototype. 103 // Test with normal setup of prototype.
85 String.prototype.TypeOfThis = TypeOfThis; 104 String.prototype.TypeOfThis = TypeOfThis;
86 Boolean.prototype.TypeOfThis = TypeOfThis; 105 Boolean.prototype.TypeOfThis = TypeOfThis;
87 Number.prototype.TypeOfThis = TypeOfThis; 106 Number.prototype.TypeOfThis = TypeOfThis;
88 Boolean.prototype[7] = TypeOfThis; 107 Boolean.prototype[7] = TypeOfThis;
89 Number.prototype[7] = TypeOfThis; 108 Number.prototype[7] = TypeOfThis;
90 109
110 String.prototype.ObjectValueOf = Object.prototype.valueOf;
111 Boolean.prototype.ObjectValueOf = Object.prototype.valueOf;
112 Number.prototype.ObjectValueOf = Object.prototype.valueOf;
113
114 String.prototype.ObjectToString = Object.prototype.toString;
115 Boolean.prototype.ObjectToString = Object.prototype.toString;
116 Number.prototype.ObjectToString = Object.prototype.toString;
91 117
92 RunTests(); 118 RunTests();
93 119
94 // Run test after properties have been set to a different value. 120 // Run test after properties have been set to a different value.
95 String.prototype.TypeOfThis = 'x'; 121 String.prototype.TypeOfThis = 'x';
96 Boolean.prototype.TypeOfThis = 'x'; 122 Boolean.prototype.TypeOfThis = 'x';
97 Number.prototype.TypeOfThis = 'x'; 123 Number.prototype.TypeOfThis = 'x';
98 Boolean.prototype[7] = 'x'; 124 Boolean.prototype[7] = 'x';
99 Number.prototype[7] = 'x'; 125 Number.prototype[7] = 'x';
100 126
(...skipping 28 matching lines...) Expand all
129 assertEquals('object', TypeOfThis.apply(42, [])); 155 assertEquals('object', TypeOfThis.apply(42, []));
130 assertEquals('object', TypeOfThis.apply(3.14, [])); 156 assertEquals('object', TypeOfThis.apply(3.14, []));
131 157
132 // 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
133 // should wrapped. According to ES5 it should not. 159 // should wrapped. According to ES5 it should not.
134 assertEquals('object', TypeOfThis.call('xxx')); 160 assertEquals('object', TypeOfThis.call('xxx'));
135 assertEquals('object', TypeOfThis.call(true)); 161 assertEquals('object', TypeOfThis.call(true));
136 assertEquals('object', TypeOfThis.call(false)); 162 assertEquals('object', TypeOfThis.call(false));
137 assertEquals('object', TypeOfThis.call(42)); 163 assertEquals('object', TypeOfThis.call(42));
138 assertEquals('object', TypeOfThis.call(3.14)); 164 assertEquals('object', TypeOfThis.call(3.14));
OLDNEW
« no previous file with comments | « src/x64/codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698