13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Copyright 2013 the V8 project authors. All rights reserved.
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Redistribution and use in source and binary forms, with or without
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// modification, are permitted provided that the following conditions
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// are met:
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// 1.  Redistributions of source code must retain the above copyright
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//     notice, this list of conditions and the following disclaimer.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// 2.  Redistributions in binary form must reproduce the above copyright
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//     notice, this list of conditions and the following disclaimer in the
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//     documentation and/or other materials provided with the distribution.
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydescription('This test makes sure stack unwinding works correctly when it occurs inside an eval contained in a dynamic scope.');
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvar result;
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryfunction runTest() {
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    var test = "outer scope";
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    with({test:"inner scope"}) {
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        eval("try { throw ''; } catch (e) { result = test; shouldBe('result', '\"inner scope\"'); }");
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        result = null;
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        eval("try { with({test:'innermost scope'}) throw ''; } catch (e) { result = test; shouldBe('result', '\"inner scope\"'); }");
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        result = null;
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        eval("with ({test:'innermost scope'}) try { throw ''; } catch (e) { result = test; shouldBe('result', '\"innermost scope\"'); }");
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        result = null;
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        with ({test:'innermost scope'}) eval("try { throw ''; } catch (e) { result = test; shouldBe('result', '\"innermost scope\"'); }");
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        result = null;
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        try {
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry            eval("try { throw ''; } finally { result = test; shouldBe('result', '\"inner scope\"'); result = null; undeclared; }");
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        } catch(e) {
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry            result = test;
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry            shouldBe('result', '"inner scope"');
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry            result = null;
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry            eval("try { with({test:'innermost scope'}) throw ''; } catch (e) { result = test; shouldBe('result', '\"inner scope\"'); }");
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry            result = null;
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry            eval("with ({test:'innermost scope'}) try { throw ''; } catch (e) { result = test; shouldBe('result', '\"innermost scope\"'); }");
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry            result = null;
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry            with ({test:'innermost scope'}) eval("try { throw ''; } catch (e) { result = test; shouldBe('result', '\"innermost scope\"'); }");
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        }
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    }
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    result = test;
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    eval("try { throw ''; } catch (e) { result = test; shouldBe('result', '\"outer scope\"'); }");
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    eval("result = test");
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    eval("try { throw ''; } catch (e) { result = test; shouldBe('result', '\"outer scope\"'); }");
54}
55runTest();
56