Revision: 24655
Author:   [email protected]
Date:     Thu Oct 16 10:42:08 2014 UTC
Log:      Introduce v8::Exception::GetStackTrace API method.

This will be needed to get a stack trace from a DOMException.

API=v8::Exception::GetStackTrace
[email protected]
LOG=Y

Review URL: https://codereview.chromium.org/655243002
https://code.google.com/p/v8/source/detail?r=24655

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Tue Oct 14 14:43:45 2014 UTC
+++ /branches/bleeding_edge/include/v8.h        Thu Oct 16 10:42:08 2014 UTC
@@ -4164,6 +4164,8 @@
   static Local<Value> SyntaxError(Handle<String> message);
   static Local<Value> TypeError(Handle<String> message);
   static Local<Value> Error(Handle<String> message);
+
+  static Local<StackTrace> GetStackTrace(Handle<Value> exception);
 };


=======================================
--- /branches/bleeding_edge/src/api.cc  Tue Oct 14 14:45:03 2014 UTC
+++ /branches/bleeding_edge/src/api.cc  Thu Oct 16 10:42:08 2014 UTC
@@ -6926,6 +6926,21 @@
 #undef DEFINE_ERROR


+Local<StackTrace> Exception::GetStackTrace(Handle<Value> exception) {
+  i::Handle<i::Object> obj = Utils::OpenHandle(*exception);
+  if (!obj->IsJSObject()) return Local<StackTrace>();
+  i::Handle<i::JSObject> js_obj = i::Handle<i::JSObject>::cast(obj);
+  i::Isolate* isolate = js_obj->GetIsolate();
+  ENTER_V8(isolate);
+ i::Handle<i::Name> key = isolate->factory()->detailed_stack_trace_symbol(); + i::Handle<i::Object> property = i::JSObject::GetDataProperty(js_obj, key);
+  if (property->IsJSArray()) {
+    return Utils::StackTraceToLocal(i::Handle<i::JSArray>::cast(property));
+  }
+  return Local<StackTrace>();
+}
+
+
 // --- D e b u g   S u p p o r t ---

 bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) {
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Wed Oct 15 08:44:00 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-api.cc Thu Oct 16 10:42:08 2014 UTC
@@ -8502,6 +8502,47 @@
   CHECK(error->IsObject());
   CHECK(error.As<v8::Object>()->Get(message)->Equals(foo));
 }
+
+
+static void ThrowV8Exception(const v8::FunctionCallbackInfo<v8::Value>& info) {
+  ApiTestFuzzer::Fuzz();
+  v8::Handle<String> foo = v8_str("foo");
+  v8::Handle<String> message = v8_str("message");
+  v8::Handle<Value> error = v8::Exception::Error(foo);
+  CHECK(error->IsObject());
+  CHECK(error.As<v8::Object>()->Get(message)->Equals(foo));
+  info.GetIsolate()->ThrowException(error);
+  info.GetReturnValue().SetUndefined();
+}
+
+
+THREADED_TEST(ExceptionGetStackTrace) {
+  LocalContext context;
+  v8::HandleScope scope(context->GetIsolate());
+
+  v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
+
+  Local<v8::FunctionTemplate> fun =
+      v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception);
+  v8::Local<v8::Object> global = context->Global();
+  global->Set(v8_str("throwV8Exception"), fun->GetFunction());
+
+  TryCatch try_catch;
+  CompileRun("function f1() { throwV8Exception(); }; f1();");
+  CHECK(try_catch.HasCaught());
+
+  v8::Handle<v8::Value> error = try_catch.Exception();
+  v8::Handle<String> foo = v8_str("foo");
+  v8::Handle<String> message = v8_str("message");
+  CHECK(error->IsObject());
+  CHECK(error.As<v8::Object>()->Get(message)->Equals(foo));
+
+ v8::Handle<v8::StackTrace> stackTrace = v8::Exception::GetStackTrace(error);
+  CHECK(!stackTrace.IsEmpty());
+  CHECK_EQ(2, stackTrace->GetFrameCount());
+
+  v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
+}


 static void YGetter(Local<String> name,

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to