| 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 '../../dart_types.dart' show DartType; | 8 import '../../dart_types.dart' show DartType; |
| 9 import '../../js/js.dart' as js; | 9 import '../../js/js.dart' as js; |
| 10 import '../../js_backend/js_backend.dart' show | 10 import '../../js_backend/js_backend.dart' show |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 /// Descriptors are used in place of the actual JavaScript function | 422 /// Descriptors are used in place of the actual JavaScript function |
| 423 /// definition in the output if additional information needs to be passed to | 423 /// definition in the output if additional information needs to be passed to |
| 424 /// facilitate the generation of tearOffs at runtime. The format is an array | 424 /// facilitate the generation of tearOffs at runtime. The format is an array |
| 425 /// with the following fields: | 425 /// with the following fields: |
| 426 /// | 426 /// |
| 427 /// [Method.code] | 427 /// [Method.code] |
| 428 /// [DartMethod.callName] | 428 /// [DartMethod.callName] |
| 429 /// [DartMethod.tearOffName] | 429 /// [DartMethod.tearOffName] |
| 430 /// [JavaScriptBackend.isInterceptedMethod] | 430 /// [JavaScriptBackend.isInterceptedMethod] |
| 431 /// functionType | 431 /// functionType |
| 432 /// [InstanceMethod.aliasName] |
| 432 /// | 433 /// |
| 433 /// followed by | 434 /// followed by |
| 434 /// | 435 /// |
| 435 /// [ParameterStubMethod.name] | 436 /// [ParameterStubMethod.name] |
| 436 /// [ParameterStubMethod.code] | 437 /// [ParameterStubMethod.code] |
| 437 /// | 438 /// |
| 438 /// for each stub in [DartMethod.parameterStubs]. | 439 /// for each stub in [DartMethod.parameterStubs]. |
| 439 | 440 |
| 440 static final String parseFunctionDescriptorBoilerplate = r""" | 441 static final String parseFunctionDescriptorBoilerplate = r""" |
| 441 function parseFunctionDescriptor(proto, name, descriptor) { | 442 function parseFunctionDescriptor(proto, name, descriptor) { |
| 442 if (descriptor instanceof Array) { | 443 if (descriptor instanceof Array) { |
| 443 proto[name] = descriptor[0]; | 444 proto[name] = descriptor[0]; |
| 444 var funs = [descriptor[0]]; | 445 var funs = [descriptor[0]]; |
| 445 funs[0].$callName = descriptor[1]; | 446 funs[0].$callName = descriptor[1]; |
| 446 for (var pos = 5; pos < descriptor.length; pos += 3) { | 447 for (var pos = 6; pos < descriptor.length; pos += 3) { |
| 447 var stub = descriptor[pos + 2]; | 448 var stub = descriptor[pos + 2]; |
| 448 stub.$callName = descriptor[pos + 1]; | 449 stub.$callName = descriptor[pos + 1]; |
| 449 proto[descriptor[pos]] = stub; | 450 proto[descriptor[pos]] = stub; |
| 450 funs.push(stub); | 451 funs.push(stub); |
| 451 } | 452 } |
| 452 if (descriptor[2] != null) { | 453 if (descriptor[2] != null) { |
| 453 var isIntercepted = descriptor[3]; | 454 var isIntercepted = descriptor[3]; |
| 454 var reflectionInfo = descriptor[4]; | 455 var reflectionInfo = descriptor[4]; |
| 455 proto[descriptor[2]] = | 456 proto[descriptor[2]] = |
| 456 tearOff(funs, reflectionInfo, false, name, isIntercepted); | 457 tearOff(funs, reflectionInfo, false, name, isIntercepted); |
| 457 } | 458 } |
| 459 // Install the alias for super calls on the prototype chain. |
| 460 if (desc[5] != null) { |
| 461 proto[desc[5]] = desc[0]; |
| 462 } |
| 458 } else { | 463 } else { |
| 459 proto[name] = descriptor; | 464 proto[name] = descriptor; |
| 460 } | 465 } |
| 461 } | 466 } |
| 462 """; | 467 """; |
| 463 | 468 |
| 464 js.Expression _generateFunctionType(DartType memberType) { | 469 js.Expression _generateFunctionType(DartType memberType) { |
| 465 if (memberType.containsTypeVariables) { | 470 if (memberType.containsTypeVariables) { |
| 466 js.Expression thisAccess = js.js(r'this.$receiver'); | 471 js.Expression thisAccess = js.js(r'this.$receiver'); |
| 467 return backend.rti.getSignatureEncoding(memberType, thisAccess); | 472 return backend.rti.getSignatureEncoding(memberType, thisAccess); |
| 468 } else { | 473 } else { |
| 469 return js.number(backend.emitter.metadataCollector.reifyType(memberType)); | 474 return js.number(backend.emitter.metadataCollector.reifyType(memberType)); |
| 470 } | 475 } |
| 471 } | 476 } |
| 472 | 477 |
| 473 Iterable<js.Expression> emitInstanceMethod(Method method) { | 478 Iterable<js.Expression> emitInstanceMethod(Method method) { |
| 474 | 479 |
| 475 List<js.Expression> makeNameCodePair(Method method) { | 480 List<js.Expression> makeNameCodePair(Method method) { |
| 476 return [js.string(method.name), method.code]; | 481 return [js.string(method.name), method.code]; |
| 477 } | 482 } |
| 478 | 483 |
| 479 List<js.Expression> makeNameCallNameCodeTriplet(ParameterStubMethod stub) { | 484 List<js.Expression> makeNameCallNameCodeTriplet(ParameterStubMethod stub) { |
| 480 js.Expression callName = stub.callName == null | 485 js.Expression callName = stub.callName == null |
| 481 ? new js.LiteralNull() | 486 ? new js.LiteralNull() |
| 482 : js.string(stub.callName); | 487 : js.string(stub.callName); |
| 483 return [js.string(stub.name), callName, stub.code]; | 488 return [js.string(stub.name), callName, stub.code]; |
| 484 } | 489 } |
| 485 | 490 |
| 486 if (method is DartMethod) { | 491 if (method is InstanceMethod) { |
| 487 if (method.needsTearOff) { | 492 if (method.needsTearOff || method.aliasName != null) { |
| 488 /// See [parseFunctionDescriptorBoilerplate] for a full description of | 493 /// See [parseFunctionDescriptorBoilerplate] for a full description of |
| 489 /// the format. | 494 /// the format. |
| 490 // [name, [function, callName, tearOffName, isIntercepted, functionType, | 495 // [name, [function, callName, tearOffName, isIntercepted, functionType, |
| 491 // stub1_name, stub1_callName, stub1_code, ...] | 496 // aliasName, stub1_name, stub1_callName, stub1_code, ...] |
| 492 bool isIntercepted = backend.isInterceptedMethod(method.element); | 497 bool isIntercepted = backend.isInterceptedMethod(method.element); |
| 493 var data = [method.code]; | 498 var data = [method.code]; |
| 494 data.add(js.string(method.callName)); | 499 data.add(js.string(method.callName)); |
| 495 data.add(js.string(method.tearOffName)); | 500 data.add(js.string(method.tearOffName)); |
| 496 data.add(new js.LiteralBool(isIntercepted)); | 501 data.add(new js.LiteralBool(isIntercepted)); |
| 497 data.add(_generateFunctionType(method.type)); | 502 data.add(_generateFunctionType(method.type)); |
| 503 if (method.aliasName != null) { |
| 504 data.add(js.string(method.aliasName)); |
| 505 } else { |
| 506 data.add(new js.LiteralNull()); |
| 507 } |
| 498 data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet)); | 508 data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet)); |
| 499 return [js.string(method.name), new js.ArrayInitializer(data)]; | 509 return [js.string(method.name), new js.ArrayInitializer(data)]; |
| 500 } else { | 510 } else { |
| 501 // TODO(floitsch): not the most efficient way... | 511 // TODO(floitsch): not the most efficient way... |
| 502 return ([method]..addAll(method.parameterStubs)) | 512 return ([method]..addAll(method.parameterStubs)) |
| 503 .expand(makeNameCodePair); | 513 .expand(makeNameCodePair); |
| 504 } | 514 } |
| 505 } else { | 515 } else { |
| 506 return makeNameCodePair(method); | 516 return makeNameCodePair(method); |
| 507 } | 517 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 | 791 |
| 782 var end = Date.now(); | 792 var end = Date.now(); |
| 783 print('Setup: ' + (end - start) + ' ms.'); | 793 print('Setup: ' + (end - start) + ' ms.'); |
| 784 | 794 |
| 785 #main(); // Start main. | 795 #main(); // Start main. |
| 786 | 796 |
| 787 }(Date.now(), #code) | 797 }(Date.now(), #code) |
| 788 }"""; | 798 }"""; |
| 789 | 799 |
| 790 } | 800 } |
| OLD | NEW |