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, |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); | 23 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); |
24 | 24 |
25 @patch | 25 @patch |
26 int identityHashCode(Object object) => objectHashCode(object); | 26 int identityHashCode(Object object) => objectHashCode(object); |
27 | 27 |
28 // Patch for Object implementation. | 28 // Patch for Object implementation. |
29 @patch | 29 @patch |
30 class Object { | 30 class Object { |
31 @patch | 31 @patch |
| 32 bool operator==(other) => identical(this, other); |
| 33 |
| 34 @patch |
32 int get hashCode => Primitives.objectHashCode(this); | 35 int get hashCode => Primitives.objectHashCode(this); |
33 | 36 |
34 | |
35 @patch | 37 @patch |
36 String toString() => Primitives.objectToString(this); | 38 String toString() => Primitives.objectToString(this); |
37 | 39 |
38 @patch | 40 @patch |
39 dynamic noSuchMethod(Invocation invocation) { | 41 dynamic noSuchMethod(Invocation invocation) { |
40 throw new NoSuchMethodError( | 42 throw new NoSuchMethodError( |
41 this, | 43 this, |
42 invocation.memberName, | 44 invocation.memberName, |
43 invocation.positionalArguments, | 45 invocation.positionalArguments, |
44 invocation.namedArguments); | 46 invocation.namedArguments); |
45 } | 47 } |
46 | 48 |
47 @patch | 49 @patch |
48 Type get runtimeType => | 50 Type get runtimeType => |
49 JS('Type', 'dart.wrapType(dart.getReifiedType(#))', this); | 51 JS('Type', 'dart.wrapType(dart.getReifiedType(#))', this); |
50 } | 52 } |
51 | 53 |
| 54 @patch |
| 55 class Null { |
| 56 @patch |
| 57 int get hashCode => super.hashCode; |
| 58 } |
| 59 |
52 // Patch for Function implementation. | 60 // Patch for Function implementation. |
53 @patch | 61 @patch |
54 class Function { | 62 class Function { |
55 @patch | 63 @patch |
56 static apply(Function f, | 64 static apply(Function f, |
57 List positionalArguments, | 65 List positionalArguments, |
58 [Map<Symbol, dynamic> namedArguments]) { | 66 [Map<Symbol, dynamic> namedArguments]) { |
59 positionalArguments ??= []; | 67 positionalArguments ??= []; |
60 // dcall expects the namedArguments as a JS map in the last slot. | 68 // dcall expects the namedArguments as a JS map in the last slot. |
61 if (namedArguments != null && namedArguments.isNotEmpty) { | 69 if (namedArguments != null && namedArguments.isNotEmpty) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 157 |
150 @patch | 158 @patch |
151 static String _stringToSafeString(String string) { | 159 static String _stringToSafeString(String string) { |
152 return jsonEncodeNative(string); | 160 return jsonEncodeNative(string); |
153 } | 161 } |
154 | 162 |
155 @patch | 163 @patch |
156 StackTrace get stackTrace => Primitives.extractStackTrace(this); | 164 StackTrace get stackTrace => Primitives.extractStackTrace(this); |
157 } | 165 } |
158 | 166 |
| 167 @patch |
| 168 class FallThroughError { |
| 169 @patch |
| 170 String toString() => super.toString(); |
| 171 } |
| 172 |
| 173 @patch |
| 174 class AbstractClassInstantiationError { |
| 175 @patch |
| 176 String toString() => "Cannot instantiate abstract class: '$_className'"; |
| 177 } |
| 178 |
159 /// An interface type for all Strong-mode errors. | 179 /// An interface type for all Strong-mode errors. |
160 class StrongModeError extends Error {} | 180 class StrongModeError extends Error {} |
161 | 181 |
162 // Patch for DateTime implementation. | 182 // Patch for DateTime implementation. |
163 @patch | 183 @patch |
164 class DateTime { | 184 class DateTime { |
165 @patch | 185 @patch |
166 DateTime.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, | 186 DateTime.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, |
167 {bool isUtc: false}) | 187 {bool isUtc: false}) |
168 : this._withValue(millisecondsSinceEpoch, isUtc: isUtc); | 188 : this._withValue(millisecondsSinceEpoch, isUtc: isUtc); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 } | 440 } |
421 } | 441 } |
422 | 442 |
423 @patch | 443 @patch |
424 class bool { | 444 class bool { |
425 @patch | 445 @patch |
426 factory bool.fromEnvironment(String name, {bool defaultValue: false}) { | 446 factory bool.fromEnvironment(String name, {bool defaultValue: false}) { |
427 throw new UnsupportedError( | 447 throw new UnsupportedError( |
428 'bool.fromEnvironment can only be used as a const constructor'); | 448 'bool.fromEnvironment can only be used as a const constructor'); |
429 } | 449 } |
| 450 |
| 451 @patch |
| 452 int get hashCode => super.hashCode; |
430 } | 453 } |
431 | 454 |
432 @patch | 455 @patch |
433 class RegExp { | 456 class RegExp { |
434 @patch | 457 @patch |
435 factory RegExp(String source, | 458 factory RegExp(String source, |
436 {bool multiLine: false, | 459 {bool multiLine: false, |
437 bool caseSensitive: true}) | 460 bool caseSensitive: true}) |
438 => new JSSyntaxRegExp(source, | 461 => new JSSyntaxRegExp(source, |
439 multiLine: multiLine, | 462 multiLine: multiLine, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 529 } |
507 | 530 |
508 static String _writeOne(String string, Object obj) { | 531 static String _writeOne(String string, Object obj) { |
509 return Primitives.stringConcatUnchecked(string, '$obj'); | 532 return Primitives.stringConcatUnchecked(string, '$obj'); |
510 } | 533 } |
511 } | 534 } |
512 | 535 |
513 @patch | 536 @patch |
514 class NoSuchMethodError { | 537 class NoSuchMethodError { |
515 @patch | 538 @patch |
| 539 NoSuchMethodError(Object receiver, |
| 540 Symbol memberName, |
| 541 List positionalArguments, |
| 542 Map<Symbol, dynamic> namedArguments, |
| 543 [List existingArgumentNames = null]) |
| 544 : _receiver = receiver, |
| 545 _memberName = memberName, |
| 546 _arguments = positionalArguments, |
| 547 _namedArguments = namedArguments, |
| 548 _existingArgumentNames = existingArgumentNames; |
| 549 |
| 550 @patch |
516 String toString() { | 551 String toString() { |
517 StringBuffer sb = new StringBuffer(); | 552 StringBuffer sb = new StringBuffer(); |
518 int i = 0; | 553 int i = 0; |
519 if (_arguments != null) { | 554 if (_arguments != null) { |
520 for (; i < _arguments.length; i++) { | 555 for (; i < _arguments.length; i++) { |
521 if (i > 0) { | 556 if (i > 0) { |
522 sb.write(", "); | 557 sb.write(", "); |
523 } | 558 } |
524 sb.write(Error.safeToString(_arguments[i])); | 559 sb.write(Error.safeToString(_arguments[i])); |
525 } | 560 } |
(...skipping 28 matching lines...) Expand all Loading... |
554 "Receiver: ${Error.safeToString(_receiver)}\n" | 589 "Receiver: ${Error.safeToString(_receiver)}\n" |
555 "Tried calling: $_memberName($actualParameters)\n" | 590 "Tried calling: $_memberName($actualParameters)\n" |
556 "Found: $_memberName($formalParameters)"; | 591 "Found: $_memberName($formalParameters)"; |
557 } | 592 } |
558 } | 593 } |
559 } | 594 } |
560 | 595 |
561 @patch | 596 @patch |
562 class Uri { | 597 class Uri { |
563 @patch | 598 @patch |
564 static bool get _isWindows => false; | |
565 | |
566 @patch | |
567 static Uri get base { | 599 static Uri get base { |
568 String uri = Primitives.currentUri(); | 600 String uri = Primitives.currentUri(); |
569 if (uri != null) return Uri.parse(uri); | 601 if (uri != null) return Uri.parse(uri); |
570 throw new UnsupportedError("'Uri.base' is not supported"); | 602 throw new UnsupportedError("'Uri.base' is not supported"); |
571 } | 603 } |
| 604 } |
572 | 605 |
| 606 @patch |
| 607 class _Uri { |
| 608 @patch |
| 609 static bool get _isWindows => false; |
573 | 610 |
574 // Matches a String that _uriEncodes to itself regardless of the kind of | 611 // Matches a String that _uriEncodes to itself regardless of the kind of |
575 // component. This corresponds to [_unreservedTable], i.e. characters that | 612 // component. This corresponds to [_unreservedTable], i.e. characters that |
576 // are not encoded by any encoding table. | 613 // are not encoded by any encoding table. |
577 static final RegExp _needsNoEncoding = new RegExp(r'^[\-\.0-9A-Z_a-z~]*$'); | 614 static final RegExp _needsNoEncoding = new RegExp(r'^[\-\.0-9A-Z_a-z~]*$'); |
578 | 615 |
579 /** | 616 /** |
580 * This is the internal implementation of JavaScript's encodeURI function. | 617 * This is the internal implementation of JavaScript's encodeURI function. |
581 * It encodes all characters in the string [text] except for those | 618 * It encodes all characters in the string [text] except for those |
582 * that appear in [canonicalTable], and returns the escaped string. | 619 * that appear in [canonicalTable], and returns the escaped string. |
583 */ | 620 */ |
584 @patch | 621 @patch |
585 static String _uriEncode(List<int> canonicalTable, | 622 static String _uriEncode(List<int> canonicalTable, |
586 String text, | 623 String text, |
587 Encoding encoding, | 624 Encoding encoding, |
588 bool spaceToPlus) { | 625 bool spaceToPlus) { |
589 if (identical(encoding, UTF8) && _needsNoEncoding.hasMatch(text)) { | 626 if (identical(encoding, UTF8) && _needsNoEncoding.hasMatch(text)) { |
590 return text; | 627 return text; |
591 } | 628 } |
592 | 629 |
593 // Encode the string into bytes then generate an ASCII only string | 630 // Encode the string into bytes then generate an ASCII only string |
594 // by percent encoding selected bytes. | 631 // by percent encoding selected bytes. |
595 StringBuffer result = new StringBuffer(); | 632 StringBuffer result = new StringBuffer(''); |
596 var bytes = encoding.encode(text); | 633 var bytes = encoding.encode(text); |
597 for (int i = 0; i < bytes.length; i++) { | 634 for (int i = 0; i < bytes.length; i++) { |
598 int byte = bytes[i]; | 635 int byte = bytes[i]; |
599 if (byte < 128 && | 636 if (byte < 128 && |
600 ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) { | 637 ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) { |
601 result.writeCharCode(byte); | 638 result.writeCharCode(byte); |
602 } else if (spaceToPlus && byte == _SPACE) { | 639 } else if (spaceToPlus && byte == _SPACE) { |
603 result.write('+'); | 640 result.write('+'); |
604 } else { | 641 } else { |
605 const String hexDigits = '0123456789ABCDEF'; | 642 const String hexDigits = '0123456789ABCDEF'; |
606 result.write('%'); | 643 result.write('%'); |
607 result.write(hexDigits[(byte >> 4) & 0x0f]); | 644 result.write(hexDigits[(byte >> 4) & 0x0f]); |
608 result.write(hexDigits[byte & 0x0f]); | 645 result.write(hexDigits[byte & 0x0f]); |
609 } | 646 } |
610 } | 647 } |
611 return result.toString(); | 648 return result.toString(); |
612 } | 649 } |
613 } | 650 } |
614 | 651 |
615 @patch | 652 @patch |
616 class StackTrace { | 653 class StackTrace { |
617 @patch | 654 @patch |
618 @NoInline() | 655 @NoInline() |
619 static StackTrace get current { | 656 static StackTrace get current { |
620 return getTraceFromException(JS('', 'new Error()')); | 657 return getTraceFromException(JS('', 'new Error()')); |
621 } | 658 } |
622 } | 659 } |
OLD | NEW |