OLD | NEW |
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:_foreign_helper' show | 9 import 'dart:_foreign_helper' show |
10 JS, | 10 JS, |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 } | 540 } |
541 | 541 |
542 throwRuntimeError(message) { | 542 throwRuntimeError(message) { |
543 throw new RuntimeError(message); | 543 throw new RuntimeError(message); |
544 } | 544 } |
545 | 545 |
546 throwAbstractClassInstantiationError(className) { | 546 throwAbstractClassInstantiationError(className) { |
547 throw new AbstractClassInstantiationError(className); | 547 throw new AbstractClassInstantiationError(className); |
548 } | 548 } |
549 | 549 |
| 550 |
| 551 @NoInline() |
| 552 throwConcurrentModificationError(collection) { |
| 553 throw new ConcurrentModificationError(collection); |
| 554 } |
| 555 |
550 class NullError extends Error implements NoSuchMethodError { | 556 class NullError extends Error implements NoSuchMethodError { |
551 final String _message; | 557 final String _message; |
552 final String _method; | 558 final String _method; |
553 | 559 |
554 NullError(this._message, match) | 560 NullError(this._message, match) |
555 : _method = match == null ? null : JS('', '#.method', match); | 561 : _method = match == null ? null : JS('', '#.method', match); |
556 | 562 |
557 String toString() { | 563 String toString() { |
558 if (_method == null) return 'NullError: $_message'; | 564 if (_method == null) return 'NullError: $_message'; |
559 return 'NullError: Cannot call "$_method" on null'; | 565 return "NullError: method not found: '$_method' on null"; |
560 } | 566 } |
561 } | 567 } |
562 | 568 |
563 class JsNoSuchMethodError extends Error implements NoSuchMethodError { | 569 class JsNoSuchMethodError extends Error implements NoSuchMethodError { |
564 final String _message; | 570 final String _message; |
565 final String _method; | 571 final String _method; |
566 final String _receiver; | 572 final String _receiver; |
567 | 573 |
568 JsNoSuchMethodError(this._message, match) | 574 JsNoSuchMethodError(this._message, match) |
569 : _method = match == null ? null : JS('String|Null', '#.method', match), | 575 : _method = match == null ? null : JS('String|Null', '#.method', match), |
570 _receiver = | 576 _receiver = |
571 match == null ? null : JS('String|Null', '#.receiver', match); | 577 match == null ? null : JS('String|Null', '#.receiver', match); |
572 | 578 |
573 String toString() { | 579 String toString() { |
574 if (_method == null) return 'NoSuchMethodError: $_message'; | 580 if (_method == null) return 'NoSuchMethodError: $_message'; |
575 if (_receiver == null) { | 581 if (_receiver == null) { |
576 return 'NoSuchMethodError: Cannot call "$_method" ($_message)'; | 582 return "NoSuchMethodError: method not found: '$_method' ($_message)"; |
577 } | 583 } |
578 return 'NoSuchMethodError: Cannot call "$_method" on "$_receiver" ' | 584 return "NoSuchMethodError: " |
579 '($_message)'; | 585 "method not found: '$_method' on '$_receiver' ($_message)"; |
580 } | 586 } |
581 } | 587 } |
582 | 588 |
583 class UnknownJsTypeError extends Error { | 589 class UnknownJsTypeError extends Error { |
584 final String _message; | 590 final String _message; |
585 | 591 |
586 UnknownJsTypeError(this._message); | 592 UnknownJsTypeError(this._message); |
587 | 593 |
588 String toString() => _message.isEmpty ? 'Error' : 'Error: $_message'; | 594 String toString() => _message.isEmpty ? 'Error' : 'Error: $_message'; |
589 } | 595 } |
590 | 596 |
591 /** | 597 /** |
592 * Called by generated code to fetch the stack trace from an | 598 * Called by generated code to fetch the stack trace from an |
593 * exception. Should never return null. | 599 * exception. Should never return null. |
594 */ | 600 */ |
595 StackTrace getTraceFromException(exception) => new _StackTrace(exception); | 601 StackTrace getTraceFromException(exception) => new _StackTrace(exception); |
596 | 602 |
597 class _StackTrace implements StackTrace { | 603 class _StackTrace implements StackTrace { |
598 var _exception; | 604 var _exception; |
599 String _trace; | 605 String _trace; |
600 _StackTrace(this._exception); | 606 _StackTrace(this._exception); |
601 | 607 |
602 String toString() { | 608 String toString() { |
603 if (_trace != null) return _trace; | 609 if (_trace != null) return JS('String', '#', _trace); |
604 | 610 |
605 String trace; | 611 String trace; |
606 if (JS('bool', 'typeof # === "object"', _exception)) { | 612 if (JS('bool', '# !== null', _exception) && |
| 613 JS('bool', 'typeof # === "object"', _exception)) { |
607 trace = JS("String|Null", r"#.stack", _exception); | 614 trace = JS("String|Null", r"#.stack", _exception); |
608 } | 615 } |
609 return _trace = (trace == null) ? '' : trace; | 616 return _trace = (trace == null) ? '' : trace; |
610 } | 617 } |
611 } | 618 } |
612 | 619 |
613 int objectHashCode(var object) { | 620 int objectHashCode(var object) { |
614 if (object == null || JS('bool', "typeof # != 'object'", object)) { | 621 if (object == null || JS('bool', "typeof # != 'object'", object)) { |
615 return object.hashCode; | 622 return object.hashCode; |
616 } else { | 623 } else { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 836 |
830 SyncIterable(this._generator, this._args); | 837 SyncIterable(this._generator, this._args); |
831 | 838 |
832 // TODO(jmesserly): this should be [Symbol.iterator]() method. Unfortunately | 839 // TODO(jmesserly): this should be [Symbol.iterator]() method. Unfortunately |
833 // we have no way of telling the compiler yet, so it will generate an extra | 840 // we have no way of telling the compiler yet, so it will generate an extra |
834 // layer of indirection that wraps the SyncIterator. | 841 // layer of indirection that wraps the SyncIterator. |
835 _jsIterator() => JS('', '#(...#)', _generator, _args); | 842 _jsIterator() => JS('', '#(...#)', _generator, _args); |
836 | 843 |
837 Iterator<E> get iterator => new SyncIterator<E>(_jsIterator()); | 844 Iterator<E> get iterator => new SyncIterator<E>(_jsIterator()); |
838 } | 845 } |
OLD | NEW |