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

Side by Side Diff: src/runtime.js

Issue 1109223004: [strong] Disallow implicit conversions for add (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « src/ic/ic.cc ('k') | test/mjsunit/strong/implicit-conversions.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This files contains runtime support implemented in JavaScript. 5 // This files contains runtime support implemented in JavaScript.
6 6
7 // CAUTION: Some of the functions specified in this file are called 7 // CAUTION: Some of the functions specified in this file are called
8 // directly from compiled code. These are the functions with names in 8 // directly from compiled code. These are the functions with names in
9 // ALL CAPS. The compiled code passes the first argument in 'this'. 9 // ALL CAPS. The compiled code passes the first argument in 'this'.
10 10
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 if (IS_STRING(a)) { 153 if (IS_STRING(a)) {
154 return %_StringAdd(a, %ToString(b)); 154 return %_StringAdd(a, %ToString(b));
155 } else if (IS_STRING(b)) { 155 } else if (IS_STRING(b)) {
156 return %_StringAdd(%NonStringToString(a), b); 156 return %_StringAdd(%NonStringToString(a), b);
157 } else { 157 } else {
158 return %NumberAdd(%ToNumber(a), %ToNumber(b)); 158 return %NumberAdd(%ToNumber(a), %ToNumber(b));
159 } 159 }
160 } 160 }
161 161
162 162
163 //ECMA-262, section 11.6.1, page 50.
Dmitry Lomov (no reviews) 2015/04/30 08:43:59 This comment does not apply anymore I guess.
conradw 2015/04/30 09:19:33 Changed this and similar examples in other places.
164 function ADD_STRONG(x) {
165 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x);
166 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x);
167
168 throw %MakeTypeError('strong_implicit_cast');
169 }
170
171
163 // Left operand (this) is already a string. 172 // Left operand (this) is already a string.
164 function STRING_ADD_LEFT(y) { 173 function STRING_ADD_LEFT(y) {
165 if (!IS_STRING(y)) { 174 if (!IS_STRING(y)) {
166 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) { 175 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) {
167 y = %_ValueOf(y); 176 y = %_ValueOf(y);
168 } else { 177 } else {
169 y = IS_NUMBER(y) 178 y = IS_NUMBER(y)
170 ? %_NumberToString(y) 179 ? %_NumberToString(y)
171 : %ToString(%ToPrimitive(y, NO_HINT)); 180 : %ToString(%ToPrimitive(y, NO_HINT));
172 } 181 }
173 } 182 }
174 return %_StringAdd(this, y); 183 return %_StringAdd(this, y);
175 } 184 }
176 185
177 186
187 //Left operand (this) is already a string.
188 function STRING_ADD_LEFT_STRONG(y) {
189 if (IS_STRING(y)) {
190 return %_StringAdd(this, y);
191 }
192 throw %MakeTypeError('strong_implicit_cast');
193 }
194
195
178 // Right operand (y) is already a string. 196 // Right operand (y) is already a string.
179 function STRING_ADD_RIGHT(y) { 197 function STRING_ADD_RIGHT(y) {
180 var x = this; 198 var x = this;
181 if (!IS_STRING(x)) { 199 if (!IS_STRING(x)) {
182 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) { 200 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) {
183 x = %_ValueOf(x); 201 x = %_ValueOf(x);
184 } else { 202 } else {
185 x = IS_NUMBER(x) 203 x = IS_NUMBER(x)
186 ? %_NumberToString(x) 204 ? %_NumberToString(x)
187 : %ToString(%ToPrimitive(x, NO_HINT)); 205 : %ToString(%ToPrimitive(x, NO_HINT));
188 } 206 }
189 } 207 }
190 return %_StringAdd(x, y); 208 return %_StringAdd(x, y);
191 } 209 }
192 210
193 211
212 //Right operand (y) is already a string.
213 function STRING_ADD_RIGHT_STRONG(y) {
214 if (IS_STRING(this)) {
215 return %_StringAdd(this, y);
216 }
217 throw %MakeTypeError('strong_implicit_cast');
218 }
219
220
194 // ECMA-262, section 11.6.2, page 50. 221 // ECMA-262, section 11.6.2, page 50.
195 function SUB(y) { 222 function SUB(y) {
196 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this); 223 var x = IS_NUMBER(this) ? this : %NonNumberToNumber(this);
197 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y); 224 if (!IS_NUMBER(y)) y = %NonNumberToNumber(y);
198 return %NumberSub(x, y); 225 return %NumberSub(x, y);
199 } 226 }
200 227
201 228
202 // ECMA-262, section 11.6.2, page 50. 229 // ECMA-262, section 11.6.2, page 50.
203 function SUB_STRONG(y) { 230 function SUB_STRONG(y) {
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 893
867 /* ----------------------------------------------- 894 /* -----------------------------------------------
868 - - - J a v a S c r i p t S t u b s - - - 895 - - - J a v a S c r i p t S t u b s - - -
869 ----------------------------------------------- 896 -----------------------------------------------
870 */ 897 */
871 898
872 function STRING_LENGTH_STUB(name) { 899 function STRING_LENGTH_STUB(name) {
873 var receiver = this; // implicit first parameter 900 var receiver = this; // implicit first parameter
874 return %_StringGetLength(%_JSValueGetValue(receiver)); 901 return %_StringGetLength(%_JSValueGetValue(receiver));
875 } 902 }
OLDNEW
« no previous file with comments | « src/ic/ic.cc ('k') | test/mjsunit/strong/implicit-conversions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698