OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 part of dart._runtime; | 4 part of dart._runtime; |
5 | 5 |
6 // We need to set these properties while the sdk is only partially initialized | 6 // We need to set these properties while the sdk is only partially initialized |
7 // so we cannot use regular Dart fields. | 7 // so we cannot use regular Dart fields. |
8 // The default values for these properties are set when the global_ final field | 8 // The default values for these properties are set when the global_ final field |
9 // in runtime.dart is initialized. | 9 // in runtime.dart is initialized. |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 /// | 33 /// |
34 /// (There are many other ways that different `is` behavior can be observed, | 34 /// (There are many other ways that different `is` behavior can be observed, |
35 /// however, even with this flag. The most obvious is due to lack of reified | 35 /// however, even with this flag. The most obvious is due to lack of reified |
36 /// generic type parameters. This affects generic functions and methods, as | 36 /// generic type parameters. This affects generic functions and methods, as |
37 /// well as generic types when the type parameter was inferred. Setting this | 37 /// well as generic types when the type parameter was inferred. Setting this |
38 /// flag to `true` will not catch these differences in behavior..) | 38 /// flag to `true` will not catch these differences in behavior..) |
39 void failForWeakModeIsChecks(bool flag) { | 39 void failForWeakModeIsChecks(bool flag) { |
40 JS('', 'dart.__failForWeakModeIsChecks = #', flag); | 40 JS('', 'dart.__failForWeakModeIsChecks = #', flag); |
41 } | 41 } |
42 | 42 |
43 throwCastError(object, actual, type) => JS( | 43 throwCastError(object, actual, type) { |
44 '', | 44 var found = typeName(actual); |
45 '''(() => { | 45 var expected = typeName(type); |
46 var found = $typeName($actual); | 46 if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); |
47 var expected = $typeName($type); | 47 throw new CastErrorImplementation(object, found, expected); |
48 if (dart.__trapRuntimeErrors) debugger; | 48 } |
49 $throw_(new $CastErrorImplementation($object, found, expected)); | |
50 })()'''); | |
51 | 49 |
52 throwTypeError(object, actual, type) => JS( | 50 throwTypeError(object, actual, type) { |
53 '', | 51 var found = typeName(actual); |
54 '''(() => { | 52 var expected = typeName(type); |
55 var found = $typeName($actual); | 53 if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); |
56 var expected = $typeName($type); | 54 throw new TypeErrorImplementation(object, found, expected); |
57 if (dart.__trapRuntimeErrors) debugger; | 55 } |
58 $throw_(new $TypeErrorImplementation($object, found, expected)); | |
59 })()'''); | |
60 | 56 |
61 throwStrongModeCastError(object, actual, type) => JS( | 57 throwStrongModeCastError(object, actual, type) { |
62 '', | 58 var found = typeName(actual); |
63 '''(() => { | 59 var expected = typeName(type); |
64 var found = $typeName($actual); | 60 if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); |
65 var expected = $typeName($type); | 61 throw new StrongModeCastError(object, found, expected); |
66 if (dart.__trapRuntimeErrors) debugger; | 62 } |
67 $throw_(new $StrongModeCastError($object, found, expected)); | |
68 })()'''); | |
69 | 63 |
70 throwStrongModeTypeError(object, actual, type) => JS( | 64 throwStrongModeTypeError(object, actual, type) { |
71 '', | 65 var found = typeName(actual); |
72 '''(() => { | 66 var expected = typeName(type); |
73 var found = $typeName($actual); | 67 if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); |
74 var expected = $typeName($type); | 68 throw new StrongModeTypeError(object, found, expected); |
75 if (dart.__trapRuntimeErrors) debugger; | 69 } |
76 $throw_(new $StrongModeTypeError($object, found, expected)); | |
77 })()'''); | |
78 | 70 |
79 throwUnimplementedError(message) => JS( | 71 throwUnimplementedError(String message) { |
80 '', | 72 if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); |
81 '''(() => { | 73 throw new UnimplementedError(message); |
82 if (dart.__trapRuntimeErrors) debugger; | 74 } |
83 $throw_(new $UnimplementedError($message)); | |
84 })()'''); | |
85 | 75 |
86 throwAssertionError([message]) => JS( | 76 throwAssertionError([String message()]) { |
87 '', | 77 if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); |
88 '''(() => { | 78 throw message != null |
89 if (dart.__trapRuntimeErrors) debugger; | 79 ? new AssertionErrorWithMessage(message()) |
90 let error = $message != null | 80 : new AssertionError(); |
91 ? new $AssertionErrorWithMessage($message()) | 81 } |
92 : new $AssertionError(); | |
93 $throw_(error); | |
94 })()'''); | |
95 | 82 |
96 throwCyclicInitializationError([String message]) { | 83 throwCyclicInitializationError([String message]) { |
97 if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); | 84 if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); |
98 throw new CyclicInitializationError(message); | 85 throw new CyclicInitializationError(message); |
99 } | 86 } |
100 | 87 |
101 throwNullValueError() => JS( | 88 throwNullValueError() { |
102 '', | |
103 '''(() => { | |
104 // TODO(vsm): Per spec, we should throw an NSM here. Technically, we ought | 89 // TODO(vsm): Per spec, we should throw an NSM here. Technically, we ought |
105 // to thread through method info, but that uglifies the code and can't | 90 // to thread through method info, but that uglifies the code and can't |
106 // actually be queried ... it only affects how the error is printed. | 91 // actually be queried ... it only affects how the error is printed. |
107 if (dart.__trapRuntimeErrors) debugger; | 92 if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); |
108 $throw_(new $NoSuchMethodError(null, | 93 throw new NoSuchMethodError( |
109 new $Symbol('<Unexpected Null Value>'), null, null, null)); | 94 null, new Symbol('<Unexpected Null Value>'), null, null, null); |
110 })()'''); | 95 } |
111 | 96 |
112 throwNoSuchMethodError( | 97 throwNoSuchMethodError(Object receiver, Symbol memberName, |
113 receiver, memberName, positionalArguments, namedArguments) => | 98 List positionalArguments, Map<Symbol, dynamic> namedArguments) { |
114 JS( | 99 if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); |
115 '', | 100 throw new NoSuchMethodError( |
116 '''(() => { | 101 receiver, memberName, positionalArguments, namedArguments); |
117 if (dart.__trapRuntimeErrors) debugger; | 102 } |
118 $throw_(new $NoSuchMethodError($receiver, $memberName, $positionalArguments, $
namedArguments)); | |
119 })()'''); | |
OLD | NEW |