1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2013 the V8 project authors. All rights reserved. 2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Redistribution and use in source and binary forms, with or without 3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// modification, are permitted provided that the following conditions are 4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// met: 5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// 6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// * Redistributions of source code must retain the above copyright 7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// notice, this list of conditions and the following disclaimer. 8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// * Redistributions in binary form must reproduce the above 9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// copyright notice, this list of conditions and the following 10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// disclaimer in the documentation and/or other materials provided 11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// with the distribution. 12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// * Neither the name of Google Inc. nor the names of its 13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// contributors may be used to endorse or promote products derived 14b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// from this software without specific prior written permission. 15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// 16b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// In the assertions but the first, the ES5 spec actually requires 0, but 29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// that is arguably a spec bug, and other browsers return 1 like us. 30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// In ES6, all of those will presumably result in a ReferenceError. 31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Our main concern with this test is that we do not crash, though. 32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction f1() { 34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var XXX = 0 35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch try { throw 1 } catch (XXX) { 36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch eval("var h = function() { return XXX }") 37b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return h() 39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(1, f1()) 41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction f2() { 43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var XXX = 0 44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch try { throw 1 } catch (XXX) { 45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch eval("function h(){ return XXX }") 46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return h() 48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(1, f2()) 50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction f3() { 52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var XXX = 0 53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch try { throw 1 } catch (XXX) { 54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch try { throw 2 } catch (y) { 55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch eval("function h(){ return XXX }") 56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return h() 59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(1, f3()) 61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction f4() { 63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var XXX = 0 64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch try { throw 1 } catch (XXX) { 65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch with ({}) { 66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch eval("function h(){ return XXX }") 67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 68b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 69b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return h() 70b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 71b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(1, f4()) 72b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 73b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction f5() { 74b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var XXX = 0 75b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch try { throw 1 } catch (XXX) { 76b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch eval('eval("function h(){ return XXX }")') 77b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 78b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return h() 79b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 80b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(1, f5()) 81b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 82b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction f6() { 83b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var XXX = 0 84b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch try { throw 1 } catch (XXX) { 85b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch eval("var h = (function() { function g(){ return XXX } return g })()") 86b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 87b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return h() 88b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 89b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(1, f6()) 90b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 91b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction f7() { 92b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var XXX = 0 93b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch try { throw 1 } catch (XXX) { 94b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch eval("function h() { var XXX=2; function g(){ return XXX } return g }") 95b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 96b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return h()() 97b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 98b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(2, f7()) // ! 99b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 100b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochvar XXX = 0 101b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochtry { throw 1 } catch (XXX) { 102b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch eval("function h(){ return XXX }") 103b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 104b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(1, h()) 105