14515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// Copyright 2010 the V8 project authors. All rights reserved. 24515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// Redistribution and use in source and binary forms, with or without 34515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// modification, are permitted provided that the following conditions are 44515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// met: 54515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// 64515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// * Redistributions of source code must retain the above copyright 74515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// notice, this list of conditions and the following disclaimer. 84515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// * Redistributions in binary form must reproduce the above 94515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// copyright notice, this list of conditions and the following 104515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// disclaimer in the documentation and/or other materials provided 114515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// with the distribution. 124515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// * Neither the name of Google Inc. nor the names of its 134515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// contributors may be used to endorse or promote products derived 144515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// from this software without specific prior written permission. 154515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// 164515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 284515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// Flags: --expose-debug-as debug 294515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// Get the Debug object exposed from the debug context global object. 304515c472dc3e5ed2448a564600976759e569a0a8Leon ClarkeDebug = debug.Debug 314515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 324515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkevar exception = null; // Exception in debug event listener. 334515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 344515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkefunction listener(event, exec_state, event_data, data) { 354515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke try { 364515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke if (event == Debug.DebugEvent.AfterCompile) { 374515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke assertEquals(Debug.ScriptCompilationType.Eval, 384515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke event_data.script().compilationType(), 394515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 'Wrong compilationType'); 404515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke var evalFromScript = event_data.script().evalFromScript(); 414515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke assertTrue(!!evalFromScript, ' evalFromScript '); 424515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke assertFalse(evalFromScript.isUndefined(), 'evalFromScript.isUndefined()'); 434515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke assertTrue(/debug-compile-event-newfunction.js$/.test( 444515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke evalFromScript.name()), 454515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 'Wrong eval from script name.'); 464515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 474515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke var evalFromLocation = event_data.script().evalFromLocation(); 484515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke assertTrue(!!evalFromLocation, 'evalFromLocation is undefined'); 494515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke assertEquals(63, evalFromLocation.line); 504515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 514515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke // Check that the event can be serialized without exceptions. 524515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke var json = event_data.toJSONProtocol(); 534515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke } 544515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke } catch (e) { 554515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke exception = e 564515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke } 574515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke}; 584515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 594515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 604515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// Add the debug event listener. 614515c472dc3e5ed2448a564600976759e569a0a8Leon ClarkeDebug.setListener(listener); 624515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 634515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke// Create a function from its body text. It will lead to an eval. 644515c472dc3e5ed2448a564600976759e569a0a8Leon Clarkenew Function('arg1', 'return arg1 + 1;'); 654515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 664515c472dc3e5ed2448a564600976759e569a0a8Leon ClarkeassertNull(exception, "exception in listener"); 674515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke 684515c472dc3e5ed2448a564600976759e569a0a8Leon ClarkeDebug.setListener(null); 69