| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- function printError(e) {
- print(e.name);
- print(e.number);
- print(e.description);
- }
- var isMac = (WScript.Platform.OS === 'darwin');
- var isWin = (WScript.Platform.OS === 'win32');
- var expects = [
- '#1', // 0
- 'In finally',
- 'Error: Out of stack space', // 2
- '#2',
- 'In finally', // 4
- 'Error: Out of stack space',
- '#3', // 6
- 'In finally',
- 'Error: Out of stack space' // 8
- ];
- if (isWin) {
- expects.push('testing stack overflow handling with catch block'); // 9
- expects.push('Error: Out of stack space'); // 10
- }
- expects.push('testing stack overflow handling with finally block'); // 11
- expects.push('Error: Out of stack space'); // 12
- if (!isMac) // last test (sometimes) we hit timeout before we hit stackoverflow.
- expects.push('Error: Out of stack space'); // 13
- expects.push('END'); // 14
- var index = 0;
- function printLog(str) {
- if (expects[index++] != str) {
- WScript.Echo('At ' + (index - 1) + ' expected \n' + expects[index - 1] + '\nOutput:' + str);
- WScript.Quit(1);
- }
- }
- for (var i = 1; i < 4; i++) {
- printLog("#" + i);
- try {
- try {
- function f() {
- f();
- }
- f();
- } finally {
- printLog("In finally");
- }
- }
- catch (e) {
- printLog(e);
- }
- }
- if (isWin) { // xplat CI timeouts (it doesn't st. overflows as soon as Windows does)
- printLog("testing stack overflow handling with catch block");
- try {
- function stackOverFlowCatch() {
- try {
- stackOverFlowCatch();
- while (true) { }
- }
- catch (e) {
- throw e;
- }
- }
- stackOverFlowCatch();
- }
- catch (e) {
- printLog(e);
- }
- }
- printLog("testing stack overflow handling with finally block");
- try
- {
- function stackOverFlowFinally() {
- try {
- stackOverFlowFinally();
- while (true) {
- }
- }
- finally {
- DoSomething();
- }
- }
- stackOverFlowFinally();
- }
- catch(e) {
- printLog(e);
- }
- function DoSomething()
- {
- }
- // 10K is not enough for our osx setup.
- // for bigger numbers, we hit to timeout on CI (before we actually hit to S.O)
- if (!isMac) {
- try
- {
- var count = 100000;
- var a = {};
- var b = a;
- for (var i = 0; i < count; i++)
- {
- a.x = {};
- a = a.x;
- }
- eval("JSON.stringify(b)");
- }
- catch(e) {
- printLog(e);
- }
- }
- printLog('END'); // do not remove this
- WScript.Echo("Pass");
|