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

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

Issue 6397011: Make exception thrown via v8 public API propagate to v8::TryCatch as JS thrown exceptions do. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing Vitaly's comments Created 9 years, 10 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/top.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 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 static bool IsNaN(double x) { 45 static bool IsNaN(double x) {
46 #ifdef WIN32 46 #ifdef WIN32
47 return _isnan(x); 47 return _isnan(x);
48 #else 48 #else
49 return isnan(x); 49 return isnan(x);
50 #endif 50 #endif
51 } 51 }
52 52
53 using ::v8::ObjectTemplate; 53 using ::v8::ObjectTemplate;
54 using ::v8::FunctionTemplate;
54 using ::v8::Value; 55 using ::v8::Value;
55 using ::v8::Context; 56 using ::v8::Context;
56 using ::v8::Local; 57 using ::v8::Local;
57 using ::v8::String; 58 using ::v8::String;
58 using ::v8::Script; 59 using ::v8::Script;
59 using ::v8::Function; 60 using ::v8::Function;
60 using ::v8::AccessorInfo; 61 using ::v8::AccessorInfo;
61 using ::v8::Extension; 62 using ::v8::Extension;
63 using ::v8::Handle;
64 using ::v8::HandleScope;
65 using ::v8::Undefined;
66 using ::v8::Object;
67 using ::v8::TryCatch;
68 using ::v8::Message;
69 using ::v8::MessageCallback;
70 using ::v8::V8;
71 using ::v8::StackTrace;
72 using ::v8::Arguments;
62 73
63 namespace i = ::i; 74 namespace i = ::i;
64 75
65 76
66 static void ExpectString(const char* code, const char* expected) { 77 static void ExpectString(const char* code, const char* expected) {
67 Local<Value> result = CompileRun(code); 78 Local<Value> result = CompileRun(code);
68 CHECK(result->IsString()); 79 CHECK(result->IsString());
69 String::AsciiValue ascii(result); 80 String::AsciiValue ascii(result);
70 CHECK_EQ(expected, *ascii); 81 CHECK_EQ(expected, *ascii);
71 } 82 }
(...skipping 7921 matching lines...) Expand 10 before | Expand all | Expand 10 after
7993 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 8004 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
7994 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); 8005 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter);
7995 LocalContext env; 8006 LocalContext env;
7996 env->Global()->Set(v8_str("obj"), 8007 env->Global()->Set(v8_str("obj"),
7997 templ->GetFunction()->NewInstance()); 8008 templ->GetFunction()->NewInstance());
7998 ExpectTrue("obj.x === 42"); 8009 ExpectTrue("obj.x === 42");
7999 ExpectTrue("!obj.propertyIsEnumerable('x')"); 8010 ExpectTrue("!obj.propertyIsEnumerable('x')");
8000 } 8011 }
8001 8012
8002 8013
8014 static Handle<Value> ThrowingGetter(Local<String> name,
8015 const AccessorInfo& info) {
8016 ApiTestFuzzer::Fuzz();
8017 ThrowException(Handle<Value>());
8018 return Undefined();
8019 }
8020
8021
8022 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) {
8023 HandleScope scope;
8024 LocalContext context;
8025
8026 Local<FunctionTemplate> templ = FunctionTemplate::New();
8027 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
8028 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter);
8029
8030 Local<Object> instance = templ->GetFunction()->NewInstance();
8031
8032 Local<Object> another = Object::New();
8033 another->SetPrototype(instance);
8034
8035 Local<Object> with_js_getter = CompileRun(
8036 "o = {};\n"
8037 "o.__defineGetter__('f', function() { throw undefined; });\n"
8038 "o\n").As<Object>();
8039 CHECK(!with_js_getter.IsEmpty());
8040
8041 TryCatch try_catch;
8042
8043 Local<Value> result = instance->GetRealNamedProperty(v8_str("f"));
8044 CHECK(try_catch.HasCaught());
8045 try_catch.Reset();
8046 CHECK(result.IsEmpty());
8047
8048 result = another->GetRealNamedProperty(v8_str("f"));
8049 CHECK(try_catch.HasCaught());
8050 try_catch.Reset();
8051 CHECK(result.IsEmpty());
8052
8053 result = another->GetRealNamedPropertyInPrototypeChain(v8_str("f"));
8054 CHECK(try_catch.HasCaught());
8055 try_catch.Reset();
8056 CHECK(result.IsEmpty());
8057
8058 result = another->Get(v8_str("f"));
8059 CHECK(try_catch.HasCaught());
8060 try_catch.Reset();
8061 CHECK(result.IsEmpty());
8062
8063 result = with_js_getter->GetRealNamedProperty(v8_str("f"));
8064 CHECK(try_catch.HasCaught());
8065 try_catch.Reset();
8066 CHECK(result.IsEmpty());
8067
8068 result = with_js_getter->Get(v8_str("f"));
8069 CHECK(try_catch.HasCaught());
8070 try_catch.Reset();
8071 CHECK(result.IsEmpty());
8072 }
8073
8074
8075 static Handle<Value> ThrowingCallbackWithTryCatch(const Arguments& args) {
8076 TryCatch try_catch;
8077 // Verboseness is important: it triggers message delivery which can call into
8078 // external code.
8079 try_catch.SetVerbose(true);
8080 CompileRun("throw 'from JS';");
8081 CHECK(try_catch.HasCaught());
8082 CHECK(!i::Top::has_pending_exception());
8083 CHECK(!i::Top::has_scheduled_exception());
8084 return Undefined();
8085 }
8086
8087
8088 static void WithTryCatch(Handle<Message> message, Handle<Value> data) {
8089 TryCatch try_catch;
8090 }
8091
8092
8093 static void ThrowFromJS(Handle<Message> message, Handle<Value> data) {
8094 CompileRun("throw 'ThrowInJS';");
8095 }
8096
8097
8098 static void ThrowViaApi(Handle<Message> message, Handle<Value> data) {
8099 ThrowException(v8_str("ThrowViaApi"));
8100 }
8101
8102
8103 static void WebKitLike(Handle<Message> message, Handle<Value> data) {
8104 Handle<String> errorMessageString = message->Get();
8105 CHECK(!errorMessageString.IsEmpty());
8106 message->GetStackTrace();
8107 message->GetScriptResourceName();
8108 }
8109
8110 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) {
8111 HandleScope scope;
8112 LocalContext context;
8113
8114 Local<Function> func =
8115 FunctionTemplate::New(ThrowingCallbackWithTryCatch)->GetFunction();
8116 context->Global()->Set(v8_str("func"), func);
8117
8118 MessageCallback callbacks[] =
8119 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch };
8120 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) {
8121 MessageCallback callback = callbacks[i];
8122 if (callback != NULL) {
8123 V8::AddMessageListener(callback);
8124 }
8125 ExpectFalse(
8126 "var thrown = false;\n"
8127 "try { func(); } catch(e) { thrown = true; }\n"
8128 "thrown\n");
8129 if (callback != NULL) {
8130 V8::RemoveMessageListeners(callback);
8131 }
8132 }
8133 }
8134
8135
8003 static v8::Handle<Value> ParentGetter(Local<String> name, 8136 static v8::Handle<Value> ParentGetter(Local<String> name,
8004 const AccessorInfo& info) { 8137 const AccessorInfo& info) {
8005 ApiTestFuzzer::Fuzz(); 8138 ApiTestFuzzer::Fuzz();
8006 return v8_num(1); 8139 return v8_num(1);
8007 } 8140 }
8008 8141
8009 8142
8010 static v8::Handle<Value> ChildGetter(Local<String> name, 8143 static v8::Handle<Value> ChildGetter(Local<String> name,
8011 const AccessorInfo& info) { 8144 const AccessorInfo& info) {
8012 ApiTestFuzzer::Fuzz(); 8145 ApiTestFuzzer::Fuzz();
(...skipping 4238 matching lines...) Expand 10 before | Expand all | Expand 10 after
12251 v8::Context::Scope context_scope(context.local()); 12384 v8::Context::Scope context_scope(context.local());
12252 12385
12253 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 12386 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New();
12254 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 12387 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
12255 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 12388 context->Global()->Set(v8_str("o"), tmpl->NewInstance());
12256 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 12389 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
12257 "var result = []; for (var k in o) result.push(k); result")); 12390 "var result = []; for (var k in o) result.push(k); result"));
12258 CHECK_EQ(1, result->Length()); 12391 CHECK_EQ(1, result->Length());
12259 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); 12392 CHECK_EQ(v8_str("universalAnswer"), result->Get(0));
12260 } 12393 }
OLDNEW
« no previous file with comments | « src/top.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698