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.js_emitter.program_builder; | 5 library dart2js.js_emitter.program_builder; |
| 6 | 6 |
| 7 import '../js_emitter.dart' show | 7 import '../js_emitter.dart' show |
| 8 ClassStubGenerator, | 8 ClassStubGenerator, |
| 9 CodeEmitterTask, | 9 CodeEmitterTask, |
| 10 computeMixinClass, | 10 computeMixinClass, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 Names, | 23 Names, |
| 24 Selectors; | 24 Selectors; |
| 25 import '../../compiler.dart' show | 25 import '../../compiler.dart' show |
| 26 Compiler; | 26 Compiler; |
| 27 import '../../constants/values.dart' show | 27 import '../../constants/values.dart' show |
| 28 ConstantValue, | 28 ConstantValue, |
| 29 InterceptorConstantValue; | 29 InterceptorConstantValue; |
| 30 import '../../core_types.dart' show | 30 import '../../core_types.dart' show |
| 31 CoreClasses; | 31 CoreClasses; |
| 32 import '../../dart_types.dart' show | 32 import '../../dart_types.dart' show |
| 33 DartType; | 33 DartType, |
| 34 FunctionType, | |
| 35 TypedefType; | |
| 34 import '../../elements/elements.dart' show | 36 import '../../elements/elements.dart' show |
| 35 ClassElement, | 37 ClassElement, |
| 36 Element, | 38 Element, |
| 37 Elements, | 39 Elements, |
| 38 FieldElement, | 40 FieldElement, |
| 39 FunctionElement, | 41 FunctionElement, |
| 40 FunctionSignature, | 42 FunctionSignature, |
| 43 GetterElement, | |
| 41 LibraryElement, | 44 LibraryElement, |
| 42 MethodElement, | 45 MethodElement, |
| 43 Name, | 46 Name, |
| 44 ParameterElement, | 47 ParameterElement, |
| 45 TypedefElement, | 48 TypedefElement, |
| 46 VariableElement; | 49 VariableElement; |
| 47 import '../../js/js.dart' as js; | 50 import '../../js/js.dart' as js; |
| 48 import '../../js_backend/backend_helpers.dart' show | 51 import '../../js_backend/backend_helpers.dart' show |
| 49 BackendHelpers; | 52 BackendHelpers; |
| 50 import '../../js_backend/js_backend.dart' show | 53 import '../../js_backend/js_backend.dart' show |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 if (stubNames.add(stubName.key)) { | 403 if (stubNames.add(stubName.key)) { |
| 401 interceptorClass.callStubs.add(_buildStubMethod( | 404 interceptorClass.callStubs.add(_buildStubMethod( |
| 402 stubName, | 405 stubName, |
| 403 js.js('function(obj, v) { return obj.# = v }', | 406 js.js('function(obj, v) { return obj.# = v }', |
| 404 [member.name]), | 407 [member.name]), |
| 405 element: member)); | 408 element: member)); |
| 406 } | 409 } |
| 407 } | 410 } |
| 408 } | 411 } |
| 409 | 412 |
| 413 bool isFunctionLike = false; | |
|
sra1
2015/10/30 20:54:59
Explain (comment) that this is generating stubs fo
Jacob
2015/10/30 22:31:53
Done.
| |
| 414 FunctionType functionType; | |
|
sra1
2015/10/30 20:54:59
I like to add = null if it is not set one some pat
Jacob
2015/10/30 22:31:53
Done.
| |
| 415 | |
| 410 if (member.isFunction) { | 416 if (member.isFunction) { |
| 417 FunctionElement fn = member; | |
| 418 functionType = fn.type; | |
| 419 } else if (member.isGetter) { | |
| 420 GetterElement getter = member; | |
| 421 DartType returnType = getter.type.returnType; | |
| 422 if (returnType.isFunctionType) { | |
| 423 functionType = returnType; | |
| 424 } else if (_compiler.types.isSubtype(returnType, | |
| 425 backend.coreTypes.functionType) || | |
| 426 returnType.treatAsDynamic) { | |
|
sra1
2015/10/30 20:54:59
Horrible indentation. If it is the formatter, can
Jacob
2015/10/30 22:31:53
done. shame line length isn't 100.
| |
| 427 if (returnType.isTypedef) { | |
| 428 TypedefType typedef = returnType; | |
| 429 functionType = typedef.element.functionSignature.type; | |
| 430 } else { | |
| 431 // Other misc function type such as coreTypes.Function. | |
| 432 // Allow any number of arguments. | |
| 433 isFunctionLike = true; | |
| 434 } | |
| 435 } | |
| 436 } // TODO(jacobr): handle field elements. | |
| 437 | |
| 438 if (isFunctionLike || functionType != null) { | |
| 439 int minArgs; | |
| 440 int maxArgs; | |
| 441 if (functionType != null) { | |
| 442 minArgs = functionType.parameterTypes.length; | |
| 443 maxArgs = minArgs + functionType.optionalParameterTypes.length; | |
| 444 } else { | |
| 445 minArgs = 0; | |
| 446 maxArgs = 32767; | |
| 447 } | |
| 411 var selectors = | 448 var selectors = |
| 412 _compiler.codegenWorld.invocationsByName(member.name); | 449 _compiler.codegenWorld.invocationsByName(member.name); |
| 413 FunctionElement fn = member; | 450 FunctionElement fn = member; |
|
sra1
2015/10/30 20:54:59
'fn' unused below. Will fail if you TODO handle f
Jacob
2015/10/30 22:31:53
done. forgot to remove this.
| |
| 414 // Named arguments are not yet supported. In the future we | 451 // Named arguments are not yet supported. In the future we |
| 415 // may want to map named arguments to an object literal containing | 452 // may want to map named arguments to an object literal containing |
| 416 // all named arguments. | 453 // all named arguments. |
| 417 if (selectors != null && !selectors.isEmpty) { | 454 if (selectors != null && !selectors.isEmpty) { |
| 418 for (var selector in selectors.keys) { | 455 for (var selector in selectors.keys) { |
| 419 // Check whether the arity matches this member. | 456 // Check whether the arity matches this member. |
| 420 var argumentCount = selector.argumentCount; | 457 var argumentCount = selector.argumentCount; |
| 421 if (argumentCount > fn.parameters.length) break; | 458 // JS interop does not support named arguments. |
| 422 if (argumentCount < fn.parameters.length && | 459 if (selector.namedArgumentCount > 0) break; |
| 423 !fn.parameters[argumentCount].isOptional) break; | 460 if (argumentCount < minArgs) break; |
| 461 if (argumentCount > maxArgs) break; | |
| 424 var stubName = namer.invocationName(selector); | 462 var stubName = namer.invocationName(selector); |
| 425 if (!stubNames.add(stubName.key)) break; | 463 if (!stubNames.add(stubName.key)) break; |
| 426 var candidateParameterNames = | |
| 427 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMOPQRSTUVWXYZ'; | |
| 428 var parameters = new List<String>.generate(argumentCount, | 464 var parameters = new List<String>.generate(argumentCount, |
| 429 (i) => candidateParameterNames[i]); | 465 (i) => 'p$i'); |
|
Siggi Cherem (dart-lang)
2015/10/30 19:54:17
you could also keep the old naming scheme to optim
Jacob
2015/10/30 22:31:53
not needed. these names will be minified anyway so
| |
| 430 | 466 |
| 431 interceptorClass.callStubs.add(_buildStubMethod( | 467 interceptorClass.callStubs.add(_buildStubMethod( |
| 432 stubName, | 468 stubName, |
|
sra1
2015/10/30 20:54:59
Do you get duplicate stubs?
Jacob
2015/10/30 22:31:53
no because of
if (!stubNames.add(stubName.key)) b
| |
| 433 js.js('function(receiver, #) { return receiver.#(#) }', | 469 js.js('function(receiver, #) { return receiver.#(#) }', |
| 434 [parameters, member.name, parameters]), | 470 [parameters, member.name, parameters]), |
|
sra1
2015/10/30 20:54:59
This is correct for function stubs, but is it what
Jacob
2015/10/30 22:31:53
this is awesome for call through stubs. It means i
| |
| 435 element: member)); | 471 element: member)); |
| 436 } | 472 } |
| 437 } | 473 } |
| 438 } | 474 } |
| 439 }); | 475 }); |
| 440 } | 476 } |
| 441 } | 477 } |
| 442 }); | 478 }); |
| 443 } | 479 } |
| 444 | 480 |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 Constant constant = new Constant(name, holder, constantValue); | 1000 Constant constant = new Constant(name, holder, constantValue); |
| 965 _constants[constantValue] = constant; | 1001 _constants[constantValue] = constant; |
| 966 } | 1002 } |
| 967 } | 1003 } |
| 968 | 1004 |
| 969 Holder _registerStaticStateHolder() { | 1005 Holder _registerStaticStateHolder() { |
| 970 return _registry.registerHolder( | 1006 return _registry.registerHolder( |
| 971 namer.staticStateHolder, isStaticStateHolder: true); | 1007 namer.staticStateHolder, isStaticStateHolder: true); |
| 972 } | 1008 } |
| 973 } | 1009 } |
| OLD | NEW |