| 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 | 4 |
| 5 /// This library defines runtime operations on objects used by the code | 5 /// This library defines runtime operations on objects used by the code |
| 6 /// generator. | 6 /// generator. |
| 7 part of dart._runtime; | 7 part of dart._runtime; |
| 8 | 8 |
| 9 _canonicalFieldName(obj, name, args, displayName) => JS('', '''(() => { | 9 _canonicalFieldName(obj, name, args, displayName) => JS('', '''(() => { |
| 10 $name = $canonicalMember($obj, $name); | 10 $name = $canonicalMember($obj, $name); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 dsetindex(obj, index, value) => JS('', '''(() => { | 146 dsetindex(obj, index, value) => JS('', '''(() => { |
| 147 $callMethod($obj, 'set', [$index, $value], '[]='); | 147 $callMethod($obj, 'set', [$index, $value], '[]='); |
| 148 return $value; | 148 return $value; |
| 149 })()'''); | 149 })()'''); |
| 150 | 150 |
| 151 _ignoreTypeFailure(actual, type) => JS('', '''(() => { | 151 _ignoreTypeFailure(actual, type) => JS('', '''(() => { |
| 152 // TODO(vsm): Remove this hack ... | 152 // TODO(vsm): Remove this hack ... |
| 153 // This is primarily due to the lack of generic methods, | 153 // This is primarily due to the lack of generic methods, |
| 154 // but we need to triage all the types. | 154 // but we need to triage all the types. |
| 155 if (isSubtype($type, $Iterable) && isSubtype($actual, $Iterable) || | 155 if ($isSubtype($type, $Iterable) && $isSubtype($actual, $Iterable) || |
| 156 isSubtype($type, $Future) && isSubtype($actual, $Future) || | 156 $isSubtype($type, $Future) && $isSubtype($actual, $Future) || |
| 157 isSubtype($type, $Map) && isSubtype($actual, $Map) || | 157 $isSubtype($type, $Map) && $isSubtype($actual, $Map) || |
| 158 isSubtype($type, $Function) && isSubtype($actual, $Function) || | 158 $isSubtype($type, $Function) && $isSubtype($actual, $Function) || |
| 159 isSubtype($type, $Stream) && isSubtype($actual, $Stream) || | 159 $isSubtype($type, $Stream) && $isSubtype($actual, $Stream) || |
| 160 isSubtype($type, $StreamSubscription) && | 160 $isSubtype($type, $StreamSubscription) && |
| 161 isSubtype($actual, $StreamSubscription)) { | 161 $isSubtype($actual, $StreamSubscription)) { |
| 162 console.warn('Ignoring cast fail from ' + $typeName($actual) + | 162 console.warn('Ignoring cast fail from ' + $typeName($actual) + |
| 163 ' to ' + $typeName($type)); | 163 ' to ' + $typeName($type)); |
| 164 return true; | 164 return true; |
| 165 } | 165 } |
| 166 return false; | 166 return false; |
| 167 })()'''); | 167 })()'''); |
| 168 | 168 |
| 169 strongInstanceOf(obj, type, ignoreFromWhiteList) => JS('', '''(() => { | 169 strongInstanceOf(obj, type, ignoreFromWhiteList) => JS('', '''(() => { |
| 170 let actual = $realRuntimeType($obj); | 170 let actual = $realRuntimeType($obj); |
| 171 if ($isSubtype(actual, $type) || actual == $jsobject || | 171 if ($isSubtype(actual, $type) || actual == $jsobject || |
| 172 actual == $int && type == $double) return true; | 172 actual == $int && type == $double) return true; |
| 173 if ($ignoreFromWhiteList == void 0) return false; | 173 if ($ignoreFromWhiteList == void 0) return false; |
| 174 if ($isGroundType($type)) return false; | 174 if ($isGroundType($type)) return false; |
| 175 if ($_ignoreTypeFailure(actual, $type)) return true; | 175 if ($_ignoreTypeFailure(actual, $type)) return true; |
| 176 return false; | 176 return false; |
| 177 })()'''); | 177 })()'''); |
| 178 | 178 |
| 179 instanceOfOrNull(obj, type) => JS('', '''(() => { | 179 instanceOfOrNull(obj, type) => JS('', '''(() => { |
| 180 if (($obj == null) || $strongInstanceOf($obj, $type, true)) return true; | 180 if (($obj == null) || $strongInstanceOf($obj, $type, true)) return true; |
| 181 return false; | 181 return false; |
| 182 })()'''); | 182 })()'''); |
| 183 | 183 |
| 184 @JSExportName('is') |
| 184 instanceOf(obj, type) => JS('', '''(() => { | 185 instanceOf(obj, type) => JS('', '''(() => { |
| 185 if ($strongInstanceOf($obj, $type)) return true; | 186 if ($strongInstanceOf($obj, $type)) return true; |
| 186 // TODO(#296): This is perhaps too eager to throw a StrongModeError? | 187 // TODO(#296): This is perhaps too eager to throw a StrongModeError? |
| 187 // It will throw on <int>[] is List<String>. | 188 // It will throw on <int>[] is List<String>. |
| 188 // TODO(vsm): We can statically detect many cases where this | 189 // TODO(vsm): We can statically detect many cases where this |
| 189 // check is unnecessary. | 190 // check is unnecessary. |
| 190 if ($isGroundType($type)) return false; | 191 if ($isGroundType($type)) return false; |
| 191 let actual = $realRuntimeType($obj); | 192 let actual = $realRuntimeType($obj); |
| 192 $throwStrongModeError('Strong mode is check failure: ' + | 193 $throwStrongModeError('Strong mode is check failure: ' + |
| 193 $typeName(actual) + ' does not soundly subtype ' + | 194 $typeName(actual) + ' does not soundly subtype ' + |
| 194 $typeName($type)); | 195 $typeName($type)); |
| 195 })()'''); | 196 })()'''); |
| 196 | 197 |
| 198 @JSExportName('as') |
| 197 cast(obj, type) => JS('', '''(() => { | 199 cast(obj, type) => JS('', '''(() => { |
| 198 // TODO(#296): This is perhaps too eager to throw a StrongModeError? | 200 // TODO(#296): This is perhaps too eager to throw a StrongModeError? |
| 199 // TODO(vsm): handle non-nullable types | 201 // TODO(vsm): handle non-nullable types |
| 200 if ($instanceOfOrNull($obj, $type)) return $obj; | 202 if ($instanceOfOrNull($obj, $type)) return $obj; |
| 201 let actual = $realRuntimeType($obj); | 203 let actual = $realRuntimeType($obj); |
| 202 if ($isGroundType($type)) $throwCastError(actual, $type); | 204 if ($isGroundType($type)) $throwCastError(actual, $type); |
| 203 | 205 |
| 204 if ($_ignoreTypeFailure(actual, $type)) return $obj; | 206 if ($_ignoreTypeFailure(actual, $type)) return $obj; |
| 205 | 207 |
| 206 $throwStrongModeError('Strong mode cast failure from ' + | 208 $throwStrongModeError('Strong mode cast failure from ' + |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 constructor(dartIterator) { | 427 constructor(dartIterator) { |
| 426 this.dartIterator = dartIterator; | 428 this.dartIterator = dartIterator; |
| 427 } | 429 } |
| 428 next() { | 430 next() { |
| 429 let i = this.dartIterator; | 431 let i = this.dartIterator; |
| 430 let done = !i.moveNext(); | 432 let done = !i.moveNext(); |
| 431 return { done: done, value: done ? void 0 : i.current }; | 433 return { done: done, value: done ? void 0 : i.current }; |
| 432 } | 434 } |
| 433 } | 435 } |
| 434 '''); | 436 '''); |
| OLD | NEW |