1 // Copyright 2013 the V8 project authors. All rights reserved. 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions 6 // are met: 7 // 1. Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // 2. Redistributions in binary form must reproduce the above copyright 10 // notice, this list of conditions and the following disclaimer in the 11 // documentation and/or other materials provided with the distribution. 12 // 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24 description('Test that if an arrity check causes a stack overflow, the exception goes to the right catch'); 25 26 function funcWith20Args(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 27 arg9, arg10, arg11, arg12, arg13, arg14, arg15, 28 arg16, arg17, arg18, arg19, arg20) 29 { 30 debug("ERROR: Shouldn't arrive in 20 arg function!"); 31 } 32 33 var gotRightCatch = false, gotWrongCatch1 = false, gotWrongCatch2 = false; 34 35 function test1() 36 { 37 try { 38 test2(); 39 } catch (err) { 40 // Should get here because of stack overflow, 41 // now cause a stack overflow exception due to arrity processing 42 try { 43 var dummy = new RegExp('a|b|c'); 44 } catch(err) { 45 // (1) It is dendent on the stack size if we arrive here, in (2) or 46 // both. 47 gotWrongCatch1 = true; 48 } 49 50 try { 51 funcWith20Args(1, 2, 3); 52 } catch (err2) { 53 gotRightCatch = true; 54 } 55 } 56 } 57 58 function test2() 59 { 60 try { 61 var dummy = new Date(); 62 } catch(err) { 63 // (2) It is dendent on the stack size if we arrive here, in (1) or 64 // both. 65 gotWrongCatch2 = true; 66 } 67 68 try { 69 test1(); 70 } catch (err) { 71 // Should get here because of stack overflow, 72 // now cause a stack overflow exception due to arrity processing 73 try { 74 funcWith20Args(1, 2, 3, 4, 5, 6); 75 } catch (err2) { 76 gotRightCatch = true; 77 } 78 } 79 } 80 81 test1(); 82 83 shouldBeTrue("gotRightCatch"); 84