| 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 assert(field.isLazy); | 411 assert(field.isLazy); |
| 412 return unparse(compiler, field.code); | 412 return unparse(compiler, field.code); |
| 413 } | 413 } |
| 414 | 414 |
| 415 static final String parseFunctionDescriptorBoilerplate = r""" | 415 static final String parseFunctionDescriptorBoilerplate = r""" |
| 416 function parseFunctionDescriptor(proto, name, desc) { | 416 function parseFunctionDescriptor(proto, name, desc) { |
| 417 if (desc instanceof Array) { | 417 if (desc instanceof Array) { |
| 418 proto[name] = desc[0]; | 418 proto[name] = desc[0]; |
| 419 var funs = [desc[0]]; | 419 var funs = [desc[0]]; |
| 420 funs[0].$callName = desc[1]; | 420 funs[0].$callName = desc[1]; |
| 421 for (var pos = 4; pos < desc.length; pos += 3) { | 421 for (var pos = 5; pos < desc.length; pos += 3) { |
| 422 var stub = desc[pos+2]; | 422 var stub = desc[pos+2]; |
| 423 stub.$callName = desc[pos+1]; | 423 stub.$callName = desc[pos+1]; |
| 424 proto[desc[pos]] = stub; | 424 proto[desc[pos]] = stub; |
| 425 funs.push(stub); | 425 funs.push(stub); |
| 426 } | 426 } |
| 427 if (desc[2] != null) { | 427 if (desc[2] != null) { |
| 428 proto[desc[2]] = tearOff(funs, desc[3], false, name, false); | 428 proto[desc[2]] = tearOff(funs, desc[3], false, name, false); |
| 429 } | 429 } |
| 430 // Install the alias for super calls on the prototype chain. |
| 431 if (desc[4] != null) { |
| 432 proto[desc[4]] = desc[0]; |
| 433 } |
| 430 } else { | 434 } else { |
| 431 proto[name] = desc; | 435 proto[name] = desc; |
| 432 } | 436 } |
| 433 } | 437 } |
| 434 """; | 438 """; |
| 435 | 439 |
| 436 Iterable<js.Expression> emitInstanceMethod(Method method) { | 440 Iterable<js.Expression> emitInstanceMethod(InstanceMethod method) { |
| 437 | 441 |
| 438 List<js.Expression> makeNameCodePair(Method method) { | 442 List<js.Expression> makeNameCodePair(Method method) { |
| 439 return [js.string(method.name), method.code]; | 443 return [js.string(method.name), method.code]; |
| 440 } | 444 } |
| 441 | 445 |
| 442 List<js.Expression> makeNameCallNameCodeTriplet(AdapterStubMethod stub) { | 446 List<js.Expression> makeNameCallNameCodeTriplet(AdapterStubMethod stub) { |
| 443 js.Expression callName = stub.callName == null | 447 js.Expression callName = stub.callName == null |
| 444 ? new js.LiteralNull() | 448 ? new js.LiteralNull() |
| 445 : js.string(stub.callName); | 449 : js.string(stub.callName); |
| 446 return [js.string(stub.name), callName, method.code]; | 450 return [js.string(stub.name), callName, method.code]; |
| 447 } | 451 } |
| 448 | 452 |
| 449 if (method is DartMethod) { | 453 if (method is DartMethod) { |
| 450 if (method.needsTearOff) { | 454 if (method.needsTearOff || method.superAlias != null) { |
| 451 // [name, [function, callName, tearOffName, functionType, | 455 // [name, [function, callName, tearOffName, functionType, aliasName, |
| 452 // stub1_name, stub1_callName, stub1_code, ...] | 456 // stub1_name, stub1_callName, stub1_code, ...] |
| 453 var data = [method.code]; | 457 var data = [method.code]; |
| 454 data.add(js.string(method.callName)); | 458 data.add(js.string(method.callName)); |
| 455 data.add(js.string(method.tearOffName)); | 459 data.add(js.string(method.tearOffName)); |
| 456 data.add(new js.LiteralNull()); | 460 data.add(new js.LiteralNull()); |
| 461 if (method.superAlias != null) { |
| 462 data.add(js.string(method.superAlias)); |
| 463 } else { |
| 464 data.add(new js.LiteralNull()); |
| 465 } |
| 457 data.addAll(method.adapterStubs.expand(makeNameCallNameCodeTriplet)); | 466 data.addAll(method.adapterStubs.expand(makeNameCallNameCodeTriplet)); |
| 458 return [js.string(method.name), new js.ArrayInitializer(data)]; | 467 return [js.string(method.name), new js.ArrayInitializer(data)]; |
| 459 } else { | 468 } else { |
| 460 // TODO(floitsch): not the most efficient way... | 469 // TODO(floitsch): not the most efficient way... |
| 461 return ([method]..addAll(method.adapterStubs)).expand(makeNameCodePair); | 470 return ([method]..addAll(method.adapterStubs)).expand(makeNameCodePair); |
| 462 } | 471 } |
| 463 } else { | 472 } else { |
| 464 return makeNameCodePair(method); | 473 return makeNameCodePair(method); |
| 465 } | 474 } |
| 466 } | 475 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 685 |
| 677 var end = Date.now(); | 686 var end = Date.now(); |
| 678 print('Setup: ' + (end - start) + ' ms.'); | 687 print('Setup: ' + (end - start) + ' ms.'); |
| 679 | 688 |
| 680 #main(); // Start main. | 689 #main(); // Start main. |
| 681 | 690 |
| 682 }(Date.now(), #code) | 691 }(Date.now(), #code) |
| 683 }"""; | 692 }"""; |
| 684 | 693 |
| 685 } | 694 } |
| OLD | NEW |