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

Side by Side Diff: compiler/lib/implementation/core.js

Issue 9192007: Simplify equality checks and get rid of unreachable code in number and bool. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Helpers for lazy static initialization. 6 * Helpers for lazy static initialization.
7 */ 7 */
8 var static$uninitialized = {}; 8 var static$uninitialized = {};
9 var static$initializing = {}; 9 var static$initializing = {};
10 10
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 */ 245 */
246 var $Dart$Null = void 0; 246 var $Dart$Null = void 0;
247 247
248 function assert(expr) { 248 function assert(expr) {
249 var val = typeof(expr) == 'function' ? $dartcall(expr, []) : expr; 249 var val = typeof(expr) == 'function' ? $dartcall(expr, []) : expr;
250 if (val !== true) { 250 if (val !== true) {
251 $Dart$ThrowException(native_ExceptionHelper_createAssertionError()); 251 $Dart$ThrowException(native_ExceptionHelper_createAssertionError());
252 } 252 }
253 } 253 }
254 254
255 // TODO(jimhug): Remove these functions after updating compiler backend.
256 function BIT_OR$operator(val1, val2) { 255 function BIT_OR$operator(val1, val2) {
257 return (typeof(val1) == 'number' && typeof(val2) == 'number') 256 return (typeof(val1) == 'number' && typeof(val2) == 'number')
258 ? val1 | val2 257 ? val1 | val2
259 : val1.BIT_OR$operator(val2); 258 : val1.BIT_OR$operator(val2);
260 } 259 }
261 260
262 function BIT_XOR$operator(val1, val2) { 261 function BIT_XOR$operator(val1, val2) {
263 return (typeof(val1) == 'number' && typeof(val2) == 'number') 262 return (typeof(val1) == 'number' && typeof(val2) == 'number')
264 ? val1 ^ val2 263 ? val1 ^ val2
265 : val1.BIT_XOR$operator(val2); 264 : val1.BIT_XOR$operator(val2);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 return (tmp < 0) ? Math.ceil(tmp) : Math.floor(tmp); 326 return (tmp < 0) ? Math.ceil(tmp) : Math.floor(tmp);
328 } else { 327 } else {
329 return val1.TRUNC$operator(val2); 328 return val1.TRUNC$operator(val2);
330 } 329 }
331 } 330 }
332 331
333 function negate$operator(val) { 332 function negate$operator(val) {
334 return (typeof(val) == 'number') ? -val : val.negate$operator(); 333 return (typeof(val) == 'number') ? -val : val.negate$operator();
335 } 334 }
336 335
336 function EQ$operator(val1, val2) {
337 return (typeof val1 != 'object')
floitsch 2012/01/19 11:31:59 what if val1 is a native string and val2 is a boxe
kasperl 2012/01/19 11:43:04 Good point. This code behaves the same (broken) wa
338 ? val1 === val2
339 : val1.EQ$operator(val2);
340 }
341
342 function NE$operator(val1, val2) {
343 return (typeof val1 != 'object')
floitsch 2012/01/19 11:31:59 ditto.
344 ? val1 !== val2
345 : !val1.EQ$operator(val2);
346 }
347
337 function LT$operator(val1, val2) { 348 function LT$operator(val1, val2) {
338 return (typeof(val1) == 'number' && typeof(val2) == 'number') 349 return (typeof(val1) == 'number' && typeof(val2) == 'number')
339 ? val1 < val2 350 ? val1 < val2
340 : val1.LT$operator(val2); 351 : val1.LT$operator(val2);
341 } 352 }
342 353
343 function GT$operator(val1, val2) { 354 function GT$operator(val1, val2) {
344 return (typeof(val1) == 'number' && typeof(val2) == 'number') 355 return (typeof(val1) == 'number' && typeof(val2) == 'number')
345 ? val1 > val2 356 ? val1 > val2
346 : val1.GT$operator(val2); 357 : val1.GT$operator(val2);
347 } 358 }
348 359
349 function LTE$operator(val1, val2) { 360 function LTE$operator(val1, val2) {
350 return (typeof(val1) == 'number' && typeof(val2) == 'number') 361 return (typeof(val1) == 'number' && typeof(val2) == 'number')
351 ? val1 <= val2 362 ? val1 <= val2
352 : val1.LTE$operator(val2); 363 : val1.LTE$operator(val2);
353 } 364 }
354 365
355 function GTE$operator(val1, val2) { 366 function GTE$operator(val1, val2) {
356 return (typeof(val1) == 'number' && typeof(val2) == 'number') 367 return (typeof(val1) == 'number' && typeof(val2) == 'number')
357 ? val1 >= val2 368 ? val1 >= val2
358 : val1.GTE$operator(val2); 369 : val1.GTE$operator(val2);
359 } 370 }
360 371
361
362 /**
363 * These operators need to work correctly with undefined
364 * so must be functions.
365 */
366 function EQ$operator(val1, val2) {
367 if (val1 === $Dart$Null) {
368 return val2 === $Dart$Null;
369 } else if (typeof(val1) == typeof(val2) && typeof val1 != 'object') {
370 // number, boolean, string
371 return val1 === val2;
372 }
373 return val1.EQ$operator(val2);
374 }
375
376 function NE$operator(val1, val2) {
377 return !EQ$operator(val1, val2);
378 }
379
380 // The following operator-functions are not called from Dart-generated code, but 372 // The following operator-functions are not called from Dart-generated code, but
381 // only from handwritten JS code. 373 // only from handwritten JS code.
382 function INDEX$operator(obj, index) { 374 function INDEX$operator(obj, index) {
383 return obj.INDEX$operator(index); 375 return obj.INDEX$operator(index);
384 } 376 }
385 377
386 function ASSIGN_INDEX$operator(obj, index, newVal) { 378 function ASSIGN_INDEX$operator(obj, index, newVal) {
387 obj.ASSIGN_INDEX$operator(index, newVal); 379 obj.ASSIGN_INDEX$operator(index, newVal);
388 } 380 }
389 381
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 return match; 519 return match;
528 } 520 }
529 o.$dartConstId = id; 521 o.$dartConstId = id;
530 $consts[key] = o; 522 $consts[key] = o;
531 return o; 523 return o;
532 } 524 }
533 525
534 function $Dart$MapLiteralFactory() { 526 function $Dart$MapLiteralFactory() {
535 return native__CoreJsUtil__newMapLiteral(); 527 return native__CoreJsUtil__newMapLiteral();
536 } 528 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698