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

Side by Side Diff: test/cctest/test-api.cc

Issue 655243002: Introduce v8::Exception::GetStackTrace API method. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: added test Created 6 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 8486 matching lines...) Expand 10 before | Expand all | Expand 10 after
8497 CHECK(syntax_error.As<v8::Object>()->Get(message)->Equals(foo)); 8497 CHECK(syntax_error.As<v8::Object>()->Get(message)->Equals(foo));
8498 v8::Handle<Value> type_error = v8::Exception::TypeError(foo); 8498 v8::Handle<Value> type_error = v8::Exception::TypeError(foo);
8499 CHECK(type_error->IsObject()); 8499 CHECK(type_error->IsObject());
8500 CHECK(type_error.As<v8::Object>()->Get(message)->Equals(foo)); 8500 CHECK(type_error.As<v8::Object>()->Get(message)->Equals(foo));
8501 v8::Handle<Value> error = v8::Exception::Error(foo); 8501 v8::Handle<Value> error = v8::Exception::Error(foo);
8502 CHECK(error->IsObject()); 8502 CHECK(error->IsObject());
8503 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); 8503 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo));
8504 } 8504 }
8505 8505
8506 8506
8507 static void ThrowV8Exception(const v8::FunctionCallbackInfo<v8::Value>& info) {
8508 ApiTestFuzzer::Fuzz();
8509 v8::Handle<String> foo = v8_str("foo");
8510 v8::Handle<String> message = v8_str("message");
8511 v8::Handle<Value> error = v8::Exception::Error(foo);
8512 CHECK(error->IsObject());
8513 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo));
8514 info.GetIsolate()->ThrowException(error);
8515 info.GetReturnValue().SetUndefined();
8516 }
8517
8518
8519 THREADED_TEST(ExceptionGetStackTrace) {
8520 LocalContext context;
8521 v8::HandleScope scope(context->GetIsolate());
8522
8523 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
8524
8525 Local<v8::FunctionTemplate> fun =
8526 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception);
8527 v8::Local<v8::Object> global = context->Global();
8528 global->Set(v8_str("throwV8Exception"), fun->GetFunction());
8529
8530 TryCatch try_catch;
8531 CompileRun("function f1() { throwV8Exception(); }; f1();");
8532 CHECK(try_catch.HasCaught());
8533
8534 v8::Handle<v8::Value> error = try_catch.Exception();
8535 v8::Handle<String> foo = v8_str("foo");
8536 v8::Handle<String> message = v8_str("message");
8537 CHECK(error->IsObject());
8538 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo));
8539
8540 v8::Handle<v8::StackTrace> stackTrace = v8::Exception::GetStackTrace(error);
8541 CHECK(!stackTrace.IsEmpty());
8542 CHECK_EQ(2, stackTrace->GetFrameCount());
8543
8544 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
8545 }
8546
8547
8507 static void YGetter(Local<String> name, 8548 static void YGetter(Local<String> name,
8508 const v8::PropertyCallbackInfo<v8::Value>& info) { 8549 const v8::PropertyCallbackInfo<v8::Value>& info) {
8509 ApiTestFuzzer::Fuzz(); 8550 ApiTestFuzzer::Fuzz();
8510 info.GetReturnValue().Set(v8_num(10)); 8551 info.GetReturnValue().Set(v8_num(10));
8511 } 8552 }
8512 8553
8513 8554
8514 static void YSetter(Local<String> name, 8555 static void YSetter(Local<String> name,
8515 Local<Value> value, 8556 Local<Value> value,
8516 const v8::PropertyCallbackInfo<void>& info) { 8557 const v8::PropertyCallbackInfo<void>& info) {
(...skipping 15276 matching lines...) Expand 10 before | Expand all | Expand 10 after
23793 char chunk2[] = 23834 char chunk2[] =
23794 "XXr = 13;\n" 23835 "XXr = 13;\n"
23795 " return foob\xeb\x91\x80\xeb\x91\x80r;\n" 23836 " return foob\xeb\x91\x80\xeb\x91\x80r;\n"
23796 "}\n"; 23837 "}\n";
23797 chunk1[strlen(chunk1) - 1] = reference[0]; 23838 chunk1[strlen(chunk1) - 1] = reference[0];
23798 chunk2[0] = reference[1]; 23839 chunk2[0] = reference[1];
23799 chunk2[1] = reference[2]; 23840 chunk2[1] = reference[2];
23800 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 23841 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
23801 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); 23842 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
23802 } 23843 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698