OLD | NEW |
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; |
| 18 |
17 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); | 19 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); |
18 | 20 |
19 _symbolMapToStringMap(Map<Symbol, dynamic> map) { | 21 _symbolMapToStringMap(Map<Symbol, dynamic> map) { |
20 if (map == null) return null; | 22 if (map == null) return null; |
21 var result = new Map<String, dynamic>(); | 23 var result = new Map<String, dynamic>(); |
22 map.forEach((Symbol key, value) { | 24 map.forEach((Symbol key, value) { |
23 result[_symbolToString(key)] = value; | 25 result[_symbolToString(key)] = value; |
24 }); | 26 }); |
25 return result; | 27 return result; |
26 } | 28 } |
(...skipping 21 matching lines...) Expand all Loading... |
48 } | 50 } |
49 | 51 |
50 @patch | 52 @patch |
51 Type get runtimeType => getRuntimeType(this); | 53 Type get runtimeType => getRuntimeType(this); |
52 } | 54 } |
53 | 55 |
54 // Patch for Function implementation. | 56 // Patch for Function implementation. |
55 @patch | 57 @patch |
56 class Function { | 58 class Function { |
57 @patch | 59 @patch |
58 static apply(Function function, | 60 static apply(Function f, |
59 List positionalArguments, | 61 List positionalArguments, |
60 [Map<Symbol, dynamic> namedArguments]) { | 62 [Map<Symbol, dynamic> namedArguments]) { |
61 return Primitives.applyFunction( | 63 return Primitives.applyFunction( |
62 function, positionalArguments, | 64 f, positionalArguments, |
63 namedArguments == null ? null : _toMangledNames(namedArguments)); | 65 namedArguments == null ? null : _toMangledNames(namedArguments)); |
64 } | 66 } |
65 | 67 |
66 static Map<String, dynamic> _toMangledNames( | 68 static Map<String, dynamic> _toMangledNames( |
67 Map<Symbol, dynamic> namedArguments) { | 69 Map<Symbol, dynamic> namedArguments) { |
68 Map<String, dynamic> result = {}; | 70 Map<String, dynamic> result = {}; |
69 namedArguments.forEach((symbol, value) { | 71 namedArguments.forEach((symbol, value) { |
70 result[_symbolToString(symbol)] = value; | 72 result[_symbolToString(symbol)] = value; |
71 }); | 73 }); |
72 return result; | 74 return result; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 static const String _EXPANDO_PROPERTY_NAME = 'expando\$values'; | 110 static const String _EXPANDO_PROPERTY_NAME = 'expando\$values'; |
109 static int _keyCount = 0; | 111 static int _keyCount = 0; |
110 } | 112 } |
111 | 113 |
112 @patch | 114 @patch |
113 class int { | 115 class int { |
114 @patch | 116 @patch |
115 static int parse(String source, | 117 static int parse(String source, |
116 { int radix, | 118 { int radix, |
117 int onError(String source) }) { | 119 int onError(String source) }) { |
118 return Primitives.parseInt(source, radix, onError); | 120 // TODO(jmesserly): fix this |
| 121 return JS('int', 'Number(#)', source); |
| 122 //return Primitives.parseInt(source, radix, onError); |
119 } | 123 } |
120 | 124 |
121 @patch | 125 @patch |
122 factory int.fromEnvironment(String name, {int defaultValue}) { | 126 factory int.fromEnvironment(String name, {int defaultValue}) { |
123 throw new UnsupportedError( | 127 throw new UnsupportedError( |
124 'int.fromEnvironment can only be used as a const constructor'); | 128 'int.fromEnvironment can only be used as a const constructor'); |
125 } | 129 } |
126 } | 130 } |
127 | 131 |
128 @patch | 132 @patch |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 @patch | 229 @patch |
226 static void _initTicker() { | 230 static void _initTicker() { |
227 Primitives.initTicker(); | 231 Primitives.initTicker(); |
228 _frequency = Primitives.timerFrequency; | 232 _frequency = Primitives.timerFrequency; |
229 } | 233 } |
230 | 234 |
231 @patch | 235 @patch |
232 static int _now() => Primitives.timerTicks(); | 236 static int _now() => Primitives.timerTicks(); |
233 } | 237 } |
234 | 238 |
235 class _ListConstructorSentinel extends JSInt { | 239 class _ListConstructorSentinel { |
236 const _ListConstructorSentinel(); | 240 const _ListConstructorSentinel(); |
237 } | 241 } |
238 | 242 |
239 // Patch for List implementation. | 243 // Patch for List implementation. |
240 @patch | 244 @patch |
241 class List<E> { | 245 class List<E> { |
242 @patch | 246 @patch |
243 factory List([int length = const _ListConstructorSentinel()]) { | 247 factory List([int length = const _ListConstructorSentinel()]) { |
244 if (length == const _ListConstructorSentinel()) { | 248 if (length == const _ListConstructorSentinel()) { |
245 return new JSArray<E>.emptyGrowable(); | 249 return new JSArray<E>.emptyGrowable(); |
246 } | 250 } |
247 return new JSArray<E>.fixed(length); | 251 return new JSArray<E>.fixed(length); |
248 } | 252 } |
249 | 253 |
250 @patch | 254 @patch |
251 factory List.filled(int length, E fill) { | 255 factory List.filled(int length, E fill) { |
252 List result = new JSArray<E>.fixed(length); | 256 List result = new JSArray<E>.fixed(length); |
253 if (length != 0 && fill != null) { | 257 if (length != 0 && fill != null) { |
254 for (int i = 0; i < result.length; i++) { | 258 for (int i = 0; i < result.length; i++) { |
255 result[i] = fill; | 259 result[i] = fill; |
256 } | 260 } |
257 } | 261 } |
258 return result; | 262 return result; |
259 } | 263 } |
260 | 264 |
261 @patch | 265 @patch |
262 factory List.from(Iterable elements, { bool growable: true }) { | 266 factory List.from(Iterable elements, { bool growable: true }) { |
| 267 // TODO(jmesserly): fix this. This is just to unblock initial SDK check in. |
| 268 return null; |
| 269 /* |
263 List<E> list = new List<E>(); | 270 List<E> list = new List<E>(); |
264 for (E e in elements) { | 271 for (E e in elements) { |
265 list.add(e); | 272 list.add(e); |
266 } | 273 } |
267 if (growable) return list; | 274 if (growable) return list; |
268 return makeListFixedLength(list); | 275 return makeListFixedLength(list); |
| 276 */ |
269 } | 277 } |
270 } | 278 } |
271 | 279 |
272 | 280 |
273 @patch | 281 @patch |
274 class String { | 282 class String { |
275 @patch | 283 @patch |
276 factory String.fromCharCodes(Iterable<int> charCodes, | 284 factory String.fromCharCodes(Iterable<int> charCodes, |
277 [int start = 0, int end]) { | 285 [int start = 0, int end]) { |
278 // If possible, recognize typed lists too. | 286 // If possible, recognize typed lists too. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 @patch | 455 @patch |
448 static bool get _isWindows => false; | 456 static bool get _isWindows => false; |
449 | 457 |
450 @patch | 458 @patch |
451 static Uri get base { | 459 static Uri get base { |
452 String uri = Primitives.currentUri(); | 460 String uri = Primitives.currentUri(); |
453 if (uri != null) return Uri.parse(uri); | 461 if (uri != null) return Uri.parse(uri); |
454 throw new UnsupportedError("'Uri.base' is not supported"); | 462 throw new UnsupportedError("'Uri.base' is not supported"); |
455 } | 463 } |
456 } | 464 } |
OLD | NEW |