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

Side by Side Diff: pkg/dev_compiler/tool/input_sdk/private/js_helper.dart

Issue 2952363003: Handle toString on DOM types (Closed)
Patch Set: Created 3 years, 6 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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._js_helper; 5 library dart._js_helper;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'dart:_debugger' show stackTraceMapper; 9 import 'dart:_debugger' show stackTraceMapper;
10 10
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return _parseDoubleError(source, handleError); 178 return _parseDoubleError(source, handleError);
179 } 179 }
180 return result; 180 return result;
181 } 181 }
182 182
183 /** [: r"$".codeUnitAt(0) :] */ 183 /** [: r"$".codeUnitAt(0) :] */
184 static const int DOLLAR_CHAR_VALUE = 36; 184 static const int DOLLAR_CHAR_VALUE = 36;
185 185
186 /// Returns the type of [object] as a string (including type arguments). 186 /// Returns the type of [object] as a string (including type arguments).
187 /// 187 ///
188 /// In minified mode, uses the unminified names if available. 188 /// In minified mode, uses the unminified names if available.
Jennifer Messerly 2017/06/23 18:27:11 not related to your change, but this comment seems
vsm 2017/06/26 20:29:24 deleted
189 static String objectTypeName(Object object) { 189 static String objectTypeName(Object object) {
Jennifer Messerly 2017/06/23 18:27:11 is this function used?
vsm 2017/06/26 20:29:24 deleted
190 return getRuntimeType(object).toString(); 190 return getRuntimeType(object).toString();
191 } 191 }
192 192
193 /// In minified mode, uses the unminified names if available. 193 /// In minified mode, uses the unminified names if available.
Jennifer Messerly 2017/06/23 18:27:11 this one too
vsm 2017/06/26 20:29:24 deleted
194 static String objectToString(Object object) { 194 static String objectToString(Object object) {
195 // String name = objectTypeName(object); 195 bool nativeType = JS('bool', 'typeof # == "object" && !(# instanceof #)',
Jennifer Messerly 2017/06/23 18:27:11 the normal way to check this is `getExtensionType`
vsm 2017/06/26 20:29:24 Ahh, all our extension types (i think) extend Inte
196 String name = JS('String', 'dart.typeName(dart.getReifiedType(#))', object); 196 object, object, Object);
197 return "Instance of '$name'"; 197 if (nativeType) {
Jennifer Messerly 2017/06/23 18:27:11 very minor suggestion: if you put the conditional
vsm 2017/06/26 20:29:24 We already inferred nativeType as non-nullable. W
198 // Forward DOM types and other JS objects to their native toString method.
199 return JS('String', '#.toString()', object);
200 } else {
201 // Otherwise, fall back on default Object implemation.
202 String name =
203 JS('String', 'dart.typeName(dart.getReifiedType(#))', object);
Jennifer Messerly 2017/06/23 18:27:11 can this just call `typeName(getReifiedType(object
vsm 2017/06/26 20:29:24 I was going to say we have no way to import our ru
204 return "Instance of '$name'";
205 }
198 } 206 }
199 207
200 static int dateNow() => JS('int', r'Date.now()'); 208 static int dateNow() => JS('int', r'Date.now()');
201 209
202 static void initTicker() { 210 static void initTicker() {
203 if (timerFrequency != null) return; 211 if (timerFrequency != null) return;
204 // Start with low-resolution. We overwrite the fields if we find better. 212 // Start with low-resolution. We overwrite the fields if we find better.
205 timerFrequency = 1000; 213 timerFrequency = 1000;
206 timerTicks = dateNow; 214 timerTicks = dateNow;
207 if (JS('bool', 'typeof window == "undefined"')) return; 215 if (JS('bool', 'typeof window == "undefined"')) return;
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 // we have no way of telling the compiler yet, so it will generate an extra 931 // we have no way of telling the compiler yet, so it will generate an extra
924 // layer of indirection that wraps the SyncIterator. 932 // layer of indirection that wraps the SyncIterator.
925 _jsIterator() => JS('', '#(...#)', _generator, _args); 933 _jsIterator() => JS('', '#(...#)', _generator, _args);
926 934
927 Iterator<E> get iterator => new SyncIterator<E>(_jsIterator()); 935 Iterator<E> get iterator => new SyncIterator<E>(_jsIterator());
928 } 936 }
929 937
930 class BooleanConversionAssertionError extends AssertionError { 938 class BooleanConversionAssertionError extends AssertionError {
931 toString() => 'Failed assertion: boolean expression must not be null'; 939 toString() => 'Failed assertion: boolean expression must not be null';
932 } 940 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698