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

Side by Side Diff: src/runtime.js

Issue 1306993003: Call JS functions via native context instead of js builtins object. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 3 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/regexp.js ('k') | src/runtime/runtime.h » ('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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 var x = this; 48 var x = this;
49 49
50 while (true) { 50 while (true) {
51 if (IS_NUMBER(x)) { 51 if (IS_NUMBER(x)) {
52 while (true) { 52 while (true) {
53 if (IS_NUMBER(y)) return %NumberEquals(x, y); 53 if (IS_NUMBER(y)) return %NumberEquals(x, y);
54 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal 54 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
55 if (!IS_SPEC_OBJECT(y)) { 55 if (!IS_SPEC_OBJECT(y)) {
56 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal 56 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
57 // String or boolean. 57 // String or boolean.
58 return %NumberEquals(x, %$toNumber(y)); 58 return %NumberEquals(x, %to_number_fun(y));
59 } 59 }
60 y = %$toPrimitive(y, NO_HINT); 60 y = %to_primitive(y, NO_HINT);
61 } 61 }
62 } else if (IS_STRING(x)) { 62 } else if (IS_STRING(x)) {
63 while (true) { 63 while (true) {
64 if (IS_STRING(y)) return %StringEquals(x, y); 64 if (IS_STRING(y)) return %StringEquals(x, y);
65 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); 65 if (IS_NUMBER(y)) return %NumberEquals(%to_number_fun(x), y);
66 if (IS_BOOLEAN(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); 66 if (IS_BOOLEAN(y)) return %NumberEquals(%to_number_fun(x), %to_number_fu n(y));
67 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal 67 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
68 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal 68 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
69 y = %$toPrimitive(y, NO_HINT); 69 y = %to_primitive(y, NO_HINT);
70 } 70 }
71 } else if (IS_SYMBOL(x)) { 71 } else if (IS_SYMBOL(x)) {
72 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1; 72 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1;
73 return 1; // not equal 73 return 1; // not equal
74 } else if (IS_BOOLEAN(x)) { 74 } else if (IS_BOOLEAN(x)) {
75 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; 75 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1;
76 if (IS_NULL_OR_UNDEFINED(y)) return 1; 76 if (IS_NULL_OR_UNDEFINED(y)) return 1;
77 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); 77 if (IS_NUMBER(y)) return %NumberEquals(%to_number_fun(x), y);
78 if (IS_STRING(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); 78 if (IS_STRING(y)) return %NumberEquals(%to_number_fun(x), %to_number_fun(y ));
79 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal 79 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
80 // y is object. 80 // y is object.
81 x = %$toNumber(x); 81 x = %to_number_fun(x);
82 y = %$toPrimitive(y, NO_HINT); 82 y = %to_primitive(y, NO_HINT);
83 } else if (IS_NULL_OR_UNDEFINED(x)) { 83 } else if (IS_NULL_OR_UNDEFINED(x)) {
84 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; 84 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1;
85 } else if (IS_SIMD_VALUE(x)) { 85 } else if (IS_SIMD_VALUE(x)) {
86 if (!IS_SIMD_VALUE(y)) return 1; // not equal 86 if (!IS_SIMD_VALUE(y)) return 1; // not equal
87 return %SimdEquals(x, y); 87 return %SimdEquals(x, y);
88 } else { 88 } else {
89 // x is an object. 89 // x is an object.
90 if (IS_SPEC_OBJECT(y)) return %_ObjectEquals(x, y) ? 0 : 1; 90 if (IS_SPEC_OBJECT(y)) return %_ObjectEquals(x, y) ? 0 : 1;
91 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal 91 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
92 if (IS_BOOLEAN(y)) { 92 if (IS_BOOLEAN(y)) {
93 y = %$toNumber(y); 93 y = %to_number_fun(y);
94 } else if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) { 94 } else if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) {
95 return 1; // not equal 95 return 1; // not equal
96 } 96 }
97 x = %$toPrimitive(x, NO_HINT); 97 x = %to_primitive(x, NO_HINT);
98 } 98 }
99 } 99 }
100 } 100 }
101 101
102 102
103 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as 103 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
104 // the result when either (or both) the operands are NaN. 104 // the result when either (or both) the operands are NaN.
105 function COMPARE(x, ncr) { 105 function COMPARE(x, ncr) {
106 var left; 106 var left;
107 var right; 107 var right;
108 // Fast cases for string, numbers and undefined compares. 108 // Fast cases for string, numbers and undefined compares.
109 if (IS_STRING(this)) { 109 if (IS_STRING(this)) {
110 if (IS_STRING(x)) return %_StringCompare(this, x); 110 if (IS_STRING(x)) return %_StringCompare(this, x);
111 if (IS_UNDEFINED(x)) return ncr; 111 if (IS_UNDEFINED(x)) return ncr;
112 left = this; 112 left = this;
113 } else if (IS_NUMBER(this)) { 113 } else if (IS_NUMBER(this)) {
114 if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr); 114 if (IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
115 if (IS_UNDEFINED(x)) return ncr; 115 if (IS_UNDEFINED(x)) return ncr;
116 left = this; 116 left = this;
117 } else if (IS_UNDEFINED(this)) { 117 } else if (IS_UNDEFINED(this)) {
118 if (!IS_UNDEFINED(x)) { 118 if (!IS_UNDEFINED(x)) {
119 %$toPrimitive(x, NUMBER_HINT); 119 %to_primitive(x, NUMBER_HINT);
120 } 120 }
121 return ncr; 121 return ncr;
122 } else if (IS_UNDEFINED(x)) { 122 } else if (IS_UNDEFINED(x)) {
123 %$toPrimitive(this, NUMBER_HINT); 123 %to_primitive(this, NUMBER_HINT);
124 return ncr; 124 return ncr;
125 } else { 125 } else {
126 left = %$toPrimitive(this, NUMBER_HINT); 126 left = %to_primitive(this, NUMBER_HINT);
127 } 127 }
128 128
129 right = %$toPrimitive(x, NUMBER_HINT); 129 right = %to_primitive(x, NUMBER_HINT);
130 if (IS_STRING(left) && IS_STRING(right)) { 130 if (IS_STRING(left) && IS_STRING(right)) {
131 return %_StringCompare(left, right); 131 return %_StringCompare(left, right);
132 } else { 132 } else {
133 var left_number = %$toNumber(left); 133 var left_number = %to_number_fun(left);
134 var right_number = %$toNumber(right); 134 var right_number = %to_number_fun(right);
135 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr; 135 if (NUMBER_IS_NAN(left_number) || NUMBER_IS_NAN(right_number)) return ncr;
136 return %NumberCompare(left_number, right_number, ncr); 136 return %NumberCompare(left_number, right_number, ncr);
137 } 137 }
138 } 138 }
139 139
140 // Strong mode COMPARE throws if an implicit conversion would be performed 140 // Strong mode COMPARE throws if an implicit conversion would be performed
141 function COMPARE_STRONG(x, ncr) { 141 function COMPARE_STRONG(x, ncr) {
142 if (IS_STRING(this) && IS_STRING(x)) return %_StringCompare(this, x); 142 if (IS_STRING(this) && IS_STRING(x)) return %_StringCompare(this, x);
143 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberCompare(this, x, ncr); 143 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
144 144
145 throw %MakeTypeError(kStrongImplicitConversion); 145 throw %make_type_error(kStrongImplicitConversion);
146 } 146 }
147 147
148 148
149 149
150 /* ----------------------------------- 150 /* -----------------------------------
151 - - - A r i t h m e t i c - - - 151 - - - A r i t h m e t i c - - -
152 ----------------------------------- 152 -----------------------------------
153 */ 153 */
154 154
155 // ECMA-262, section 11.6.1, page 50. 155 // ECMA-262, section 11.6.1, page 50.
156 function ADD(x) { 156 function ADD(x) {
157 // Fast case: Check for number operands and do the addition. 157 // Fast case: Check for number operands and do the addition.
158 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); 158 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x);
159 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); 159 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x);
160 160
161 // Default implementation. 161 // Default implementation.
162 var a = %$toPrimitive(this, NO_HINT); 162 var a = %to_primitive(this, NO_HINT);
163 var b = %$toPrimitive(x, NO_HINT); 163 var b = %to_primitive(x, NO_HINT);
164 164
165 if (IS_STRING(a)) { 165 if (IS_STRING(a)) {
166 return %_StringAdd(a, %$toString(b)); 166 return %_StringAdd(a, %to_string_fun(b));
167 } else if (IS_STRING(b)) { 167 } else if (IS_STRING(b)) {
168 return %_StringAdd(%$nonStringToString(a), b); 168 return %_StringAdd(%non_string_to_string(a), b);
169 } else { 169 } else {
170 return %NumberAdd(%$toNumber(a), %$toNumber(b)); 170 return %NumberAdd(%to_number_fun(a), %to_number_fun(b));
171 } 171 }
172 } 172 }
173 173
174 174
175 // Strong mode ADD throws if an implicit conversion would be performed 175 // Strong mode ADD throws if an implicit conversion would be performed
176 function ADD_STRONG(x) { 176 function ADD_STRONG(x) {
177 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); 177 if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x);
178 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); 178 if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x);
179 179
180 throw %MakeTypeError(kStrongImplicitConversion); 180 throw %make_type_error(kStrongImplicitConversion);
181 } 181 }
182 182
183 183
184 // Left operand (this) is already a string. 184 // Left operand (this) is already a string.
185 function STRING_ADD_LEFT(y) { 185 function STRING_ADD_LEFT(y) {
186 if (!IS_STRING(y)) { 186 if (!IS_STRING(y)) {
187 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) { 187 if (IS_STRING_WRAPPER(y) && %_IsStringWrapperSafeForDefaultValueOf(y)) {
188 y = %_ValueOf(y); 188 y = %_ValueOf(y);
189 } else { 189 } else {
190 y = IS_NUMBER(y) 190 y = IS_NUMBER(y)
191 ? %_NumberToString(y) 191 ? %_NumberToString(y)
192 : %$toString(%$toPrimitive(y, NO_HINT)); 192 : %to_string_fun(%to_primitive(y, NO_HINT));
193 } 193 }
194 } 194 }
195 return %_StringAdd(this, y); 195 return %_StringAdd(this, y);
196 } 196 }
197 197
198 198
199 // Right operand (y) is already a string. 199 // Right operand (y) is already a string.
200 function STRING_ADD_RIGHT(y) { 200 function STRING_ADD_RIGHT(y) {
201 var x = this; 201 var x = this;
202 if (!IS_STRING(x)) { 202 if (!IS_STRING(x)) {
203 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) { 203 if (IS_STRING_WRAPPER(x) && %_IsStringWrapperSafeForDefaultValueOf(x)) {
204 x = %_ValueOf(x); 204 x = %_ValueOf(x);
205 } else { 205 } else {
206 x = IS_NUMBER(x) 206 x = IS_NUMBER(x)
207 ? %_NumberToString(x) 207 ? %_NumberToString(x)
208 : %$toString(%$toPrimitive(x, NO_HINT)); 208 : %to_string_fun(%to_primitive(x, NO_HINT));
209 } 209 }
210 } 210 }
211 return %_StringAdd(x, y); 211 return %_StringAdd(x, y);
212 } 212 }
213 213
214 214
215 // ECMA-262, section 11.6.2, page 50. 215 // ECMA-262, section 11.6.2, page 50.
216 function SUB(y) { 216 function SUB(y) {
217 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 217 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
218 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 218 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
219 return %NumberSub(x, y); 219 return %NumberSub(x, y);
220 } 220 }
221 221
222 222
223 // Strong mode SUB throws if an implicit conversion would be performed 223 // Strong mode SUB throws if an implicit conversion would be performed
224 function SUB_STRONG(y) { 224 function SUB_STRONG(y) {
225 if (IS_NUMBER(this) && IS_NUMBER(y)) { 225 if (IS_NUMBER(this) && IS_NUMBER(y)) {
226 return %NumberSub(this, y); 226 return %NumberSub(this, y);
227 } 227 }
228 throw %MakeTypeError(kStrongImplicitConversion); 228 throw %make_type_error(kStrongImplicitConversion);
229 } 229 }
230 230
231 231
232 // ECMA-262, section 11.5.1, page 48. 232 // ECMA-262, section 11.5.1, page 48.
233 function MUL(y) { 233 function MUL(y) {
234 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 234 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
235 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 235 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
236 return %NumberMul(x, y); 236 return %NumberMul(x, y);
237 } 237 }
238 238
239 239
240 // Strong mode MUL throws if an implicit conversion would be performed 240 // Strong mode MUL throws if an implicit conversion would be performed
241 function MUL_STRONG(y) { 241 function MUL_STRONG(y) {
242 if (IS_NUMBER(this) && IS_NUMBER(y)) { 242 if (IS_NUMBER(this) && IS_NUMBER(y)) {
243 return %NumberMul(this, y); 243 return %NumberMul(this, y);
244 } 244 }
245 throw %MakeTypeError(kStrongImplicitConversion); 245 throw %make_type_error(kStrongImplicitConversion);
246 } 246 }
247 247
248 248
249 // ECMA-262, section 11.5.2, page 49. 249 // ECMA-262, section 11.5.2, page 49.
250 function DIV(y) { 250 function DIV(y) {
251 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 251 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
252 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 252 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
253 return %NumberDiv(x, y); 253 return %NumberDiv(x, y);
254 } 254 }
255 255
256 256
257 // Strong mode DIV throws if an implicit conversion would be performed 257 // Strong mode DIV throws if an implicit conversion would be performed
258 function DIV_STRONG(y) { 258 function DIV_STRONG(y) {
259 if (IS_NUMBER(this) && IS_NUMBER(y)) { 259 if (IS_NUMBER(this) && IS_NUMBER(y)) {
260 return %NumberDiv(this, y); 260 return %NumberDiv(this, y);
261 } 261 }
262 throw %MakeTypeError(kStrongImplicitConversion); 262 throw %make_type_error(kStrongImplicitConversion);
263 } 263 }
264 264
265 265
266 // ECMA-262, section 11.5.3, page 49. 266 // ECMA-262, section 11.5.3, page 49.
267 function MOD(y) { 267 function MOD(y) {
268 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 268 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
269 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 269 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
270 return %NumberMod(x, y); 270 return %NumberMod(x, y);
271 } 271 }
272 272
273 273
274 // Strong mode MOD throws if an implicit conversion would be performed 274 // Strong mode MOD throws if an implicit conversion would be performed
275 function MOD_STRONG(y) { 275 function MOD_STRONG(y) {
276 if (IS_NUMBER(this) && IS_NUMBER(y)) { 276 if (IS_NUMBER(this) && IS_NUMBER(y)) {
277 return %NumberMod(this, y); 277 return %NumberMod(this, y);
278 } 278 }
279 throw %MakeTypeError(kStrongImplicitConversion); 279 throw %make_type_error(kStrongImplicitConversion);
280 } 280 }
281 281
282 282
283 /* ------------------------------------------- 283 /* -------------------------------------------
284 - - - B i t o p e r a t i o n s - - - 284 - - - B i t o p e r a t i o n s - - -
285 ------------------------------------------- 285 -------------------------------------------
286 */ 286 */
287 287
288 // ECMA-262, section 11.10, page 57. 288 // ECMA-262, section 11.10, page 57.
289 function BIT_OR(y) { 289 function BIT_OR(y) {
290 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 290 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
291 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 291 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
292 return %NumberOr(x, y); 292 return %NumberOr(x, y);
293 } 293 }
294 294
295 295
296 // Strong mode BIT_OR throws if an implicit conversion would be performed 296 // Strong mode BIT_OR throws if an implicit conversion would be performed
297 function BIT_OR_STRONG(y) { 297 function BIT_OR_STRONG(y) {
298 if (IS_NUMBER(this) && IS_NUMBER(y)) { 298 if (IS_NUMBER(this) && IS_NUMBER(y)) {
299 return %NumberOr(this, y); 299 return %NumberOr(this, y);
300 } 300 }
301 throw %MakeTypeError(kStrongImplicitConversion); 301 throw %make_type_error(kStrongImplicitConversion);
302 } 302 }
303 303
304 304
305 // ECMA-262, section 11.10, page 57. 305 // ECMA-262, section 11.10, page 57.
306 function BIT_AND(y) { 306 function BIT_AND(y) {
307 var x; 307 var x;
308 if (IS_NUMBER(this)) { 308 if (IS_NUMBER(this)) {
309 x = this; 309 x = this;
310 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 310 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
311 } else { 311 } else {
312 x = %$nonNumberToNumber(this); 312 x = %non_number_to_number(this);
313 // Make sure to convert the right operand to a number before 313 // Make sure to convert the right operand to a number before
314 // bailing out in the fast case, but after converting the 314 // bailing out in the fast case, but after converting the
315 // left operand. This ensures that valueOf methods on the right 315 // left operand. This ensures that valueOf methods on the right
316 // operand are always executed. 316 // operand are always executed.
317 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 317 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
318 // Optimize for the case where we end up AND'ing a value 318 // Optimize for the case where we end up AND'ing a value
319 // that doesn't convert to a number. This is common in 319 // that doesn't convert to a number. This is common in
320 // certain benchmarks. 320 // certain benchmarks.
321 if (NUMBER_IS_NAN(x)) return 0; 321 if (NUMBER_IS_NAN(x)) return 0;
322 } 322 }
323 return %NumberAnd(x, y); 323 return %NumberAnd(x, y);
324 } 324 }
325 325
326 326
327 // Strong mode BIT_AND throws if an implicit conversion would be performed 327 // Strong mode BIT_AND throws if an implicit conversion would be performed
328 function BIT_AND_STRONG(y) { 328 function BIT_AND_STRONG(y) {
329 if (IS_NUMBER(this) && IS_NUMBER(y)) { 329 if (IS_NUMBER(this) && IS_NUMBER(y)) {
330 return %NumberAnd(this, y); 330 return %NumberAnd(this, y);
331 } 331 }
332 throw %MakeTypeError(kStrongImplicitConversion); 332 throw %make_type_error(kStrongImplicitConversion);
333 } 333 }
334 334
335 335
336 // ECMA-262, section 11.10, page 57. 336 // ECMA-262, section 11.10, page 57.
337 function BIT_XOR(y) { 337 function BIT_XOR(y) {
338 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 338 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
339 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 339 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
340 return %NumberXor(x, y); 340 return %NumberXor(x, y);
341 } 341 }
342 342
343 343
344 // Strong mode BIT_XOR throws if an implicit conversion would be performed 344 // Strong mode BIT_XOR throws if an implicit conversion would be performed
345 function BIT_XOR_STRONG(y) { 345 function BIT_XOR_STRONG(y) {
346 if (IS_NUMBER(this) && IS_NUMBER(y)) { 346 if (IS_NUMBER(this) && IS_NUMBER(y)) {
347 return %NumberXor(this, y); 347 return %NumberXor(this, y);
348 } 348 }
349 throw %MakeTypeError(kStrongImplicitConversion); 349 throw %make_type_error(kStrongImplicitConversion);
350 } 350 }
351 351
352 352
353 // ECMA-262, section 11.7.1, page 51. 353 // ECMA-262, section 11.7.1, page 51.
354 function SHL(y) { 354 function SHL(y) {
355 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 355 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
356 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 356 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
357 return %NumberShl(x, y); 357 return %NumberShl(x, y);
358 } 358 }
359 359
360 360
361 // Strong mode SHL throws if an implicit conversion would be performed 361 // Strong mode SHL throws if an implicit conversion would be performed
362 function SHL_STRONG(y) { 362 function SHL_STRONG(y) {
363 if (IS_NUMBER(this) && IS_NUMBER(y)) { 363 if (IS_NUMBER(this) && IS_NUMBER(y)) {
364 return %NumberShl(this, y); 364 return %NumberShl(this, y);
365 } 365 }
366 throw %MakeTypeError(kStrongImplicitConversion); 366 throw %make_type_error(kStrongImplicitConversion);
367 } 367 }
368 368
369 369
370 // ECMA-262, section 11.7.2, page 51. 370 // ECMA-262, section 11.7.2, page 51.
371 function SAR(y) { 371 function SAR(y) {
372 var x; 372 var x;
373 if (IS_NUMBER(this)) { 373 if (IS_NUMBER(this)) {
374 x = this; 374 x = this;
375 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 375 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
376 } else { 376 } else {
377 x = %$nonNumberToNumber(this); 377 x = %non_number_to_number(this);
378 // Make sure to convert the right operand to a number before 378 // Make sure to convert the right operand to a number before
379 // bailing out in the fast case, but after converting the 379 // bailing out in the fast case, but after converting the
380 // left operand. This ensures that valueOf methods on the right 380 // left operand. This ensures that valueOf methods on the right
381 // operand are always executed. 381 // operand are always executed.
382 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 382 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
383 // Optimize for the case where we end up shifting a value 383 // Optimize for the case where we end up shifting a value
384 // that doesn't convert to a number. This is common in 384 // that doesn't convert to a number. This is common in
385 // certain benchmarks. 385 // certain benchmarks.
386 if (NUMBER_IS_NAN(x)) return 0; 386 if (NUMBER_IS_NAN(x)) return 0;
387 } 387 }
388 return %NumberSar(x, y); 388 return %NumberSar(x, y);
389 } 389 }
390 390
391 391
392 // Strong mode SAR throws if an implicit conversion would be performed 392 // Strong mode SAR throws if an implicit conversion would be performed
393 function SAR_STRONG(y) { 393 function SAR_STRONG(y) {
394 if (IS_NUMBER(this) && IS_NUMBER(y)) { 394 if (IS_NUMBER(this) && IS_NUMBER(y)) {
395 return %NumberSar(this, y); 395 return %NumberSar(this, y);
396 } 396 }
397 throw %MakeTypeError(kStrongImplicitConversion); 397 throw %make_type_error(kStrongImplicitConversion);
398 } 398 }
399 399
400 400
401 // ECMA-262, section 11.7.3, page 52. 401 // ECMA-262, section 11.7.3, page 52.
402 function SHR(y) { 402 function SHR(y) {
403 var x = IS_NUMBER(this) ? this : %$nonNumberToNumber(this); 403 var x = IS_NUMBER(this) ? this : %non_number_to_number(this);
404 if (!IS_NUMBER(y)) y = %$nonNumberToNumber(y); 404 if (!IS_NUMBER(y)) y = %non_number_to_number(y);
405 return %NumberShr(x, y); 405 return %NumberShr(x, y);
406 } 406 }
407 407
408 408
409 // Strong mode SHR throws if an implicit conversion would be performed 409 // Strong mode SHR throws if an implicit conversion would be performed
410 function SHR_STRONG(y) { 410 function SHR_STRONG(y) {
411 if (IS_NUMBER(this) && IS_NUMBER(y)) { 411 if (IS_NUMBER(this) && IS_NUMBER(y)) {
412 return %NumberShr(this, y); 412 return %NumberShr(this, y);
413 } 413 }
414 throw %MakeTypeError(kStrongImplicitConversion); 414 throw %make_type_error(kStrongImplicitConversion);
415 } 415 }
416 416
417 417
418 /* ----------------------------- 418 /* -----------------------------
419 - - - H e l p e r s - - - 419 - - - H e l p e r s - - -
420 ----------------------------- 420 -----------------------------
421 */ 421 */
422 422
423 // ECMA-262, section 11.8.7, page 54. 423 // ECMA-262, section 11.8.7, page 54.
424 function IN(x) { 424 function IN(x) {
425 if (!IS_SPEC_OBJECT(x)) { 425 if (!IS_SPEC_OBJECT(x)) {
426 throw %MakeTypeError(kInvalidInOperatorUse, this, x); 426 throw %make_type_error(kInvalidInOperatorUse, this, x);
427 } 427 }
428 if (%_IsNonNegativeSmi(this)) { 428 if (%_IsNonNegativeSmi(this)) {
429 if (IS_ARRAY(x) && %_HasFastPackedElements(x)) { 429 if (IS_ARRAY(x) && %_HasFastPackedElements(x)) {
430 return this < x.length; 430 return this < x.length;
431 } 431 }
432 return %HasElement(x, this); 432 return %HasElement(x, this);
433 } 433 }
434 return %HasProperty(x, %$toName(this)); 434 return %HasProperty(x, %to_name(this));
435 } 435 }
436 436
437 437
438 function CALL_NON_FUNCTION() { 438 function CALL_NON_FUNCTION() {
439 var delegate = %GetFunctionDelegate(this); 439 var delegate = %GetFunctionDelegate(this);
440 if (!IS_FUNCTION(delegate)) { 440 if (!IS_FUNCTION(delegate)) {
441 var callsite = %RenderCallSite(); 441 var callsite = %RenderCallSite();
442 if (callsite == "") callsite = typeof this; 442 if (callsite == "") callsite = typeof this;
443 throw %MakeTypeError(kCalledNonCallable, callsite); 443 throw %make_type_error(kCalledNonCallable, callsite);
444 } 444 }
445 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); 445 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength());
446 } 446 }
447 447
448 448
449 function CALL_NON_FUNCTION_AS_CONSTRUCTOR() { 449 function CALL_NON_FUNCTION_AS_CONSTRUCTOR() {
450 var delegate = %GetConstructorDelegate(this); 450 var delegate = %GetConstructorDelegate(this);
451 if (!IS_FUNCTION(delegate)) { 451 if (!IS_FUNCTION(delegate)) {
452 var callsite = %RenderCallSite(); 452 var callsite = %RenderCallSite();
453 if (callsite == "") callsite = typeof this; 453 if (callsite == "") callsite = typeof this;
454 throw %MakeTypeError(kCalledNonCallable, callsite); 454 throw %make_type_error(kCalledNonCallable, callsite);
455 } 455 }
456 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength()); 456 return %Apply(delegate, this, arguments, 0, %_ArgumentsLength());
457 } 457 }
458 458
459 459
460 function CALL_FUNCTION_PROXY() { 460 function CALL_FUNCTION_PROXY() {
461 var arity = %_ArgumentsLength() - 1; 461 var arity = %_ArgumentsLength() - 1;
462 var proxy = %_Arguments(arity); // The proxy comes in as an additional arg. 462 var proxy = %_Arguments(arity); // The proxy comes in as an additional arg.
463 var trap = %GetCallTrap(proxy); 463 var trap = %GetCallTrap(proxy);
464 return %Apply(trap, this, arguments, 0, arity); 464 return %Apply(trap, this, arguments, 0, arity);
(...skipping 18 matching lines...) Expand all
483 IS_SPEC_FUNCTION(this)) { 483 IS_SPEC_FUNCTION(this)) {
484 return length; 484 return length;
485 } 485 }
486 } 486 }
487 487
488 length = (args == null) ? 0 : TO_UINT32(args.length); 488 length = (args == null) ? 0 : TO_UINT32(args.length);
489 489
490 // We can handle any number of apply arguments if the stack is 490 // We can handle any number of apply arguments if the stack is
491 // big enough, but sanity check the value to avoid overflow when 491 // big enough, but sanity check the value to avoid overflow when
492 // multiplying with pointer size. 492 // multiplying with pointer size.
493 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); 493 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow);
494 494
495 if (!IS_SPEC_FUNCTION(this)) { 495 if (!IS_SPEC_FUNCTION(this)) {
496 throw %MakeTypeError(kApplyNonFunction, %$toString(this), typeof this); 496 throw %make_type_error(kApplyNonFunction, %to_string_fun(this), typeof this) ;
497 } 497 }
498 498
499 // Make sure the arguments list has the right type. 499 // Make sure the arguments list has the right type.
500 if (args != null && !IS_SPEC_OBJECT(args)) { 500 if (args != null && !IS_SPEC_OBJECT(args)) {
501 throw %MakeTypeError(kWrongArgs, "Function.prototype.apply"); 501 throw %make_type_error(kWrongArgs, "Function.prototype.apply");
502 } 502 }
503 503
504 // Return the length which is the number of arguments to copy to the 504 // Return the length which is the number of arguments to copy to the
505 // stack. It is guaranteed to be a small integer at this point. 505 // stack. It is guaranteed to be a small integer at this point.
506 return length; 506 return length;
507 } 507 }
508 508
509 509
510 function REFLECT_APPLY_PREPARE(args) { 510 function REFLECT_APPLY_PREPARE(args) {
511 var length; 511 var length;
512 // First check whether length is a positive Smi and args is an 512 // First check whether length is a positive Smi and args is an
513 // array. This is the fast case. If this fails, we do the slow case 513 // array. This is the fast case. If this fails, we do the slow case
514 // that takes care of more eventualities. 514 // that takes care of more eventualities.
515 if (IS_ARRAY(args)) { 515 if (IS_ARRAY(args)) {
516 length = args.length; 516 length = args.length;
517 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && 517 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength &&
518 IS_SPEC_FUNCTION(this)) { 518 IS_SPEC_FUNCTION(this)) {
519 return length; 519 return length;
520 } 520 }
521 } 521 }
522 522
523 if (!IS_SPEC_FUNCTION(this)) { 523 if (!IS_SPEC_FUNCTION(this)) {
524 throw %MakeTypeError(kCalledNonCallable, %$toString(this)); 524 throw %make_type_error(kCalledNonCallable, %to_string_fun(this));
525 } 525 }
526 526
527 if (!IS_SPEC_OBJECT(args)) { 527 if (!IS_SPEC_OBJECT(args)) {
528 throw %MakeTypeError(kWrongArgs, "Reflect.apply"); 528 throw %make_type_error(kWrongArgs, "Reflect.apply");
529 } 529 }
530 530
531 length = %$toLength(args.length); 531 length = %to_length_fun(args.length);
532 532
533 // We can handle any number of apply arguments if the stack is 533 // We can handle any number of apply arguments if the stack is
534 // big enough, but sanity check the value to avoid overflow when 534 // big enough, but sanity check the value to avoid overflow when
535 // multiplying with pointer size. 535 // multiplying with pointer size.
536 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); 536 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow);
537 537
538 // Return the length which is the number of arguments to copy to the 538 // Return the length which is the number of arguments to copy to the
539 // stack. It is guaranteed to be a small integer at this point. 539 // stack. It is guaranteed to be a small integer at this point.
540 return length; 540 return length;
541 } 541 }
542 542
543 543
544 function REFLECT_CONSTRUCT_PREPARE( 544 function REFLECT_CONSTRUCT_PREPARE(
545 args, newTarget) { 545 args, newTarget) {
546 var length; 546 var length;
547 var ctorOk = IS_SPEC_FUNCTION(this) && %IsConstructor(this); 547 var ctorOk = IS_SPEC_FUNCTION(this) && %IsConstructor(this);
548 var newTargetOk = IS_SPEC_FUNCTION(newTarget) && %IsConstructor(newTarget); 548 var newTargetOk = IS_SPEC_FUNCTION(newTarget) && %IsConstructor(newTarget);
549 549
550 // First check whether length is a positive Smi and args is an 550 // First check whether length is a positive Smi and args is an
551 // array. This is the fast case. If this fails, we do the slow case 551 // array. This is the fast case. If this fails, we do the slow case
552 // that takes care of more eventualities. 552 // that takes care of more eventualities.
553 if (IS_ARRAY(args)) { 553 if (IS_ARRAY(args)) {
554 length = args.length; 554 length = args.length;
555 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength && 555 if (%_IsSmi(length) && length >= 0 && length < kSafeArgumentsLength &&
556 ctorOk && newTargetOk) { 556 ctorOk && newTargetOk) {
557 return length; 557 return length;
558 } 558 }
559 } 559 }
560 560
561 if (!ctorOk) { 561 if (!ctorOk) {
562 if (!IS_SPEC_FUNCTION(this)) { 562 if (!IS_SPEC_FUNCTION(this)) {
563 throw %MakeTypeError(kCalledNonCallable, %$toString(this)); 563 throw %make_type_error(kCalledNonCallable, %to_string_fun(this));
564 } else { 564 } else {
565 throw %MakeTypeError(kNotConstructor, %$toString(this)); 565 throw %make_type_error(kNotConstructor, %to_string_fun(this));
566 } 566 }
567 } 567 }
568 568
569 if (!newTargetOk) { 569 if (!newTargetOk) {
570 if (!IS_SPEC_FUNCTION(newTarget)) { 570 if (!IS_SPEC_FUNCTION(newTarget)) {
571 throw %MakeTypeError(kCalledNonCallable, %$toString(newTarget)); 571 throw %make_type_error(kCalledNonCallable, %to_string_fun(newTarget));
572 } else { 572 } else {
573 throw %MakeTypeError(kNotConstructor, %$toString(newTarget)); 573 throw %make_type_error(kNotConstructor, %to_string_fun(newTarget));
574 } 574 }
575 } 575 }
576 576
577 if (!IS_SPEC_OBJECT(args)) { 577 if (!IS_SPEC_OBJECT(args)) {
578 throw %MakeTypeError(kWrongArgs, "Reflect.construct"); 578 throw %make_type_error(kWrongArgs, "Reflect.construct");
579 } 579 }
580 580
581 length = %$toLength(args.length); 581 length = %to_length_fun(args.length);
582 582
583 // We can handle any number of apply arguments if the stack is 583 // We can handle any number of apply arguments if the stack is
584 // big enough, but sanity check the value to avoid overflow when 584 // big enough, but sanity check the value to avoid overflow when
585 // multiplying with pointer size. 585 // multiplying with pointer size.
586 if (length > kSafeArgumentsLength) throw %MakeRangeError(kStackOverflow); 586 if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow);
587 587
588 // Return the length which is the number of arguments to copy to the 588 // Return the length which is the number of arguments to copy to the
589 // stack. It is guaranteed to be a small integer at this point. 589 // stack. It is guaranteed to be a small integer at this point.
590 return length; 590 return length;
591 } 591 }
592 592
593 593
594 function CONCAT_ITERABLE_TO_ARRAY(iterable) { 594 function CONCAT_ITERABLE_TO_ARRAY(iterable) {
595 return %$concatIterableToArray(this, iterable); 595 return %concat_iterable_to_array(this, iterable);
596 }; 596 };
597 597
598 598
599 function STACK_OVERFLOW(length) { 599 function STACK_OVERFLOW(length) {
600 throw %MakeRangeError(kStackOverflow); 600 throw %make_range_error(kStackOverflow);
601 } 601 }
602 602
603 603
604 // Convert the receiver to a number - forward to ToNumber. 604 // Convert the receiver to a number - forward to ToNumber.
605 function TO_NUMBER() { 605 function TO_NUMBER() {
606 return %$toNumber(this); 606 return %to_number_fun(this);
607 } 607 }
608 608
609 609
610 // Convert the receiver to a string - forward to ToString. 610 // Convert the receiver to a string - forward to ToString.
611 function TO_STRING() { 611 function TO_STRING() {
612 return %$toString(this); 612 return %to_string_fun(this);
613 } 613 }
614 614
615 615
616 // Convert the receiver to a string or symbol - forward to ToName. 616 // Convert the receiver to a string or symbol - forward to ToName.
617 function TO_NAME() { 617 function TO_NAME() {
618 return %$toName(this); 618 return %to_name(this);
619 } 619 }
620 620
621 621
622 /* ------------------------------------- 622 /* -------------------------------------
623 - - - C o n v e r s i o n s - - - 623 - - - C o n v e r s i o n s - - -
624 ------------------------------------- 624 -------------------------------------
625 */ 625 */
626 626
627 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, 627 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint,
628 // (1) for number hint, and (2) for string hint. 628 // (1) for number hint, and (2) for string hint.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 // NOTE: Setting the prototype for Array must take place as early as 815 // NOTE: Setting the prototype for Array must take place as early as
816 // possible due to code generation for array literals. When 816 // possible due to code generation for array literals. When
817 // generating code for a array literal a boilerplate array is created 817 // generating code for a array literal a boilerplate array is created
818 // that is cloned when running the code. It is essential that the 818 // that is cloned when running the code. It is essential that the
819 // boilerplate gets the right prototype. 819 // boilerplate gets the right prototype.
820 %FunctionSetPrototype(GlobalArray, new GlobalArray(0)); 820 %FunctionSetPrototype(GlobalArray, new GlobalArray(0));
821 821
822 // ---------------------------------------------------------------------------- 822 // ----------------------------------------------------------------------------
823 // Exports 823 // Exports
824 824
825 $concatIterableToArray = ConcatIterableToArray;
826 $defaultNumber = DefaultNumber; 825 $defaultNumber = DefaultNumber;
827 $defaultString = DefaultString; 826 $defaultString = DefaultString;
828 $NaN = %GetRootNaN(); 827 $NaN = %GetRootNaN();
829 $nonNumberToNumber = NonNumberToNumber; 828 $nonNumberToNumber = NonNumberToNumber;
830 $nonStringToString = NonStringToString; 829 $nonStringToString = NonStringToString;
831 $sameValue = SameValue; 830 $sameValue = SameValue;
832 $sameValueZero = SameValueZero; 831 $sameValueZero = SameValueZero;
833 $toInteger = ToInteger; 832 $toInteger = ToInteger;
834 $toLength = ToLength; 833 $toLength = ToLength;
835 $toName = ToName; 834 $toName = ToName;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 CONCAT_ITERABLE_TO_ARRAY, 873 CONCAT_ITERABLE_TO_ARRAY,
875 APPLY_PREPARE, 874 APPLY_PREPARE,
876 REFLECT_APPLY_PREPARE, 875 REFLECT_APPLY_PREPARE,
877 REFLECT_CONSTRUCT_PREPARE, 876 REFLECT_CONSTRUCT_PREPARE,
878 STACK_OVERFLOW, 877 STACK_OVERFLOW,
879 TO_NUMBER, 878 TO_NUMBER,
880 TO_STRING, 879 TO_STRING,
881 TO_NAME, 880 TO_NAME,
882 }); 881 });
883 882
884 utils.ExportToRuntime(function(to) { 883 %InstallToContext([
885 to["to_integer_fun"] = ToInteger; 884 "concat_iterable_to_array", ConcatIterableToArray,
886 to["to_length_fun"] = ToLength; 885 "non_number_to_number", NonNumberToNumber,
887 to["to_number_fun"] = ToNumber; 886 "non_string_to_string", NonStringToString,
888 to["to_string_fun"] = ToString; 887 "to_integer_fun", ToInteger,
889 }); 888 "to_length_fun", ToLength,
889 "to_name", ToName,
890 "to_number_fun", ToNumber,
891 "to_primitive", ToPrimitive,
892 "to_string_fun", ToString,
893 ]);
890 894
891 utils.Export(function(to) { 895 utils.Export(function(to) {
892 to.ToBoolean = ToBoolean; 896 to.ToBoolean = ToBoolean;
897 to.ToLength = ToLength;
898 to.ToName = ToName;
893 to.ToNumber = ToNumber; 899 to.ToNumber = ToNumber;
900 to.ToPrimitive = ToPrimitive;
894 to.ToString = ToString; 901 to.ToString = ToString;
895 }) 902 });
896 903
897 }) 904 })
OLDNEW
« no previous file with comments | « src/regexp.js ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698