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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 /** | 7 /** |
8 * Categorizes `noSuchMethod` implementations. | 8 * Categorizes `noSuchMethod` implementations. |
9 * | 9 * |
10 * If user code includes `noSuchMethod` implementations, type inference is | 10 * If user code includes `noSuchMethod` implementations, type inference is |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 ClassElement classElement = element.enclosingClass; | 186 ClassElement classElement = element.enclosingClass; |
187 return classElement == _compiler.coreClasses.objectClass || | 187 return classElement == _compiler.coreClasses.objectClass || |
188 classElement == _backend.helpers.jsInterceptorClass || | 188 classElement == _backend.helpers.jsInterceptorClass || |
189 classElement == _backend.helpers.jsNullClass; | 189 classElement == _backend.helpers.jsNullClass; |
190 } | 190 } |
191 | 191 |
192 bool _hasForwardingSyntax(FunctionElement element) { | 192 bool _hasForwardingSyntax(FunctionElement element) { |
193 // At this point we know that this is signature-compatible with | 193 // At this point we know that this is signature-compatible with |
194 // Object.noSuchMethod, but it may have more than one argument as long as | 194 // Object.noSuchMethod, but it may have more than one argument as long as |
195 // it only has one required argument. | 195 // it only has one required argument. |
| 196 if (!element.hasResolvedAst) { |
| 197 // TODO(johnniwinther): Why do we see unresolved elements here? |
| 198 return false; |
| 199 } |
| 200 ResolvedAst resolvedAst = element.resolvedAst; |
| 201 if (resolvedAst.kind != ResolvedAstKind.PARSED) { |
| 202 return false; |
| 203 } |
196 String param = element.parameters.first.name; | 204 String param = element.parameters.first.name; |
197 Statement body = element.node.body; | 205 Statement body = resolvedAst.body; |
198 Expression expr; | 206 Expression expr; |
199 if (body is Return && body.isArrowBody) { | 207 if (body is Return && body.isArrowBody) { |
200 expr = body.expression; | 208 expr = body.expression; |
201 } else if (body is Block && | 209 } else if (body is Block && |
202 !body.statements.isEmpty && | 210 !body.statements.isEmpty && |
203 body.statements.nodes.tail.isEmpty) { | 211 body.statements.nodes.tail.isEmpty) { |
204 Statement stmt = body.statements.nodes.head; | 212 Statement stmt = body.statements.nodes.head; |
205 if (stmt is Return && stmt.hasExpression) { | 213 if (stmt is Return && stmt.hasExpression) { |
206 expr = stmt.expression; | 214 expr = stmt.expression; |
207 } | 215 } |
(...skipping 16 matching lines...) Expand all Loading... |
224 arg.receiver == null && | 232 arg.receiver == null && |
225 arg.selector is Identifier && | 233 arg.selector is Identifier && |
226 arg.selector.source == param) { | 234 arg.selector.source == param) { |
227 return true; | 235 return true; |
228 } | 236 } |
229 } | 237 } |
230 return false; | 238 return false; |
231 } | 239 } |
232 | 240 |
233 bool _hasThrowingSyntax(FunctionElement element) { | 241 bool _hasThrowingSyntax(FunctionElement element) { |
234 Statement body = element.node.body; | 242 if (!element.hasResolvedAst) { |
| 243 // TODO(johnniwinther): Why do we see unresolved elements here? |
| 244 return false; |
| 245 } |
| 246 ResolvedAst resolvedAst = element.resolvedAst; |
| 247 if (resolvedAst.kind != ResolvedAstKind.PARSED) { |
| 248 return false; |
| 249 } |
| 250 Statement body = resolvedAst.body; |
235 if (body is Return && body.isArrowBody) { | 251 if (body is Return && body.isArrowBody) { |
236 if (body.expression is Throw) { | 252 if (body.expression is Throw) { |
237 return true; | 253 return true; |
238 } | 254 } |
239 } else if (body is Block && | 255 } else if (body is Block && |
240 !body.statements.isEmpty && | 256 !body.statements.isEmpty && |
241 body.statements.nodes.tail.isEmpty) { | 257 body.statements.nodes.tail.isEmpty) { |
242 if (body.statements.nodes.head is ExpressionStatement) { | 258 if (body.statements.nodes.head is ExpressionStatement) { |
243 ExpressionStatement stmt = body.statements.nodes.head; | 259 ExpressionStatement stmt = body.statements.nodes.head; |
244 return stmt.expression is Throw; | 260 return stmt.expression is Throw; |
245 } | 261 } |
246 } | 262 } |
247 return false; | 263 return false; |
248 } | 264 } |
249 } | 265 } |
250 | 266 |
251 enum NsmCategory { DEFAULT, THROWING, NOT_APPLICABLE, OTHER, } | 267 enum NsmCategory { DEFAULT, THROWING, NOT_APPLICABLE, OTHER, } |
OLD | NEW |