forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps: revert removal of V8::PromiseEvent
The removal of the promise debug event is an API/ABI breaking change. Ref: https://codereview.chromium.org/1833563002 Ref: ofrobots#23 PR-URL: nodejs#7016 Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
- Loading branch information
Showing
11 changed files
with
299 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Copyright 2014 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: --allow-natives-syntax --expose-debug-as debug | ||
|
||
Debug = debug.Debug; | ||
|
||
var eventsExpected = 16; | ||
var exception = null; | ||
var result = []; | ||
|
||
function updatePromise(promise, parentPromise, status, value) { | ||
var i; | ||
for (i = 0; i < result.length; ++i) { | ||
if (result[i].promise === promise) { | ||
result[i].parentPromise = parentPromise || result[i].parentPromise; | ||
result[i].status = status || result[i].status; | ||
result[i].value = value || result[i].value; | ||
break; | ||
} | ||
} | ||
assertTrue(i < result.length); | ||
} | ||
|
||
function listener(event, exec_state, event_data, data) { | ||
if (event != Debug.DebugEvent.PromiseEvent) return; | ||
try { | ||
eventsExpected--; | ||
assertTrue(event_data.promise().isPromise()); | ||
if (event_data.status() === 0) { | ||
// New promise. | ||
assertEquals("pending", event_data.promise().status()); | ||
result.push({ promise: event_data.promise().value(), status: 0 }); | ||
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); | ||
} else if (event_data.status() !== undefined) { | ||
// Resolve/reject promise. | ||
updatePromise(event_data.promise().value(), | ||
undefined, | ||
event_data.status(), | ||
event_data.value().value()); | ||
} else { | ||
// Chain promises. | ||
assertTrue(event_data.parentPromise().isPromise()); | ||
updatePromise(event_data.promise().value(), | ||
event_data.parentPromise().value()); | ||
assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); | ||
} | ||
} catch (e) { | ||
print(e + e.stack) | ||
exception = e; | ||
} | ||
} | ||
|
||
Debug.setListener(listener); | ||
|
||
function resolver(resolve, reject) { resolve(); } | ||
|
||
var p1 = new Promise(resolver); // event | ||
var p2 = p1.then().then(); // event | ||
var p3 = new Promise(function(resolve, reject) { // event | ||
reject("rejected"); | ||
}); | ||
var p4 = p3.then(); // event | ||
var p5 = p1.then(); // event | ||
|
||
function assertAsync(b, s) { | ||
if (b) { | ||
print(s, "succeeded"); | ||
} else { | ||
%AbortJS(s + " FAILED!"); | ||
} | ||
} | ||
|
||
function testDone(iteration) { | ||
function checkResult() { | ||
if (eventsExpected === 0) { | ||
assertAsync(result.length === 6, "result.length"); | ||
|
||
assertAsync(result[0].promise === p1, "result[0].promise"); | ||
assertAsync(result[0].parentPromise === undefined, | ||
"result[0].parentPromise"); | ||
assertAsync(result[0].status === 1, "result[0].status"); | ||
assertAsync(result[0].value === undefined, "result[0].value"); | ||
|
||
assertAsync(result[1].parentPromise === p1, | ||
"result[1].parentPromise"); | ||
assertAsync(result[1].status === 1, "result[1].status"); | ||
|
||
assertAsync(result[2].promise === p2, "result[2].promise"); | ||
|
||
assertAsync(result[3].promise === p3, "result[3].promise"); | ||
assertAsync(result[3].parentPromise === undefined, | ||
"result[3].parentPromise"); | ||
assertAsync(result[3].status === -1, "result[3].status"); | ||
assertAsync(result[3].value === "rejected", "result[3].value"); | ||
|
||
assertAsync(result[4].promise === p4, "result[4].promise"); | ||
assertAsync(result[4].parentPromise === p3, | ||
"result[4].parentPromise"); | ||
assertAsync(result[4].status === -1, "result[4].status"); | ||
assertAsync(result[4].value === "rejected", "result[4].value"); | ||
|
||
assertAsync(result[5].promise === p5, "result[5].promise"); | ||
assertAsync(result[5].parentPromise === p1, | ||
"result[5].parentPromise"); | ||
assertAsync(result[5].status === 1, "result[5].status"); | ||
|
||
assertAsync(exception === null, "exception === null"); | ||
Debug.setListener(null); | ||
} else if (iteration > 10) { | ||
%AbortJS("Not all events were received!"); | ||
} else { | ||
testDone(iteration + 1); | ||
} | ||
} | ||
|
||
var iteration = iteration || 0; | ||
%EnqueueMicrotask(checkResult); | ||
} | ||
|
||
testDone(); |
32 changes: 32 additions & 0 deletions
32
deps/v8/test/mjsunit/es6/debug-promises/resolve-after-aborted-try-finally.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2014 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: --expose-debug-as debug --allow-natives-syntax | ||
|
||
// Test debug events when we listen to all exceptions and | ||
// there is a catch handler for the exception thrown in a Promise. | ||
// We expect a normal Exception debug event to be triggered. | ||
|
||
Debug = debug.Debug; | ||
|
||
var events = []; | ||
|
||
function listener(event, exec_state, event_data, data) { | ||
if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status()); | ||
} | ||
|
||
Debug.setListener(listener); | ||
|
||
var p = new Promise(function(resolve, reject) { | ||
do { | ||
try { | ||
throw new Error("reject"); | ||
} finally { | ||
break; // No rethrow. | ||
} | ||
} while (false); | ||
resolve(); | ||
}); | ||
|
||
assertEquals([0 /* create */, 1 /* resolve */], events); |
29 changes: 29 additions & 0 deletions
29
deps/v8/test/mjsunit/es6/debug-promises/resolve-after-try-catch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2014 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: --expose-debug-as debug --allow-natives-syntax | ||
|
||
// Test debug events when we listen to all exceptions and | ||
// there is a catch handler for the exception thrown in a Promise. | ||
// We expect a normal Exception debug event to be triggered. | ||
|
||
Debug = debug.Debug; | ||
|
||
var events = []; | ||
|
||
function listener(event, exec_state, event_data, data) { | ||
if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status()); | ||
} | ||
|
||
Debug.setListener(listener); | ||
|
||
var p = new Promise(function (resolve, reject) { | ||
try { | ||
throw new Error("reject"); | ||
} catch (e) { | ||
} | ||
resolve(); | ||
}); | ||
|
||
assertEquals([0 /* create */, 1 /* resolve */], events); |
30 changes: 30 additions & 0 deletions
30
deps/v8/test/mjsunit/es6/debug-promises/rethrow-in-try-finally.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2014 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: --expose-debug-as debug --allow-natives-syntax | ||
|
||
// Test debug events when we listen to all exceptions and | ||
// there is a catch handler for the exception thrown in a Promise. | ||
// We expect a normal Exception debug event to be triggered. | ||
|
||
Debug = debug.Debug; | ||
|
||
var events = []; | ||
|
||
function listener(event, exec_state, event_data, data) { | ||
if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status()); | ||
} | ||
|
||
Debug.setListener(listener); | ||
|
||
var p = new Promise(function(resolve, reject) { | ||
try { | ||
throw new Error("reject"); | ||
} finally { | ||
// Implicit rethrow. | ||
} | ||
resolve(); | ||
}); | ||
|
||
assertEquals([0 /* create */, -1 /* rethrown */], events); |