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

Side by Side Diff: lib/compiler/implementation/lib/interceptors.dart

Issue 10979050: Ensure that hashCode and runtimeType work on null. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #library('dart:_interceptors'); 5 #library('dart:_interceptors');
6 6
7 #import('coreimpl.dart'); 7 #import('coreimpl.dart');
8 #import('js_helper.dart'); 8 #import('js_helper.dart');
9 9
10 add$1(var receiver, var value) { 10 add$1(var receiver, var value) {
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 610
611 /** 611 /**
612 * This is the [Jenkins hash function][1] but using masking to keep 612 * This is the [Jenkins hash function][1] but using masking to keep
613 * values in SMI range. 613 * values in SMI range.
614 * 614 *
615 * [1]: http://en.wikipedia.org/wiki/Jenkins_hash_function 615 * [1]: http://en.wikipedia.org/wiki/Jenkins_hash_function
616 */ 616 */
617 hashCode(receiver) { 617 hashCode(receiver) {
618 // TODO(ahe): This method shouldn't have to use JS. Update when our 618 // TODO(ahe): This method shouldn't have to use JS. Update when our
619 // optimizations are smarter. 619 // optimizations are smarter.
620 if (receiver === null) return 0;
620 if (receiver is num) return JS('int', r'# & 0x1FFFFFFF', receiver); 621 if (receiver is num) return JS('int', r'# & 0x1FFFFFFF', receiver);
621 if (receiver is !String) return UNINTERCEPTED(receiver.hashCode()); 622 if (receiver is !String) return UNINTERCEPTED(receiver.hashCode());
ngeoffray 2012/09/27 08:36:54 Don't forget JS array too.
Lasse Reichstein Nielsen 2012/09/27 09:55:37 And bool. Yey.
622 int hash = 0; 623 int hash = 0;
623 int length = JS('int', r'#.length', receiver); 624 int length = JS('int', r'#.length', receiver);
624 for (int i = 0; i < length; i++) { 625 for (int i = 0; i < length; i++) {
625 hash = 0x1fffffff & (hash + JS('int', r'#.charCodeAt(#)', receiver, i)); 626 hash = 0x1fffffff & (hash + JS('int', r'#.charCodeAt(#)', receiver, i));
626 hash = 0x1fffffff & (hash + JS('int', r'# << #', 0x0007ffff & hash, 10)); 627 hash = 0x1fffffff & (hash + JS('int', r'# << #', 0x0007ffff & hash, 10));
627 hash ^= hash >> 6; 628 hash ^= hash >> 6;
628 } 629 }
629 hash = 0x1fffffff & (hash + JS('int', r'# << #', 0x03ffffff & hash, 3)); 630 hash = 0x1fffffff & (hash + JS('int', r'# << #', 0x03ffffff & hash, 3));
630 hash ^= hash >> 11; 631 hash ^= hash >> 11;
631 return 0x1fffffff & (hash + JS('int', r'# << #', 0x00003fff & hash, 15)); 632 return 0x1fffffff & (hash + JS('int', r'# << #', 0x00003fff & hash, 15));
(...skipping 12 matching lines...) Expand all
644 isEven(receiver) { 645 isEven(receiver) {
645 if (receiver is !int) return UNINTERCEPTED(receiver.isEven()); 646 if (receiver is !int) return UNINTERCEPTED(receiver.isEven());
646 return (receiver & 1) === 0; 647 return (receiver & 1) === 0;
647 } 648 }
648 649
649 isOdd(receiver) { 650 isOdd(receiver) {
650 if (receiver is !int) return UNINTERCEPTED(receiver.isOdd()); 651 if (receiver is !int) return UNINTERCEPTED(receiver.isOdd());
651 return (receiver & 1) === 1; 652 return (receiver & 1) === 1;
652 } 653 }
653 654
654 get$toString(receiver) => () => toString(receiver);
655
656 get$runtimeType(receiver) { 655 get$runtimeType(receiver) {
657 if (receiver is int) { 656 if (receiver is int) {
658 return getOrCreateCachedRuntimeType('int'); 657 return getOrCreateCachedRuntimeType('int');
659 } else if (receiver is String) { 658 } else if (receiver is String) {
660 return getOrCreateCachedRuntimeType('String'); 659 return getOrCreateCachedRuntimeType('String');
661 } else if (receiver is double) { 660 } else if (receiver is double) {
662 return getOrCreateCachedRuntimeType('double'); 661 return getOrCreateCachedRuntimeType('double');
662 } else if (receiver === null) {
663 return getOrCreateCachedRuntimeType('Null');
663 } else if (isJsArray(receiver)) { 664 } else if (isJsArray(receiver)) {
664 return getOrCreateCachedRuntimeType('List'); 665 return getOrCreateCachedRuntimeType('List');
665 } else { 666 } else {
666 return UNINTERCEPTED(receiver.runtimeType); 667 return UNINTERCEPTED(receiver.runtimeType);
667 } 668 }
668 } 669 }
670
671 // TODO(lrn): These getters should be generated added automatically for all
ngeoffray 2012/09/27 08:36:54 remove 'added'
Lasse Reichstein Nielsen 2012/09/27 09:55:37 Done.
672 // methods.
ngeoffray 2012/09/27 08:36:54 methods -> interceptors
Lasse Reichstein Nielsen 2012/09/27 09:55:37 "intercepted methods"
673 get$toString(receiver) => () => toString(receiver);
674
675 get$hashCode(receiver) => () => hashCode(receiver);
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/builder.dart » ('j') | tests/corelib/corelib.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698