Skip to content

Commit 823293a

Browse files
author
ngeoffray@google.com
committed
We can only use JavaScript's String.split and String.+ if both inputs are Strings.
R=karlklose@google.com Review URL: https://codereview.chromium.org//23494057 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27557 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 372d907 commit 823293a

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

sdk/lib/_internal/compiler/implementation/ssa/interceptor_simplifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class SsaSimplifyInterceptors extends HBaseVisitor
264264
// they have side effects.
265265
HInstruction instruction;
266266
if (selector.isGetter()) {
267-
instruction= new HInvokeDynamicGetter(
267+
instruction = new HInvokeDynamicGetter(
268268
selector,
269269
node.element,
270270
<HInstruction>[constant, node.inputs[1]],

sdk/lib/_internal/compiler/implementation/ssa/optimize.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,17 @@ class SsaInstructionSimplifier extends HBaseVisitor
299299
}
300300
} else if (input.isString(compiler)) {
301301
if (selector.applies(backend.jsStringSplit, compiler)) {
302-
if (node.inputs[2].isString(compiler)) {
302+
HInstruction argument = node.inputs[2];
303+
if (argument.isString(compiler) && !argument.canBeNull()) {
303304
target = backend.jsStringSplit;
304305
}
305306
} else if (selector.applies(backend.jsStringOperatorAdd, compiler)) {
306307
// `operator+` is turned into a JavaScript '+' so we need to
307-
// make sure the receiver is not null.
308-
if (node.inputs[2].isString(compiler) && !input.canBeNull()) {
308+
// make sure the receiver and the argument are not null.
309+
HInstruction argument = node.inputs[2];
310+
if (argument.isString(compiler)
311+
&& !argument.canBeNull()
312+
&& !input.canBeNull()) {
309313
target = backend.jsStringOperatorAdd;
310314
}
311315
} else if (selector.applies(backend.jsStringToString, compiler)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import "package:expect/expect.dart";
6+
import "../language/compiler_annotations.dart";
7+
8+
@DontInline()
9+
returnStringOrNull() {
10+
() => 42;
11+
return new DateTime.now().millisecondsSinceEpoch == 0 ? 'foo' : null;
12+
}
13+
14+
main() {
15+
Expect.throws(() => 'foo' + returnStringOrNull(),
16+
(e) => e is ArgumentError);
17+
Expect.throws(() => 'foo'.split(returnStringOrNull()),
18+
(e) => e is ArgumentError || e is NoSuchMethodError);
19+
}

0 commit comments

Comments
 (0)