Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: test/mjsunit/debug-liveedit-restart-frame-on-exception.js

Issue 22801003: Patch CEntry stub to swallow exception if liveedit/restart frame needs it. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: follow code review Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/x64/code-stubs-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/debug-liveedit-restart-frame-on-exception.js
diff --git a/test/mjsunit/debug-liveedit-restart-frame-on-exception.js b/test/mjsunit/debug-liveedit-restart-frame-on-exception.js
new file mode 100644
index 0000000000000000000000000000000000000000..aae8dcf9d1b6f15f2e58318b933135cae6e9a948
--- /dev/null
+++ b/test/mjsunit/debug-liveedit-restart-frame-on-exception.js
@@ -0,0 +1,257 @@
+// Copyright 2012 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Flags: --expose-debug-as debug
+// Get the Debug object exposed from the debug context global object.
+
+Debug = debug.Debug
+
+function TestCase(fun, restart_fun_name, break_type)
+{
+ function FindCallFrame(exec_state, function_name) {
+ for (var i = 0; i < exec_state.frameCount(); i++) {
+ var frame = exec_state.frame(i);
+ var func_mirror = frame.func();
+ if (function_name== func_mirror.name()) {
+ return frame;
+ }
+ }
+ throw new Error("Failed to find function name " + function_name);
+ }
+
+ function DebuggerStatementHandler(exec_state) {
+ var frame = FindCallFrame(exec_state, restart_fun_name);
+ // Throws if fails.
+ Debug.LiveEdit.RestartFrame(frame);
+ }
+
+ var saved_exception = null;
+
+ function listener(event, exec_state, event_data, data) {
+ if (saved_exception != null) {
+ return;
+ }
+ if (event == Debug.DebugEvent.BeforeCompile ||
+ event == Debug.DebugEvent.AfterCompile) {
+ // Ignore.
+ } else if (event == break_type) {
+ try {
+ DebuggerStatementHandler(exec_state);
+ } catch (e) {
+ saved_exception = e;
+ }
+ } else {
+ var name = event;
+ for (var k in Debug.DebugEvent) {
+ if (Debug.DebugEvent[k] == event) {
+ name = "Debug.DebugEvent." + k;
+ }
+ }
+ print("Other: " + name);
+ }
+ }
+
+ var fun_name = /function ?(.*)\(/.exec(String(fun))[1];
+ print("Test function " + fun_name);
+
+ Debug.setListener(listener);
+
+ var result;
+ try {
+ result = fun();
+ } catch (e) {
+ result = "Exception caught: " + e;
+ }
+
+ Debug.setListener(null);
+
+ if (saved_exception) {
+ print("Exception: " + saved_exception);
+ print("Stack: " + saved_exception.stack);
+ assertUnreachable();
+ }
+ print("Done, result " + result);
+ assertEquals("Capybara", result);
+ print("\n");
+}
+
+
+
+// Test cases.
+
+
+// Restart when throwing exception in eval.
+function RestartWhenThrowingInEval() {
+ var input = [ "}", "'Capybara'" ];
+ var pos = 0;
+
+ function Inner(p) {
+ return eval(p);
+ }
+
+ function Helper() {
+ var p = input[pos++];
+ return Inner(p);
+ }
+
+ return Helper();
+}
+
+Debug.setBreakOnException();
+TestCase(RestartWhenThrowingInEval, "Helper", Debug.DebugEvent.Exception)
+Debug.clearBreakOnException();
+
+
+// Restart when throwing exception.
+function RestartWhenThrowing() {
+ var input = [ undefined, "Capybara" ];
+ var pos = 0;
+
+ function Inner(p) {
+ return p.toString();
+ }
+
+ function Helper() {
+ var p = input[pos++];
+ return Inner(p);
+ }
+
+ return Helper();
+}
+
+Debug.setBreakOnException();
+TestCase(RestartWhenThrowing, "Helper", Debug.DebugEvent.Exception)
+Debug.clearBreakOnException();
+
+
+// Restart when catching an exception.
+function RestartWhenCatching() {
+ var input = [ undefined, "Capybara" ];
+ var pos = 0;
+
+ function Inner() {
+ var p = input[pos++];
+ try {
+ return p.toString();
+ } catch (e) {
+ debugger;
+ return "Not capybara";
+ }
+ }
+
+ return Inner();
+}
+
+TestCase(RestartWhenCatching, "Inner", Debug.DebugEvent.Break)
+
+
+// Restart on throwing while catching an exception.
+function RestartWhenThrowingInCatch() {
+ var input = [ undefined, "Capybara" ];
+ var pos = 0;
+
+ function Inner() {
+ var p = input[pos++];
+ Debug.clearBreakOnException();
+ try {
+ return p.toString();
+ } catch (e) {
+ Debug.setBreakOnException();
+ (3).changeValue();
+ }
+ return "Something";
+ }
+
+ return Inner();
+}
+
+TestCase(RestartWhenThrowingInCatch, "Inner", Debug.DebugEvent.Exception)
+Debug.clearBreakOnException();
+
+
+// Restart on throwing while catching an exception, not touching catch.
+function RestartWhenThrowingInCatchKeepCatch() {
+ var input = [ undefined, "Cat" ];
+ var pos = 0;
+
+ function Inner() {
+ var p = input[pos++];
+ Debug.setBreakOnException();
+ return p.toString();
+ }
+
+ function Middle() {
+ Debug.clearBreakOnException();
+ try {
+ throw new Error("Capybara");
+ } catch (e) {
+ Inner();
+ return e.message;
+ }
+ }
+
+ return Middle();
+}
+
+TestCase(RestartWhenThrowingInCatchKeepCatch, "Inner",
+ Debug.DebugEvent.Exception)
+Debug.clearBreakOnException();
+
+
+// Restart while in finally, not touching finally.
+function RestartWhenThrowingInFinally() {
+ var input = [
+ function() { debugger; },
+ function() {}
+ ];
+ var pos = 0;
+
+ function Inner() {
+ try {
+ throw new Error("Cat");
+ } catch (e) {
+ input[pos++]();
+ }
+ }
+
+ function Middle() {
+ try {
+ try {
+ throw new Error("Capybara");
+ } finally {
+ Inner();
+ }
+ } catch (e) {
+ return e.message;
+ }
+ }
+
+ return Middle();
+}
+
+TestCase(RestartWhenThrowingInFinally, "Inner", Debug.DebugEvent.Break)
+
« no previous file with comments | « src/x64/code-stubs-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698