Chromium Code Reviews| Index: test/mjsunit/harmony/debug-async-liveedit.js |
| diff --git a/test/mjsunit/es6/generators-debug-liveedit.js b/test/mjsunit/harmony/debug-async-liveedit.js |
| similarity index 52% |
| copy from test/mjsunit/es6/generators-debug-liveedit.js |
| copy to test/mjsunit/harmony/debug-async-liveedit.js |
| index 987a42c41cd94b986e741d6be18bbaa11f7be452..4b69f267f3bbf4d79ecbc4de0c6b501f63bfd9b5 100644 |
| --- a/test/mjsunit/es6/generators-debug-liveedit.js |
| +++ b/test/mjsunit/harmony/debug-async-liveedit.js |
| @@ -1,7 +1,8 @@ |
| -// Copyright 2014 the V8 project authors. All rights reserved. |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +// Flags: --harmony-async-await |
| // Flags: --expose-debug-as debug --allow-natives-syntax |
| var Debug = debug.Debug; |
| @@ -9,18 +10,27 @@ var LiveEdit = Debug.LiveEdit; |
| unique_id = 0; |
| -var Generator = (function*(){}).constructor; |
| +var AsyncFunction = (async function(){}).constructor; |
| -function assertIteratorResult(value, done, result) { |
| - assertEquals({value: value, done: done}, result); |
| +function assertPromiseValue(value, promise) { |
| + promise.then(resolve => { |
| + went = true; |
| + if (resolve !== value) { |
| + print(`expected ${value} found ${resolve}`); |
| + quit(1); |
| + } |
| + }, reject => { |
| + print(`rejected ${reject}`); |
| + quit(1); |
| + }); |
| } |
| -function MakeGenerator() { |
| +function MakeAsyncFunction() { |
| // Prevents eval script caching. |
| unique_id++; |
| - return Generator('callback', |
| + return AsyncFunction('callback', |
| "/* " + unique_id + "*/\n" + |
| - "yield callback();\n" + |
| + "await callback();\n" + |
| "return 'Cat';\n"); |
| } |
| @@ -35,11 +45,10 @@ function MakeFunction() { |
| // First, try MakeGenerator with no perturbations. |
| (function(){ |
| - var generator = MakeGenerator(); |
| + var asyncfn = MakeAsyncFunction(); |
| function callback() {}; |
| - var iter = generator(callback); |
| - assertIteratorResult(undefined, false, iter.next()); |
| - assertIteratorResult("Cat", true, iter.next()); |
| + var promise = asyncfn(callback); |
| + assertPromiseValue('Cat', promise); |
| })(); |
| function patch(fun, from, to) { |
| @@ -47,6 +56,7 @@ function patch(fun, from, to) { |
| var log = new Array(); |
| var script = Debug.findScript(fun); |
| var pos = script.source.indexOf(from); |
| + print(`pos ${pos}`); |
| try { |
| LiveEdit.TestApi.ApplySingleChunkPatch(script, pos, from.length, to, |
| log); |
| @@ -57,40 +67,41 @@ function patch(fun, from, to) { |
| %ExecuteInDebugContext(debug); |
| } |
| -// Try to edit a MakeGenerator while it's running, then again while it's |
| +// Try to edit a MakeAsyncFunction while it's running, then again while it's |
| // stopped. |
| (function(){ |
| - var generator = MakeGenerator(); |
| + var asyncfn = MakeAsyncFunction(); |
| - var gen_patch_attempted = false; |
| - function attempt_gen_patch() { |
| - assertFalse(gen_patch_attempted); |
| - gen_patch_attempted = true; |
| - assertThrows(function() { patch(generator, "'Cat'", "'Capybara'") }, |
| + var patch_attempted = false; |
| + function attempt_patch() { |
| + assertFalse(patch_attempted); |
| + patch_attempted = true; |
| + assertThrows(function() { patch(asyncfn, "'Cat'", "'Capybara'") }, |
| LiveEdit.Failure); |
| }; |
| - var iter = generator(attempt_gen_patch); |
| - assertIteratorResult(undefined, false, iter.next()); |
| - // Patch should not succeed because there is a live generator activation on |
| - // the stack. |
| - assertIteratorResult("Cat", true, iter.next()); |
| - assertTrue(gen_patch_attempted); |
| + var promise = asyncfn(attempt_patch); |
| + // Patch should not succeed because there is a live async function activation |
| + // on the stack. |
| + assertPromiseValue("Cat", promise); |
| + assertTrue(patch_attempted); |
| + |
| + %RunMicrotasks(); |
| // At this point one iterator is live, but closed, so the patch will succeed. |
| - patch(generator, "'Cat'", "'Capybara'"); |
| - iter = generator(function(){}); |
| - assertIteratorResult(undefined, false, iter.next()); |
| + patch(asyncfn, "'Cat'", "'Capybara'"); |
| + promise = asyncfn(function(){}); |
| // Patch successful. |
| - assertIteratorResult("Capybara", true, iter.next()); |
| + assertPromiseValue("Capybara", promise); |
| - // Patching will fail however when a live iterator is suspended. |
| - iter = generator(function(){}); |
| - assertIteratorResult(undefined, false, iter.next()); |
| - assertThrows(function() { patch(generator, "'Capybara'", "'Tapir'") }, |
| + // Patching will fail however when an async function is suspended. |
| + var resolve; |
| + promise = asyncfn(function(){return new Promise(function(r){resolve = r})}); |
| + assertThrows(function() { patch(asyncfn, "'Capybara'", "'Tapir'") }, |
| LiveEdit.Failure); |
| - assertIteratorResult("Capybara", true, iter.next()); |
| + resolve(); |
| + assertPromiseValue("Capybara", promise); |
| - // Try to patch functions with activations inside and outside generator |
| + // Try to patch functions with activations inside and outside async |
| // function activations. We should succeed in the former case, but not in the |
| // latter. |
| var fun_outside = MakeFunction(); |
| @@ -104,16 +115,18 @@ function patch(fun, from, to) { |
| return; |
| } |
| fun_patch_attempted = true; |
| - // Patching outside a generator activation must fail. |
| + // Patching outside an async function activation must fail. |
| assertThrows(function() { patch(fun_outside, "'Cat'", "'Cobra'") }, |
|
caitp (gmail)
2016/06/08 14:01:24
New theory on why this is broken:
By the time we
|
| LiveEdit.Failure); |
| - // Patching inside a generator activation may succeed. |
| + // Patching inside an async function activation may succeed. |
| patch(fun_inside, "'Cat'", "'Koala'"); |
| } |
| - iter = generator(function() { return fun_inside(attempt_fun_patches) }); |
| + promise = asyncfn(function() { return fun_inside(attempt_fun_patches) }); |
| assertEquals('Cat', |
| fun_outside(function () { |
| - assertIteratorResult('Koala', false, iter.next()); |
| + assertPromiseValue('Koala', promise); |
| assertTrue(fun_patch_restarted); |
| })); |
| })(); |
| + |
| +%RunMicrotasks(); |