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

Unified Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 1457383003: Alternative fix for the js-interop crash. (Closed) 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/native/behavior.dart ('k') | tests/compiler/dart2js/compiler_helper.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/builder.dart
diff --git a/pkg/compiler/lib/src/ssa/builder.dart b/pkg/compiler/lib/src/ssa/builder.dart
index 0945568cfec8ca52f74c4eecf1ca669123a40266..3668109ef34cf1720a21eaaf3ebf059d00f71f44 100644
--- a/pkg/compiler/lib/src/ssa/builder.dart
+++ b/pkg/compiler/lib/src/ssa/builder.dart
@@ -5864,7 +5864,7 @@ class SsaBuilder extends ast.Visitor
&& params.optionalParametersAreNamed;
}
- HForeignCode invokeJsInteropFunction(Element element,
+ HForeignCode invokeJsInteropFunction(FunctionElement element,
List<HInstruction> arguments,
SourceInformation sourceInformation) {
assert(backend.isJsInterop(element));
@@ -5898,6 +5898,9 @@ class SsaBuilder extends ast.Visitor
var nativeBehavior = new native.NativeBehavior()
..codeTemplate = codeTemplate;
+ if (compiler.trustJSInteropTypeAnnotations) {
+ nativeBehavior.typesReturned.add(constructor.enclosingClass.thisType);
+ }
return new HForeignCode(
codeTemplate,
backend.dynamicType, filteredArguments,
@@ -5917,34 +5920,43 @@ class SsaBuilder extends ast.Visitor
arguments = arguments.where((arg) => arg != null).toList();
var inputs = <HInstruction>[target]..addAll(arguments);
- js.Template codeTemplate;
+ var nativeBehavior = new native.NativeBehavior()
+ ..sideEffects.setAllSideEffects();
+
+ DartType type = element.isConstructor ?
+ element.enclosingClass.thisType : element.type.returnType;
+ // Native behavior effects here are similar to native/behavior.dart.
+ // The return type is dynamic if we don't trust js-interop type
+ // declarations.
+ nativeBehavior.typesReturned.add(
+ compiler.trustJSInteropTypeAnnotations ? type : const DynamicType());
+
+ // The allocation effects include the declared type if it is native (which
+ // includes js interop types).
+ if (type.element != null && backend.isNative(type.element)) {
+ nativeBehavior.typesInstantiated.add(type);
+ }
+
+ // It also includes any other JS interop type if we don't trust the
+ // annotation or if is declared too broad.
+ if (!compiler.trustJSInteropTypeAnnotations || type.isObject ||
+ type.isDynamic) {
+ nativeBehavior.typesInstantiated.add(
+ backend.helpers.jsJavaScriptObjectClass.thisType);
+ }
+
+ String code;
if (element.isGetter) {
- codeTemplate = js.js.parseForeignJS("#");
+ code = "#";
} else if (element.isSetter) {
- codeTemplate = js.js.parseForeignJS("# = #");
+ code = "# = #";
} else {
- FunctionElement function = element;
- FunctionSignature params = function.functionSignature;
-
- var argsStub = <String>[];
- for (int i = 0; i < arguments.length; i++) {
- argsStub.add('#');
- }
-
- if (element.isConstructor) {
- codeTemplate = js.js.parseForeignJS("new #(${argsStub.join(",")})");
- } else {
- codeTemplate = js.js.parseForeignJS("#(${argsStub.join(",")})");
- }
+ var args = new List.filled(arguments.length, '#').join(',');
+ code = element.isConstructor ? "new #($args)" : "#($args)";
}
+ js.Template codeTemplate = js.js.parseForeignJS(code);
+ nativeBehavior.codeTemplate = codeTemplate;
- var nativeBehavior = new native.NativeBehavior()
- ..codeTemplate = codeTemplate
- ..typesReturned.add(
- helpers.jsJavaScriptObjectClass.thisType)
- ..typesInstantiated.add(
- helpers.jsJavaScriptObjectClass.thisType)
- ..sideEffects.setAllSideEffects();
return new HForeignCode(
codeTemplate,
backend.dynamicType, inputs,
« no previous file with comments | « pkg/compiler/lib/src/native/behavior.dart ('k') | tests/compiler/dart2js/compiler_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698