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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/codegen.dart

Issue 23440034: Make sure we throw the right NSM error when indexing out of range of a variable that can be null. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SsaCodeGeneratorTask extends CompilerTask { 7 class SsaCodeGeneratorTask extends CompilerTask {
8 8
9 final JavaScriptBackend backend; 9 final JavaScriptBackend backend;
10 10
(...skipping 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 } 1969 }
1970 assert(over != null || under != null); 1970 assert(over != null || under != null);
1971 js.Expression underOver = under == null 1971 js.Expression underOver = under == null
1972 ? over 1972 ? over
1973 : over == null 1973 : over == null
1974 ? under 1974 ? under
1975 : new js.Binary("||", under, over); 1975 : new js.Binary("||", under, over);
1976 js.Statement thenBody = new js.Block.empty(); 1976 js.Statement thenBody = new js.Block.empty();
1977 js.Block oldContainer = currentContainer; 1977 js.Block oldContainer = currentContainer;
1978 currentContainer = thenBody; 1978 currentContainer = thenBody;
1979 generateThrowWithHelper('ioore', node.index); 1979 generateThrowWithHelper('ioore', [node.array, node.index]);
1980 currentContainer = oldContainer; 1980 currentContainer = oldContainer;
1981 thenBody = unwrapStatement(thenBody); 1981 thenBody = unwrapStatement(thenBody);
1982 pushStatement(new js.If.noElse(underOver, thenBody), node); 1982 pushStatement(new js.If.noElse(underOver, thenBody), node);
1983 } else { 1983 } else {
1984 generateThrowWithHelper('ioore', node.index); 1984 generateThrowWithHelper('ioore', [node.array, node.index]);
1985 } 1985 }
1986 } 1986 }
1987 1987
1988 void generateThrowWithHelper(String helperName, HInstruction argument) { 1988 void generateThrowWithHelper(String helperName, argument) {
1989 Element helper = compiler.findHelper(new SourceString(helperName)); 1989 Element helper = compiler.findHelper(new SourceString(helperName));
1990 world.registerStaticUse(helper); 1990 world.registerStaticUse(helper);
1991 js.VariableUse jsHelper = 1991 js.VariableUse jsHelper =
1992 new js.VariableUse(backend.namer.isolateAccess(helper)); 1992 new js.VariableUse(backend.namer.isolateAccess(helper));
1993 use(argument); 1993 List arguments = [];
1994 js.Call value = new js.Call(jsHelper, [pop()]); 1994 var location;
1995 attachLocation(value, argument); 1995 if (argument is List) {
1996 location = argument[0];
1997 argument.forEach((instruction) {
1998 use(instruction);
1999 arguments.add(pop());
2000 });
2001 } else {
2002 location = argument;
2003 use(argument);
2004 arguments.add(pop());
2005 }
2006 js.Call value = new js.Call(jsHelper, arguments);
2007 attachLocation(value, location);
1996 // BUG(4906): Using throw here adds to the size of the generated code 2008 // BUG(4906): Using throw here adds to the size of the generated code
1997 // but it has the advantage of explicitly telling the JS engine that 2009 // but it has the advantage of explicitly telling the JS engine that
1998 // this code path will terminate abruptly. Needs more work. 2010 // this code path will terminate abruptly. Needs more work.
1999 pushStatement(new js.Throw(value)); 2011 pushStatement(new js.Throw(value));
2000 } 2012 }
2001 2013
2002 visitThrowExpression(HThrowExpression node) { 2014 visitThrowExpression(HThrowExpression node) {
2003 HInstruction argument = node.inputs[0]; 2015 HInstruction argument = node.inputs[0];
2004 use(argument); 2016 use(argument);
2005 2017
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
2991 if (leftType.canBeNull() && rightType.canBeNull()) { 3003 if (leftType.canBeNull() && rightType.canBeNull()) {
2992 if (left.isConstantNull() || right.isConstantNull() || 3004 if (left.isConstantNull() || right.isConstantNull() ||
2993 (leftType.isPrimitive(compiler) && leftType == rightType)) { 3005 (leftType.isPrimitive(compiler) && leftType == rightType)) {
2994 return '=='; 3006 return '==';
2995 } 3007 }
2996 return null; 3008 return null;
2997 } else { 3009 } else {
2998 return '==='; 3010 return '===';
2999 } 3011 }
3000 } 3012 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698