| 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 d13108a3a767d5860f8f4e4d3794776291687681..2764bccf133834ff44426e745c4e932cdf40acc5 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
|
| @@ -22,7 +22,7 @@ import 'package:_internal/compiler/js_lib/shared/embedded_names.dart' show
|
| METADATA,
|
| TYPE_TO_INTERCEPTOR_MAP;
|
|
|
| -import '../js_emitter.dart' show NativeGenerator;
|
| +import '../js_emitter.dart' show NativeGenerator, buildTearOffCode;
|
| import '../model.dart';
|
|
|
| class ModelEmitter {
|
| @@ -108,6 +108,9 @@ class ModelEmitter {
|
| boilerplate,
|
| {'deferredInitializer': emitDeferredInitializerGlobal(program.loadMap),
|
| 'holders': emitHolders(fragment.holders),
|
| + 'tearOff': buildTearOffCode(backend),
|
| + 'parseFunctionDescriptor':
|
| + js.js.statement(parseFunctionDescriptorBoilerplate),
|
| 'cyclicThrow':
|
| backend.emitter.staticFunctionAccess(backend.getCyclicThrowHelper()),
|
| 'outputContainsConstantList': program.outputContainsConstantList,
|
| @@ -395,19 +398,12 @@ class ModelEmitter {
|
| } else {
|
| elements.add(_generateConstructor(cls));
|
| }
|
| - Iterable<Method> methods = cls.methods.expand((Method method) {
|
| - // TODO(floitsch): can there be anything else than a DartMethod?
|
| - if (method is DartMethod) {
|
| - return [method]..addAll(method.parameterStubs);
|
| - } else {
|
| - return [method];
|
| - }
|
| - });
|
| + Iterable<Method> methods = cls.methods;
|
| Iterable<Method> isChecks = cls.isChecks;
|
| Iterable<Method> gettersSetters = _generateGettersSetters(cls);
|
| Iterable<Method> allMethods =
|
| [methods, isChecks, gettersSetters].expand((x) => x);
|
| - elements.addAll(allMethods.expand((e) => [js.string(e.name), e.code]));
|
| + elements.addAll(allMethods.expand(emitInstanceMethod));
|
| return unparse(compiler, new js.ArrayInitializer(elements));
|
| }
|
|
|
| @@ -416,6 +412,67 @@ class ModelEmitter {
|
| return unparse(compiler, field.code);
|
| }
|
|
|
| + static final String parseFunctionDescriptorBoilerplate = r"""
|
| +function parseFunctionDescriptor(proto, name, desc) {
|
| + if (desc instanceof Array) {
|
| + proto[name] = desc[0];
|
| + var funs = [desc[0]];
|
| + funs[0].$callName = desc[1];
|
| + for (var pos = 4; pos < desc.length; pos += 3) {
|
| + var stub = desc[pos+2];
|
| + stub.$callName = desc[pos+1];
|
| + proto[desc[pos]] = stub;
|
| + funs.push(stub);
|
| + }
|
| + if (desc[2] != null) {
|
| + // TODO(floitsch): desc[3] should be the reflectionInfo, not
|
| + // isIntercepted.
|
| + var isIntercepted = desc[3];
|
| + var reflectionInfo = null;
|
| + proto[desc[2]] = tearOff(funs, reflectionInfo, false, name, isIntercepted);
|
| + }
|
| + } else {
|
| + proto[name] = desc;
|
| + }
|
| +}
|
| +""";
|
| +
|
| + Iterable<js.Expression> emitInstanceMethod(Method method) {
|
| +
|
| + List<js.Expression> makeNameCodePair(Method method) {
|
| + return [js.string(method.name), method.code];
|
| + }
|
| +
|
| + List<js.Expression> makeNameCallNameCodeTriplet(ParameterStubMethod stub) {
|
| + js.Expression callName = stub.callName == null
|
| + ? new js.LiteralNull()
|
| + : js.string(stub.callName);
|
| + return [js.string(stub.name), callName, stub.code];
|
| + }
|
| +
|
| + if (method is DartMethod) {
|
| + if (method.needsTearOff) {
|
| + bool isIntercepted = backend.isInterceptedMethod(method.element);
|
| + // [name, [function, callName, tearOffName, functionType,
|
| + // stub1_name, stub1_callName, stub1_code, ...]
|
| + var data = [method.code];
|
| + data.add(js.string(method.callName));
|
| + data.add(js.string(method.tearOffName));
|
| + // TODO(floitsch): this field should be the type, not the bool if the
|
| + // method is intercepted.
|
| + // data.add(new js.LiteralNull());
|
| + data.add(new js.LiteralBool(isIntercepted));
|
| + data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet));
|
| + return [js.string(method.name), new js.ArrayInitializer(data)];
|
| + } else {
|
| + // TODO(floitsch): not the most efficient way...
|
| + return ([method]..addAll(method.parameterStubs)).expand(makeNameCodePair);
|
| + }
|
| + } else {
|
| + return makeNameCodePair(method);
|
| + }
|
| + }
|
| +
|
| Iterable<js.Expression> emitStaticMethod(StaticMethod method) {
|
| js.Expression holderIndex = js.number(method.holder.index);
|
| List<js.Expression> output = <js.Expression>[];
|
| @@ -441,7 +498,6 @@ class ModelEmitter {
|
| #deferredInitializer;
|
|
|
| !function(start, program) {
|
| -
|
| // Initialize holder objects.
|
| #holders;
|
|
|
| @@ -530,6 +586,10 @@ class ModelEmitter {
|
| holder[name] = patch;
|
| }
|
|
|
| + #tearOff;
|
| +
|
| + #parseFunctionDescriptor;
|
| +
|
| function compileConstructor(name, descriptor) {
|
| descriptor = compile(name, descriptor);
|
| var prototype = determinePrototype(descriptor);
|
| @@ -538,12 +598,12 @@ class ModelEmitter {
|
| if (typeof descriptor[2] !== 'function') {
|
| constructor = compileMixinConstructor(name, prototype, descriptor);
|
| for (var i = 4; i < descriptor.length; i += 2) {
|
| - prototype[descriptor[i]] = descriptor[i + 1];
|
| + parseFunctionDescriptor(prototype, descriptor, descriptor[i + 1]);
|
| }
|
| } else {
|
| constructor = descriptor[2];
|
| for (var i = 3; i < descriptor.length; i += 2) {
|
| - prototype[descriptor[i]] = descriptor[i + 1];
|
| + parseFunctionDescriptor(prototype, descriptor[i], descriptor[i + 1]);
|
| }
|
| }
|
| constructor.builtin\$cls = name; // Needed for RTI.
|
|
|