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: tool/input_sdk/patch/core_patch.dart

Issue 1153003003: fixes #40, extension methods for primitive types (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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) 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 // Patch file for dart:core classes. 5 // Patch file for dart:core classes.
6 import "dart:_internal" as _symbol_dev; 6 import "dart:_internal" as _symbol_dev;
7 import 'dart:_interceptors'; 7 import 'dart:_interceptors';
8 import 'dart:_js_helper' show patch, 8 import 'dart:_js_helper' show patch,
9 checkInt, 9 checkInt,
10 getRuntimeType, 10 getRuntimeType,
11 jsonEncodeNative, 11 jsonEncodeNative,
12 JSSyntaxRegExp, 12 JSSyntaxRegExp,
13 Primitives, 13 Primitives,
14 stringJoinUnchecked, 14 stringJoinUnchecked,
15 objectHashCode; 15 objectHashCode;
16 16
17 import 'dart:_foreign_helper' show JS; 17 import 'dart:_foreign_helper' show JS;
18 18
19 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); 19 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol);
20 20
21 _symbolMapToStringMap(Map<Symbol, dynamic> map) {
22 if (map == null) return null;
23 var result = new Map<String, dynamic>();
24 map.forEach((Symbol key, value) {
25 result[_symbolToString(key)] = value;
26 });
27 return result;
28 }
29
30 class SupportJsExtensionMethods {
31 const SupportJsExtensionMethods();
32 }
33
34 @patch 21 @patch
35 int identityHashCode(Object object) => objectHashCode(object); 22 int identityHashCode(Object object) => objectHashCode(object);
36 23
37 // Patch for Object implementation. 24 // Patch for Object implementation.
38 @patch 25 @patch
39 class Object { 26 class Object {
40 @patch 27 @patch
41 int get hashCode => Primitives.objectHashCode(this); 28 int get hashCode => Primitives.objectHashCode(this);
42 29
43 30
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 @patch 218 @patch
232 static void _initTicker() { 219 static void _initTicker() {
233 Primitives.initTicker(); 220 Primitives.initTicker();
234 _frequency = Primitives.timerFrequency; 221 _frequency = Primitives.timerFrequency;
235 } 222 }
236 223
237 @patch 224 @patch
238 static int _now() => Primitives.timerTicks(); 225 static int _now() => Primitives.timerTicks();
239 } 226 }
240 227
241 class _ListConstructorSentinel {
242 const _ListConstructorSentinel();
243 }
244
245 // Patch for List implementation. 228 // Patch for List implementation.
246 @patch 229 @patch
247 class List<E> { 230 class List<E> {
248 @patch 231 @patch
249 factory List([int length]) { 232 factory List([int length]) {
250 dynamic list; 233 dynamic list;
251 if (length == null) { 234 if (length == null) {
252 list = JS('', '[]'); 235 list = JS('', '[]');
253 } else { 236 } else {
254 // Explicit type test is necessary to guard against JavaScript conversions 237 // Explicit type test is necessary to guard against JavaScript conversions
255 // in unchecked mode. 238 // in unchecked mode.
256 if ((length is !int) || (length < 0)) { 239 if ((length is !int) || (length < 0)) {
257 throw new ArgumentError("Length must be a non-negative integer: $length" ); 240 throw new ArgumentError("Length must be a non-negative integer: $length" );
258 } 241 }
259 list = JS('', 'new Array(#)', length); 242 list = JSArray.markFixedList(JS('', 'new Array(#)', length));
260 // TODO(jmesserly): consider a fixed array subclass instead.
261 JS('void', r'#.fixed$length = Array', list);
262 } 243 }
263 // TODO(jmesserly): skip this when E is dynamic and Object. 244 return new JSArray<E>.typed(list);
264 JS('void', 'dart.setType(#, List\$(#))', list, E);
265 // TODO(jmesserly): compiler creates a bogus type check here.
266 return list;
267 } 245 }
268 246
269 @patch 247 @patch
270 factory List.filled(int length, E fill) { 248 factory List.filled(int length, E fill) {
271 List<E> result = new List<E>(length); 249 List<E> result = new List<E>(length);
272 if (length != 0 && fill != null) { 250 if (length != 0 && fill != null) {
273 for (int i = 0; i < result.length; i++) { 251 for (int i = 0; i < result.length; i++) {
274 result[i] = fill; 252 result[i] = fill;
275 } 253 }
276 } 254 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 @patch 444 @patch
467 static bool get _isWindows => false; 445 static bool get _isWindows => false;
468 446
469 @patch 447 @patch
470 static Uri get base { 448 static Uri get base {
471 String uri = Primitives.currentUri(); 449 String uri = Primitives.currentUri();
472 if (uri != null) return Uri.parse(uri); 450 if (uri != null) return Uri.parse(uri);
473 throw new UnsupportedError("'Uri.base' is not supported"); 451 throw new UnsupportedError("'Uri.base' is not supported");
474 } 452 }
475 } 453 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698