Index: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart |
diff --git a/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart b/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart |
index ad7057b5154513348953c6f6d30b6f2a4cd1bfc7..8e3e941ed907ff59d7a36720e3abe4a437cb12bc 100644 |
--- a/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart |
+++ b/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart |
@@ -4,6 +4,7 @@ |
library dart2js.new_js_emitter.model_emitter; |
+import '../../constants/values.dart' show ConstantValue; |
import '../../dart2jslib.dart' show Compiler; |
import '../../dart_types.dart' show DartType; |
import '../../elements/elements.dart' show ClassElement; |
@@ -113,7 +114,10 @@ class ModelEmitter { |
'holders': emitHolders(program.holders), |
'tearOff': buildTearOffCode(backend), |
'parseFunctionDescriptor': |
- js.js.statement(parseFunctionDescriptorBoilerplate), |
+ js.js.statement(parseFunctionDescriptorBoilerplate, |
+ {'argCnt': js.string(namer.requiredParameterField), |
+ 'defArgValues': js.string(namer.defaultValuesField)}), |
+ |
'cyclicThrow': |
backend.emitter.staticFunctionAccess(backend.getCyclicThrowHelper()), |
'outputContainsConstantList': program.outputContainsConstantList, |
@@ -564,7 +568,13 @@ class ModelEmitter { |
/// [ParameterStubMethod.name] |
/// [ParameterStubMethod.code] |
floitsch
2015/02/16 15:26:03
Something seems to be missing here.
herhut
2015/02/17 10:25:39
[ParameterStubMethod.callName] was missing. Fixed.
|
/// |
- /// for each stub in [DartMethod.parameterStubs]. |
+ /// for each stub in [DartMethod.parameterStubs]. If [DartMethod.canBeApplied] |
floitsch
2015/02/16 15:26:03
Start a new paragraph.
If the closure could be us
herhut
2015/02/17 10:25:39
Done.
|
+ /// is true |
+ /// |
+ /// [DartMethod.requiredParameterCount] |
+ /// [DartMethod.optionalParameterDefaultValues] |
+ /// |
+ /// is also appended. |
static final String parseFunctionDescriptorBoilerplate = r""" |
function parseFunctionDescriptor(proto, name, descriptor) { |
@@ -591,7 +601,7 @@ function parseFunctionDescriptor(proto, name, descriptor) { |
reflectionInfo = descriptor[++pos]; |
} |
- for (++pos; pos < descriptor.length; pos += 3) { |
+ for (++pos; pos < descriptor.length - 2; pos += 3) { |
floitsch
2015/02/16 15:26:03
add a comment why the "2".
herhut
2015/02/17 10:25:39
Done.
|
var stub = descriptor[pos + 2]; |
stub.$callName = descriptor[pos + 1]; |
floitsch
2015/02/16 15:26:03
This should be a shared variable. (the "$callName"
herhut
2015/02/17 10:25:39
Done.
|
proto[descriptor[pos]] = stub; |
@@ -602,7 +612,10 @@ function parseFunctionDescriptor(proto, name, descriptor) { |
proto[tearOffName] = |
tearOff(funs, reflectionInfo, false, name, isIntercepted); |
} |
- |
+ if (descriptor[pos] != null) { |
+ f[#argCnt] = descriptor[pos]; |
+ f[#defArgValues] = descriptor[pos + 1]; |
+ } |
} else { |
proto[name] = descriptor; |
} |
@@ -618,6 +631,24 @@ function parseFunctionDescriptor(proto, name, descriptor) { |
} |
} |
+ js.Expression _encodeOptionalParameterDefaultValues(DartMethod method) { |
+ js.Expression result; |
+ // TODO(herhut): Replace [js.LiteralNull] with [js.ArrayHole]. |
+ if (method.optionalParameterDefaultValues is List) { |
+ List<ConstantValue> defs = method.optionalParameterDefaultValues; |
+ Iterable<js.Expression> elements = defs.map(constantEmitter.reference); |
+ return new js.ArrayInitializer(elements.toList()); |
+ } else { |
+ Map<String, ConstantValue> defs = method.optionalParameterDefaultValues; |
+ List<js.Property> properties = <js.Property>[]; |
+ defs.forEach((String name, ConstantValue value) { |
+ properties.add(new js.Property(js.string(name), |
+ constantEmitter.reference(value))); |
+ }); |
+ return new js.ObjectInitializer(properties); |
+ } |
+ } |
+ |
Iterable<js.Expression> emitInstanceMethod(Method method) { |
List<js.Expression> makeNameCodePair(Method method) { |
@@ -652,6 +683,10 @@ function parseFunctionDescriptor(proto, name, descriptor) { |
} |
data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet)); |
+ if (method.canBeApplied) { |
+ data.add(js.number(method.requiredParameterCount)); |
+ data.add(_encodeOptionalParameterDefaultValues(method)); |
+ } |
return [js.string(method.name), new js.ArrayInitializer(data)]; |
} else { |
// TODO(floitsch): not the most efficient way... |
@@ -695,6 +730,10 @@ function parseFunctionDescriptor(proto, name, descriptor) { |
data.add(js.string(method.tearOffName)); |
data.add(_generateFunctionType(method.type)); |
data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet)); |
+ if (method.canBeApplied) { |
+ data.add(js.number(method.requiredParameterCount)); |
+ data.add(_encodeOptionalParameterDefaultValues(method)); |
+ } |
return [js.string(method.name), holderIndex, |
new js.ArrayInitializer(data)]; |
} else { |