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

Side by Side Diff: dart/frog/leg/lib/js_helper.dart

Issue 9395070: Triage Expect. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 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 | « no previous file | dart/frog/leg/lib/mockimpl.dart » ('j') | dart/frog/leg/ssa/codegen.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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('js_helper'); 5 #library('js_helper');
6 6
7 #import('coreimpl.dart'); 7 #import('coreimpl.dart');
8 8
9 #source('date_helper.dart'); 9 #source('date_helper.dart');
10 10
11 /** 11 /**
12 * Returns true if both arguments are numbers. 12 * Returns true if both arguments are numbers.
13 * If only the first argument is a number, throws the given message as 13 * If only the first argument is a number, throws the given message as
14 * exception. 14 * exception.
15 */ 15 */
16 bool checkNumbers(var a, var b, var message) { 16 bool checkNumbers(var a, var b, var message) {
17 if (a is num) { 17 if (a is num) {
18 if (b is num) { 18 if (b is num) {
19 return true; 19 return true;
20 } else { 20 } else {
21 checkNull(b); 21 checkNull(b);
22 throw new IllegalArgumentException(message); 22 throw new IllegalArgumentException(message);
23 } 23 }
24 } 24 }
25 return false; 25 return false;
26 } 26 }
27 27
28 28
29 bool isJSArray(var value) { 29 bool isJSArray(var value) {
30 return JS("bool", @"$0.constructor === Array", value); 30 return value !== null && JS("bool", @"$0.constructor === Array", value);
ngeoffray 2012/02/21 12:23:51 No need.
31 } 31 }
32 32
33 33
34 add(var a, var b) { 34 add(var a, var b) {
35 if (checkNumbers(a, b, "num+ expects a number as second operand.")) { 35 if (checkNumbers(a, b, "num+ expects a number as second operand.")) {
36 return JS("num", @"$0 + $1", a, b); 36 return JS("num", @"$0 + $1", a, b);
37 } else if (a is String) { 37 } else if (a is String) {
38 b = b.toString(); 38 b = b.toString();
39 if (b is String) { 39 if (b is String) {
40 return JS("String", @"$0 + $1", a, b); 40 return JS("String", @"$0 + $1", a, b);
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 953
954 builtin$contains$2(receiver, other, startIndex) { 954 builtin$contains$2(receiver, other, startIndex) {
955 checkNull(receiver); 955 checkNull(receiver);
956 if (receiver is !String) { 956 if (receiver is !String) {
957 return UNINTERCEPTED(receiver.contains(other, startIndex)); 957 return UNINTERCEPTED(receiver.contains(other, startIndex));
958 } 958 }
959 checkNull(other); 959 checkNull(other);
960 if (other is !String) { 960 if (other is !String) {
961 throw 'String.contains with non-String is not implemented'; 961 throw 'String.contains with non-String is not implemented';
962 } 962 }
963 if ((startIndex !== null) || (startIndex is !num)) { 963 if ((startIndex !== null) && (startIndex is !num)) {
964 throw new IllegalArgumentException(startIndex); 964 throw new IllegalArgumentException(startIndex);
965 } 965 }
966 return receiver.indexOf(other, startIndex) >= 0; 966 return receiver.indexOf(other, startIndex) >= 0;
967 } 967 }
968 968
969 builtin$endsWith$1(receiver, other) { 969 builtin$endsWith$1(receiver, other) {
970 checkNull(receiver); 970 checkNull(receiver);
971 if (receiver is !String) return UNINTERCEPTED(receiver.endsWith(other)); 971 if (receiver is !String) return UNINTERCEPTED(receiver.endsWith(other));
972 972
973 checkNull(other); 973 checkNull(other);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 builtin$hashCode$0(receiver) { 1134 builtin$hashCode$0(receiver) {
1135 if (receiver is num) return receiver & 0x1FFFFFFF; 1135 if (receiver is num) return receiver & 0x1FFFFFFF;
1136 if (receiver is String) { 1136 if (receiver is String) {
1137 throw 'String.hashCode is not implemented'; 1137 throw 'String.hashCode is not implemented';
1138 } 1138 }
1139 if (isJSArray(receiver)) { 1139 if (isJSArray(receiver)) {
1140 throw 'List.hashCode is not implemented'; 1140 throw 'List.hashCode is not implemented';
1141 } 1141 }
1142 return UNINTERCEPTED(receiver.hashCode()); 1142 return UNINTERCEPTED(receiver.hashCode());
1143 } 1143 }
OLDNEW
« no previous file with comments | « no previous file | dart/frog/leg/lib/mockimpl.dart » ('j') | dart/frog/leg/ssa/codegen.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698