Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js.new_js_emitter.model_emitter; | 5 library dart2js.new_js_emitter.model_emitter; |
| 6 | 6 |
| 7 import '../../dart2jslib.dart' show Compiler; | 7 import '../../dart2jslib.dart' show Compiler; |
| 8 import '../../js/js.dart' as js; | 8 import '../../js/js.dart' as js; |
| 9 import '../../js_backend/js_backend.dart' show | 9 import '../../js_backend/js_backend.dart' show |
| 10 JavaScriptBackend, | 10 JavaScriptBackend, |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 List elements = [js.string(cls.superclassName), | 388 List elements = [js.string(cls.superclassName), |
| 389 js.number(cls.superclassHolderIndex)]; | 389 js.number(cls.superclassHolderIndex)]; |
| 390 | 390 |
| 391 if (cls.isMixinApplication) { | 391 if (cls.isMixinApplication) { |
| 392 MixinApplication mixin = cls; | 392 MixinApplication mixin = cls; |
| 393 elements.add(js.string(mixin.mixinClass.name)); | 393 elements.add(js.string(mixin.mixinClass.name)); |
| 394 elements.add(js.number(mixin.mixinClass.holder.index)); | 394 elements.add(js.number(mixin.mixinClass.holder.index)); |
| 395 } else { | 395 } else { |
| 396 elements.add(_generateConstructor(cls)); | 396 elements.add(_generateConstructor(cls)); |
| 397 } | 397 } |
| 398 Iterable<Method> methods = cls.methods.expand((Method method) { | 398 Iterable<Method> methods = cls.methods; |
| 399 // TODO(floitsch): can there be anything else than a DartMethod? | |
| 400 if (method is DartMethod) { | |
| 401 return [method]..addAll(method.parameterStubs); | |
| 402 } else { | |
| 403 return [method]; | |
| 404 } | |
| 405 }); | |
| 406 Iterable<Method> isChecks = cls.isChecks; | 399 Iterable<Method> isChecks = cls.isChecks; |
| 407 Iterable<Method> gettersSetters = _generateGettersSetters(cls); | 400 Iterable<Method> gettersSetters = _generateGettersSetters(cls); |
| 408 Iterable<Method> allMethods = | 401 Iterable<Method> allMethods = |
| 409 [methods, isChecks, gettersSetters].expand((x) => x); | 402 [methods, isChecks, gettersSetters].expand((x) => x); |
| 410 elements.addAll(allMethods.expand((e) => [js.string(e.name), e.code])); | 403 elements.addAll(allMethods.expand(emitInstanceMethod)); |
| 411 return unparse(compiler, new js.ArrayInitializer(elements)); | 404 return unparse(compiler, new js.ArrayInitializer(elements)); |
| 412 } | 405 } |
| 413 | 406 |
| 414 js.Expression emitLazyInitializer(StaticField field) { | 407 js.Expression emitLazyInitializer(StaticField field) { |
| 415 assert(field.isLazy); | 408 assert(field.isLazy); |
| 416 return unparse(compiler, field.code); | 409 return unparse(compiler, field.code); |
| 417 } | 410 } |
| 418 | 411 |
| 412 static final String tearOffBoilerplate = """ | |
| 413 function(prototype, tearOffDescriptor) { | |
| 414 prototype[tearOffDescriptor[0]] = tearOffDescriptor[1]; | |
| 415 for (var i = 3; i < tearOffDescriptor.length; i += 3) { | |
| 416 // Copy over the parameter stubs. | |
| 417 prototype[tearOffDescriptor[i]] = tearOffDescriptor[i + 2]; | |
| 418 } | |
| 419 // Build the functions map. | |
| 420 var funcs = Object.create(null); | |
| 421 for (var i = 3; i < tearOffDescriptor.length; i += 3) { | |
| 422 // Copy over the parameter stubs. | |
| 423 prototype[tearOffDescriptor[i]] = tearOffDescriptor[i + 2]; | |
| 424 } | |
| 425 | |
| 426 } | |
| 427 """; | |
| 428 | |
| 429 Iterable<js.Expression> emitInstanceMethod(Method method) { | |
| 430 | |
| 431 List<js.Expression> makeNameCodePair(Method method) { | |
| 432 return [js.string(method.name), method.code]; | |
| 433 } | |
| 434 | |
| 435 List<js.Expression> makeNameCallNameCodeTriplet(ParameterStubMethod stub) { | |
| 436 js.Expression callName = stub.callName == null | |
| 437 ? new js.LiteralNull() | |
| 438 : js.string(stub.callName); | |
| 439 return [js.string(stub.name), callName, method.code]; | |
| 440 } | |
| 441 | |
| 442 if (method is DartMethod) { | |
| 443 if (method.needsTearOff) { | |
| 444 var data = makeNameCodePair(method); | |
| 445 data.add(js.string(method.tearOffName)); | |
| 446 data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet)); | |
| 447 return [new js.ArrayInitializer(data)]; | |
| 448 } else { | |
| 449 // TODO(floitsch): not the most efficient way... | |
| 450 return ([method]..addAll(method.parameterStubs)).expand(makeNameCodePair ); | |
|
zarah
2015/01/30 14:24:23
long line.
| |
| 451 } | |
| 452 } else { | |
| 453 return makeNameCodePair(method); | |
| 454 } | |
| 455 } | |
| 456 | |
| 419 Iterable<js.Expression> emitStaticMethod(StaticMethod method) { | 457 Iterable<js.Expression> emitStaticMethod(StaticMethod method) { |
| 420 js.Expression holderIndex = js.number(method.holder.index); | 458 js.Expression holderIndex = js.number(method.holder.index); |
| 421 List<js.Expression> output = <js.Expression>[]; | 459 List<js.Expression> output = <js.Expression>[]; |
| 422 | 460 |
| 423 void _addMethod(Method method) { | 461 void _addMethod(Method method) { |
| 424 js.Expression unparsed = unparse(compiler, method.code); | 462 js.Expression unparsed = unparse(compiler, method.code); |
| 425 output.add(js.string(method.name)); | 463 output.add(js.string(method.name)); |
| 426 output.add(holderIndex); | 464 output.add(holderIndex); |
| 427 output.add(unparsed); | 465 output.add(unparsed); |
| 428 } | 466 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 | 661 |
| 624 var end = Date.now(); | 662 var end = Date.now(); |
| 625 print('Setup: ' + (end - start) + ' ms.'); | 663 print('Setup: ' + (end - start) + ' ms.'); |
| 626 | 664 |
| 627 #main(); // Start main. | 665 #main(); // Start main. |
| 628 | 666 |
| 629 }(Date.now(), #code) | 667 }(Date.now(), #code) |
| 630 }"""; | 668 }"""; |
| 631 | 669 |
| 632 } | 670 } |
| OLD | NEW |