Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 1458313002: Fix for the js-interop crash Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of ssa; 5 part of ssa;
6 6
7 class SsaFunctionCompiler implements FunctionCompiler { 7 class SsaFunctionCompiler implements FunctionCompiler {
8 final SsaCodeGeneratorTask generator; 8 final SsaCodeGeneratorTask generator;
9 final SsaBuilderTask builder; 9 final SsaBuilderTask builder;
10 final SsaOptimizerTask optimizer; 10 final SsaOptimizerTask optimizer;
(...skipping 5846 matching lines...) Expand 10 before | Expand all | Expand 10 after
5857 ..sourceInformation = sourceInformation); 5857 ..sourceInformation = sourceInformation);
5858 } 5858 }
5859 } 5859 }
5860 5860
5861 bool _hasNamedParameters(FunctionElement function) { 5861 bool _hasNamedParameters(FunctionElement function) {
5862 FunctionSignature params = function.functionSignature; 5862 FunctionSignature params = function.functionSignature;
5863 return params.optionalParameterCount > 0 5863 return params.optionalParameterCount > 0
5864 && params.optionalParametersAreNamed; 5864 && params.optionalParametersAreNamed;
5865 } 5865 }
5866 5866
5867 HForeignCode invokeJsInteropFunction(Element element, 5867 HForeignCode invokeJsInteropFunction(FunctionElement element,
5868 List<HInstruction> arguments, 5868 List<HInstruction> arguments,
5869 SourceInformation sourceInformation) { 5869 SourceInformation sourceInformation) {
5870 assert(backend.isJsInterop(element)); 5870 assert(backend.isJsInterop(element));
5871 nativeEmitter.nativeMethods.add(element); 5871 nativeEmitter.nativeMethods.add(element);
5872 String templateString; 5872 String templateString;
5873 5873
5874 if (element.isFactoryConstructor && 5874 if (element.isFactoryConstructor &&
5875 backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass)) { 5875 backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass)) {
5876 // Factory constructor that is syntactic sugar for creating a JavaScript 5876 // Factory constructor that is syntactic sugar for creating a JavaScript
5877 // object literal. 5877 // object literal.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5911 <HInstruction>[]); 5911 <HInstruction>[]);
5912 add(target); 5912 add(target);
5913 // Strip off trailing arguments that were not specified. 5913 // Strip off trailing arguments that were not specified.
5914 // we could assert that the trailing arguments are all null. 5914 // we could assert that the trailing arguments are all null.
5915 // TODO(jacobr): rewrite named arguments to an object literal matching 5915 // TODO(jacobr): rewrite named arguments to an object literal matching
5916 // the factory constructor case. 5916 // the factory constructor case.
5917 arguments = arguments.where((arg) => arg != null).toList(); 5917 arguments = arguments.where((arg) => arg != null).toList();
5918 var inputs = <HInstruction>[target]..addAll(arguments); 5918 var inputs = <HInstruction>[target]..addAll(arguments);
5919 5919
5920 js.Template codeTemplate; 5920 js.Template codeTemplate;
5921 DartType type = element.type.returnType;
5921 if (element.isGetter) { 5922 if (element.isGetter) {
5922 codeTemplate = js.js.parseForeignJS("#"); 5923 codeTemplate = js.js.parseForeignJS("#");
5923 } else if (element.isSetter) { 5924 } else if (element.isSetter) {
5924 codeTemplate = js.js.parseForeignJS("# = #"); 5925 codeTemplate = js.js.parseForeignJS("# = #");
5925 } else { 5926 } else {
5926 FunctionElement function = element; 5927 FunctionSignature params = element.functionSignature;
5927 FunctionSignature params = function.functionSignature;
5928 5928
5929 var argsStub = <String>[]; 5929 var argsStub = <String>[];
5930 for (int i = 0; i < arguments.length; i++) { 5930 for (int i = 0; i < arguments.length; i++) {
5931 argsStub.add('#'); 5931 argsStub.add('#');
5932 } 5932 }
5933 5933
5934 if (element.isConstructor) { 5934 if (element.isConstructor) {
5935 codeTemplate = js.js.parseForeignJS("new #(${argsStub.join(",")})"); 5935 codeTemplate = js.js.parseForeignJS("new #(${argsStub.join(",")})");
5936 type = element.enclosingClass.thisType;
5936 } else { 5937 } else {
5937 codeTemplate = js.js.parseForeignJS("#(${argsStub.join(",")})"); 5938 codeTemplate = js.js.parseForeignJS("#(${argsStub.join(",")})");
5938 } 5939 }
5939 } 5940 }
5940 5941
5942 // Note: here we are trusting the declared type by default to keep the
5943 // codegen behavior consistent with the resolution behavior. Currently the
5944 // NativeResolutionEnqueuer will trust the types by default (since this is
5945 // what we always did for native APIs in dart:html). We could change both to
5946 // be more conservative, but that could bring in a lot more code than what
5947 // we want.
Jacob 2015/11/20 00:50:34 I thought in resolution we were treating each of t
Siggi Cherem (dart-lang) 2015/11/20 01:06:17 Good question - we have been debating about this t
Siggi Cherem (dart-lang) 2015/11/20 01:56:15 I made a CL with the alternative approach, I'm sti
5941 var nativeBehavior = new native.NativeBehavior() 5948 var nativeBehavior = new native.NativeBehavior()
5942 ..codeTemplate = codeTemplate 5949 ..codeTemplate = codeTemplate
5943 ..typesReturned.add( 5950 ..typesReturned.add(type)
5944 helpers.jsJavaScriptObjectClass.thisType) 5951 ..typesInstantiated.add(type)
5945 ..typesInstantiated.add(
5946 helpers.jsJavaScriptObjectClass.thisType)
5947 ..sideEffects.setAllSideEffects(); 5952 ..sideEffects.setAllSideEffects();
5948 return new HForeignCode( 5953 return new HForeignCode(
5949 codeTemplate, 5954 codeTemplate,
5950 backend.dynamicType, inputs, 5955 backend.dynamicType, inputs,
5951 nativeBehavior: nativeBehavior) 5956 nativeBehavior: nativeBehavior)
5952 ..sourceInformation = sourceInformation; 5957 ..sourceInformation = sourceInformation;
5953 } 5958 }
5954 5959
5955 void pushInvokeStatic(ast.Node location, 5960 void pushInvokeStatic(ast.Node location,
5956 Element element, 5961 Element element,
(...skipping 3204 matching lines...) Expand 10 before | Expand all | Expand 10 after
9161 if (unaliased is TypedefType) throw 'unable to unalias $type'; 9166 if (unaliased is TypedefType) throw 'unable to unalias $type';
9162 unaliased.accept(this, builder); 9167 unaliased.accept(this, builder);
9163 } 9168 }
9164 9169
9165 void visitDynamicType(DynamicType type, SsaBuilder builder) { 9170 void visitDynamicType(DynamicType type, SsaBuilder builder) {
9166 JavaScriptBackend backend = builder.compiler.backend; 9171 JavaScriptBackend backend = builder.compiler.backend;
9167 ClassElement cls = backend.helpers.DynamicRuntimeType; 9172 ClassElement cls = backend.helpers.DynamicRuntimeType;
9168 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); 9173 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld)));
9169 } 9174 }
9170 } 9175 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/js_interop_analysis.dart ('k') | tests/compiler/dart2js/compiler_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698