dart2js: Bugfix for when 'await' occurs in an initializer list.

If the JS ast contains an initializer list:

  var x = foo(), y = await x;

It would be retained as a single statement and generate invalid output
that awaits 'x' before it has been defined.

CLOSES=23997

BUG=
R=sigurdm@google.com

Review URL: https://codereview.chromium.org/1427593003 .
This commit is contained in:
Asger Feldthaus 2015-10-27 11:36:57 +01:00
parent 529bc75d81
commit 3634c3998a
6 changed files with 7 additions and 28 deletions

View file

@ -1023,7 +1023,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
}
if (node.init != null) {
addExpressionStatement(visitExpression(node.init));
visitExpressionIgnoreResult(node.init);
}
int startLabel = newLabel("for condition");
// If there is no update, continuing the loop is the same as going to the
@ -1553,29 +1553,17 @@ abstract class AsyncRewriterBase extends js.NodeVisitor {
@override
js.Expression visitVariableDeclarationList(js.VariableDeclarationList node) {
List<js.Expression> initializations = new List<js.Expression>();
// Declaration of local variables is hoisted outside the helper but the
// initialization is done here.
for (js.VariableInitialization initialization in node.declarations) {
js.VariableDeclaration declaration = initialization.declaration;
localVariables.add(declaration);
if (initialization.value != null) {
withExpression(initialization.value, (js.Expression value) {
initializations.add(
addExpressionStatement(
new js.Assignment(new js.VariableUse(declaration.name), value));
}, store: false);
}
}
if (initializations.isEmpty) {
// Dummy expression. Will be dropped by [visitExpressionIgnoreResult].
return js.number(0);
} else {
return initializations.reduce(
(js.Expression first, js.Expression second) {
return new js.Binary(",", first, second);
});
}
return js.number(0); // Dummy expression.
}
@override

View file

@ -155,9 +155,6 @@ third_party/di_tests/di_test: Pass, Slow # Issue 22896
[ $use_repository_packages ]
analyzer/test/*: PubGetError
[ $compiler == dart2js && $cps_ir ]
lookup_map/test/lookup_map_test: RuntimeError # $async$temp1.get$tests is not a function
[ $compiler == dart2js && $cps_ir && $host_checked ]
analyzer/test/enum_test: Crash # Issue 24485
analyzer/test/generated/all_the_rest_test: Crash # Issue 24485

View file

@ -64,12 +64,13 @@ r"""function() async {
switch (__goto) {
case 0:
// Function start
closures = [new A.main_closure()];
__goto = 2;
closures = [new A.main_closure()];
return thenHelper(closures, body, __completer);
return thenHelper(closures, body, __completer);
case 2:
// returning from await.
v0 = __result, v1 = 0;
v0 = __result;
v1 = 0;
if (v1 < 0 || v1 >= v0.length)
H.ioore(v0, v1);
else

View file

@ -6,8 +6,6 @@ compile_with_empty_libraries_test: Fail # Issue 24223
boolified_operator_test: Fail # Issue 8001
async_await_js_transform_test/01: RuntimeError # Issue 23997
# Don't mark these tests as failing. Instead, fix the errors/warnings that they
# report or update the whitelist in the test-files to temporarily allow
# digression.

View file

@ -271,7 +271,6 @@ async_star_regression_fisk_test: Crash # (fisk()async*{res.ad... cannot handle
async_star_stream_take_test: Crash # (Stream makeStream(i... cannot handle sync*/async* functions
async_star_take_reyield_test: Crash # (fivePartialSums(Str... cannot handle sync*/async* functions
async_star_test: Crash # (f()async*{}): cannot handle sync*/async* functions
async_this_bound_test: RuntimeError # Cannot read property 'set$f' of undefined
asyncstar_concat_test: Crash # (concat(a,b)async*{yield* a;yield* b;}): cannot handle sync*/async* functions
asyncstar_throw_in_catch_test: Crash # (foo4(Tracer tracer)... cannot handle sync*/async* functions
asyncstar_yield_test: Crash # (Stream<int> foo4()a... cannot handle sync*/async* functions
@ -279,10 +278,7 @@ asyncstar_yieldstar_test: Crash # (foo2(Stream subStream)async*{yield* subStream
await_for_cancel_test: Crash # (await for(var x in controller.stream){for(int j=0;j<10;j++ ){if(j==5)continue outer;}}): await for
await_for_test: Crash # (await for(var x in infiniteStream()){i++ ;if(i>10)break;t4.record(x);}): await for
await_for_use_local_test: Crash # (await for(var v in s){accum+= v;}): await for
await_future_test: RuntimeError # Cannot read property '_await_future_test$_box_0' of undefined
await_postfix_expr_test: RuntimeError # Please triage this failure.
await_regression_test: RuntimeError # "Obelix".then$1 is not a function
await_test: RuntimeError # Cannot read property '$add' of undefined
cha_deopt1_test: Crash # (d.make_u()): deferred access is not implemented
cha_deopt2_test: Crash # (d.make_u()): deferred access is not implemented
cha_deopt3_test: Crash # (d.make_u()): deferred access is not implemented

View file

@ -338,7 +338,6 @@ convert/streamed_conversion_json_utf8_decode_test: Skip # Timeout.
[ $compiler == dart2js && $cps_ir ]
async/async_await_zones_test: Crash # (await for(var x in bar().take(100)){sum+= x;}): await for
async/stream_empty_test: RuntimeError # $async$temp1.runTest_unreachable is not a function
async/stream_iterator_test: Crash # (Stream createCancel... cannot handle sync*/async* functions
convert/json_pretty_test: RuntimeError # Please triage this failure.
convert/line_splitter_test: RuntimeError # Please triage this failure.