OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 typedef jsAst.Expression _ConstantReferenceGenerator(ConstantValue constant); | 7 typedef jsAst.Expression _ConstantReferenceGenerator(ConstantValue constant); |
8 | 8 |
9 typedef jsAst.Expression _ConstantListGenerator(jsAst.Expression array); | 9 typedef jsAst.Expression _ConstantListGenerator(jsAst.Expression array); |
10 | 10 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 return constant.payload; | 278 return constant.payload; |
279 default: | 279 default: |
280 reporter.internalError(NO_LOCATION_SPANNABLE, | 280 reporter.internalError(NO_LOCATION_SPANNABLE, |
281 "Unexpected DummyConstantKind ${constant.kind}"); | 281 "Unexpected DummyConstantKind ${constant.kind}"); |
282 return null; | 282 return null; |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 @override | 286 @override |
287 jsAst.Expression visitConstructed(ConstructedConstantValue constant, [_]) { | 287 jsAst.Expression visitConstructed(ConstructedConstantValue constant, [_]) { |
288 Element element = constant.type.element; | 288 ClassElement element = constant.type.element; |
289 if (backend.isForeign(element) && element.name == 'JS_CONST') { | 289 if (backend.isForeign(element) && element.name == 'JS_CONST') { |
290 StringConstantValue str = constant.fields.values.single; | 290 StringConstantValue str = constant.fields.values.single; |
291 String value = str.primitiveValue.slowToString(); | 291 String value = str.primitiveValue.slowToString(); |
292 return new jsAst.LiteralExpression(stripComments(value)); | 292 return new jsAst.LiteralExpression(stripComments(value)); |
293 } | 293 } |
294 jsAst.Expression constructor = | 294 jsAst.Expression constructor = |
295 backend.emitter.constructorAccess(constant.type.element); | 295 backend.emitter.constructorAccess(constant.type.element); |
296 List<jsAst.Expression> fields = constant.fields.values | 296 List<jsAst.Expression> fields = <jsAst.Expression>[]; |
297 .map(constantReferenceGenerator) | 297 element.forEachInstanceField((_, FieldElement field) { |
298 .toList(growable: false); | 298 fields.add(constantReferenceGenerator(constant.fields[field])); |
| 299 }, includeSuperAndInjectedMembers: true); |
299 jsAst.New instantiation = new jsAst.New(constructor, fields); | 300 jsAst.New instantiation = new jsAst.New(constructor, fields); |
300 return maybeAddTypeArguments(constant.type, instantiation); | 301 return maybeAddTypeArguments(constant.type, instantiation); |
301 } | 302 } |
302 | 303 |
303 String stripComments(String rawJavaScript) { | 304 String stripComments(String rawJavaScript) { |
304 return rawJavaScript.replaceAll(COMMENT_RE, ''); | 305 return rawJavaScript.replaceAll(COMMENT_RE, ''); |
305 } | 306 } |
306 | 307 |
307 jsAst.Expression maybeAddTypeArguments( | 308 jsAst.Expression maybeAddTypeArguments( |
308 InterfaceType type, jsAst.Expression value) { | 309 InterfaceType type, jsAst.Expression value) { |
(...skipping 12 matching lines...) Expand all Loading... |
321 [value, argumentList]); | 322 [value, argumentList]); |
322 } | 323 } |
323 return value; | 324 return value; |
324 } | 325 } |
325 | 326 |
326 @override | 327 @override |
327 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { | 328 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { |
328 return constantReferenceGenerator(constant.referenced); | 329 return constantReferenceGenerator(constant.referenced); |
329 } | 330 } |
330 } | 331 } |
OLD | NEW |