Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/names.dart'; | 8 import '../common/names.dart'; |
| 9 import '../constants/constructors.dart'; | 9 import '../constants/constructors.dart'; |
| 10 import '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 /// Return `true` if [node] is the `dart:_foreign_helper` library. | 239 /// Return `true` if [node] is the `dart:_foreign_helper` library. |
| 240 bool isForeignLibrary(ir.Library node) { | 240 bool isForeignLibrary(ir.Library node) { |
| 241 return node.importUri == BackendHelpers.DART_FOREIGN_HELPER; | 241 return node.importUri == BackendHelpers.DART_FOREIGN_HELPER; |
| 242 } | 242 } |
| 243 | 243 |
| 244 /// Looks up [typeName] for use in the spec-string of a `JS` called. | 244 /// Looks up [typeName] for use in the spec-string of a `JS` called. |
| 245 // TODO(johnniwinther): Use this in [native.NativeBehavior] instead of calling | 245 // TODO(johnniwinther): Use this in [native.NativeBehavior] instead of calling |
| 246 // the `ForeignResolver`. | 246 // the `ForeignResolver`. |
| 247 // TODO(johnniwinther): Cache the result to avoid redundant lookups? | 247 // TODO(johnniwinther): Cache the result to avoid redundant lookups? |
| 248 native.TypeLookup typeLookup({bool resolveAsRaw: true}) { | 248 native.TypeLookup typeLookup({bool resolveAsRaw: true}) { |
| 249 return (String typeName) { | 249 DartType lookup(String typeName, {bool required}) { |
| 250 DartType findIn(Uri uri) { | 250 DartType findIn(Uri uri) { |
| 251 LibraryEntity library = elementEnvironment.lookupLibrary(uri); | 251 LibraryEntity library = elementEnvironment.lookupLibrary(uri); |
| 252 if (library != null) { | 252 if (library != null) { |
| 253 ClassEntity cls = elementEnvironment.lookupClass(library, typeName); | 253 ClassEntity cls = elementEnvironment.lookupClass(library, typeName); |
| 254 if (cls != null) { | 254 if (cls != null) { |
| 255 // TODO(johnniwinther): Align semantics. | 255 // TODO(johnniwinther): Align semantics. |
| 256 return resolveAsRaw | 256 return resolveAsRaw |
| 257 ? elementEnvironment.getRawType(cls) | 257 ? elementEnvironment.getRawType(cls) |
| 258 : elementEnvironment.getThisType(cls); | 258 : elementEnvironment.getThisType(cls); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 return null; | 261 return null; |
| 262 } | 262 } |
| 263 | 263 |
| 264 DartType type = findIn(Uris.dart_core); | 264 DartType type = findIn(Uris.dart_core); |
| 265 type ??= findIn(BackendHelpers.DART_JS_HELPER); | 265 type ??= findIn(BackendHelpers.DART_JS_HELPER); |
| 266 type ??= findIn(BackendHelpers.DART_INTERCEPTORS); | 266 type ??= findIn(BackendHelpers.DART_INTERCEPTORS); |
| 267 type ??= findIn(BackendHelpers.DART_ISOLATE_HELPER); | 267 type ??= findIn(BackendHelpers.DART_ISOLATE_HELPER); |
| 268 type ??= findIn(Uris.dart_collection); | 268 type ??= findIn(Uris.dart_collection); |
| 269 type ??= findIn(Uris.dart_html); | 269 type ??= findIn(Uris.dart_html); |
| 270 type ??= findIn(Uris.dart_svg); | 270 type ??= findIn(Uris.dart_svg); |
| 271 type ??= findIn(Uris.dart_web_audio); | 271 type ??= findIn(Uris.dart_web_audio); |
| 272 type ??= findIn(Uris.dart_web_gl); | 272 type ??= findIn(Uris.dart_web_gl); |
| 273 if (type == null && required) { | |
| 274 reporter.reportErrorMessage(CURRENT_ELEMENT_SPANNABLE, | |
| 275 MessageKind.GENERIC, {'text': "Type '$typeName' not found."}); | |
| 276 } | |
| 273 return type; | 277 return type; |
| 274 }; | 278 } |
| 279 | |
| 280 ; | |
|
Siggi Cherem (dart-lang)
2017/02/09 21:01:35
delete `;` :)
Johnni Winther
2017/02/10 09:38:24
Done.
| |
| 281 return lookup; | |
| 275 } | 282 } |
| 276 | 283 |
| 277 String _getStringArgument(ir.StaticInvocation node, int index) { | 284 String _getStringArgument(ir.StaticInvocation node, int index) { |
| 278 return node.arguments.positional[index].accept(new Stringifier()); | 285 return node.arguments.positional[index].accept(new Stringifier()); |
| 279 } | 286 } |
| 280 | 287 |
| 281 /// Computes the [native.NativeBehavior] for a call to the [JS] function. | 288 /// Computes the [native.NativeBehavior] for a call to the [JS] function. |
| 282 // TODO(johnniwinther): Cache this for later use. | 289 // TODO(johnniwinther): Cache this for later use. |
| 283 native.NativeBehavior getNativeBehaviorForJsCall(ir.StaticInvocation node) { | 290 native.NativeBehavior getNativeBehaviorForJsCall(ir.StaticInvocation node) { |
| 284 if (node.arguments.positional.length < 2 || | 291 if (node.arguments.positional.length < 2 || |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 } | 569 } |
| 563 if (isRedirecting) { | 570 if (isRedirecting) { |
| 564 return new RedirectingGenerativeConstantConstructor( | 571 return new RedirectingGenerativeConstantConstructor( |
| 565 defaultValues, superConstructorInvocation); | 572 defaultValues, superConstructorInvocation); |
| 566 } else { | 573 } else { |
| 567 return new GenerativeConstantConstructor( | 574 return new GenerativeConstantConstructor( |
| 568 type, defaultValues, fieldMap, superConstructorInvocation); | 575 type, defaultValues, fieldMap, superConstructorInvocation); |
| 569 } | 576 } |
| 570 } | 577 } |
| 571 } | 578 } |
| OLD | NEW |