| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- // Test HostPromiseRejectionTracker - see ecma262 section 25.4.1.9
- let tests = [
- {
- name: "Reject promise with no reactions.",
- body: function(index)
- {
- let controller;
- let promise = new Promise((resolve, reject)=>{
- controller = {resolve, reject};
- });
- controller.reject("Rejection from test " + index);//Should notify rejected
- }
- },
- {
- name: "Reject promise with a catch reaction only.",
- body: function(index)
- {
- let controller;
- let promise = new Promise((resolve, reject)=>{
- controller = {resolve, reject};
- }).catch(()=>{});
- controller.reject("Rejection from test " + index);//Should NOT notify
- }
- },
- {
- name: "Reject promise with catch and then reactions.",
- body: function(index)
- {
- let controller;
- let promise = new Promise((resolve, reject)=>{
- controller = {resolve, reject};
- }).then(()=>{}).catch(()=>{});
- controller.reject("Rejection from test " + index);//Should NOT notify
- }
- },
- {
- name: "Reject promise then add a catch afterwards.",
- body: function(index)
- {
- let controller;
- let promise = new Promise((resolve, reject)=>{
- controller = {resolve, reject};
- });
- controller.reject("Rejection from test " + index);//Should notify rejected
- promise.catch(()=>{});//Should notify handled
- }
- },
- {
- name: "Reject promise then add two catches afterwards.",
- body: function(index)
- {
- let controller;
- let promise = new Promise((resolve, reject)=>{
- controller = {resolve, reject};
- });
- controller.reject("Rejection from test " + index);//Should notify rejected
- promise.catch(()=>{});//Should notify handled
- promise.catch(()=>{});//Should NOT notify
- }
- },
- {
- name: "Async function that throws.",
- body: function(index)
- {
- async function aFunction()
- {
- throw ("Rejection from test " + index);
- }
- aFunction();//Should notify rejected
- }
- },
- {
- name: "Async function that throws but is caught.",
- body: function(index)
- {
- async function aFunction()
- {
- throw ("Rejection from test " + index);
- }
- aFunction().catch(()=>{});//Should notify rejected AND then handled
- }
- },
- {
- name: "Async function that awaits a function that throws.",
- body: function(index)
- {
- async function aFunction()
- {
- throw ("Rejection from test " + index);//Should notify rejected
- }
- async function bFunction()
- {
- await aFunction();//Should notify handled
- }
- bFunction();//Should notify rejected in the async section
- },
- },
- {
- name: "Reject a handled promise then handle one of the handles but not the other.",
- body: function(index)
- {
- let controller;
- let promise = new Promise((resolve, reject) => { controller = {resolve, reject};});
- let a = promise.then(() => {});//a is not handled
- let b = promise.then(() => {});//b is not handled
- controller.reject("Rejection from test " + index);//no notification as handled
- let c = a.then(() => {}); //handle a
- c.catch(() => {b.then(()=>{})}); // handle c
- //b is still not handled -> notify once in async section
- //b has an async handler -> will notify handled in async section
- //the .then() on b is not handled so will notify in async section
- },
- },
- {
- name: "Reject a handled promise and don't handle either path.",
- body: function(index)
- {
- let controller;
- let promise = new Promise((resolve, reject) => { controller = {resolve, reject};});
- let a = promise.then(() => {});//a is not handled
- let b = promise.then(() => {});//b is not handled
- controller.reject("Rejection from test " + index);//no notification as handled
- let c = a.then(() => {}); //handle a
- //b is not handled -> will notify in async section
- //c is not handled -> will notify in async section
- }
- }
- ];
- for(let i = 0; i < tests.length; ++i)
- {
- WScript.Echo('Executing test #' + (i + 1) + ' - ' + tests[i].name);
- tests[i].body(i+1);
- }
- WScript.Echo("Begin async results:");
|