 Chromium Code Reviews
 Chromium Code Reviews Issue 12901:
  Reporting uncaught errors at the boundary between C++ and JS instead of tryin...  (Closed) 
  Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
    
  
    Issue 12901:
  Reporting uncaught errors at the boundary between C++ and JS instead of tryin...  (Closed) 
  Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/| OLD | NEW | 
|---|---|
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 2942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2953 static int report_count = 0; | 2953 static int report_count = 0; | 
| 2954 static void ApiUncaughtExceptionTestListener(v8::Handle<v8::Message>, | 2954 static void ApiUncaughtExceptionTestListener(v8::Handle<v8::Message>, | 
| 2955 v8::Handle<Value>) { | 2955 v8::Handle<Value>) { | 
| 2956 report_count++; | 2956 report_count++; | 
| 2957 } | 2957 } | 
| 2958 | 2958 | 
| 2959 | 2959 | 
| 2960 // Counts uncaught exceptions, but other tests running in parallel | 2960 // Counts uncaught exceptions, but other tests running in parallel | 
| 2961 // also have uncaught exceptions. | 2961 // also have uncaught exceptions. | 
| 2962 TEST(ApiUncaughtException) { | 2962 TEST(ApiUncaughtException) { | 
| 2963 report_count = 0; | |
| 2963 v8::HandleScope scope; | 2964 v8::HandleScope scope; | 
| 2964 LocalContext env; | 2965 LocalContext env; | 
| 2965 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); | 2966 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); | 
| 2966 | 2967 | 
| 2967 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); | 2968 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); | 
| 2968 v8::Local<v8::Object> global = env->Global(); | 2969 v8::Local<v8::Object> global = env->Global(); | 
| 2969 global->Set(v8_str("trouble"), fun->GetFunction()); | 2970 global->Set(v8_str("trouble"), fun->GetFunction()); | 
| 2970 | 2971 | 
| 2971 Script::Compile(v8_str("function trouble_callee() {" | 2972 Script::Compile(v8_str("function trouble_callee() {" | 
| 2972 " var x = null;" | 2973 " var x = null;" | 
| 2973 " return x.foo;" | 2974 " return x.foo;" | 
| 2974 "};" | 2975 "};" | 
| 2975 "function trouble_caller() {" | 2976 "function trouble_caller() {" | 
| 2976 " trouble();" | 2977 " trouble();" | 
| 2977 "};"))->Run(); | 2978 "};"))->Run(); | 
| 2978 Local<Value> trouble = global->Get(v8_str("trouble")); | 2979 Local<Value> trouble = global->Get(v8_str("trouble")); | 
| 2979 CHECK(trouble->IsFunction()); | 2980 CHECK(trouble->IsFunction()); | 
| 2980 Local<Value> trouble_callee = global->Get(v8_str("trouble_callee")); | 2981 Local<Value> trouble_callee = global->Get(v8_str("trouble_callee")); | 
| 2981 CHECK(trouble_callee->IsFunction()); | 2982 CHECK(trouble_callee->IsFunction()); | 
| 2982 Local<Value> trouble_caller = global->Get(v8_str("trouble_caller")); | 2983 Local<Value> trouble_caller = global->Get(v8_str("trouble_caller")); | 
| 2983 CHECK(trouble_caller->IsFunction()); | 2984 CHECK(trouble_caller->IsFunction()); | 
| 2984 Function::Cast(*trouble_caller)->Call(global, 0, NULL); | 2985 Function::Cast(*trouble_caller)->Call(global, 0, NULL); | 
| 2985 CHECK_EQ(1, report_count); | 2986 CHECK_EQ(1, report_count); | 
| 2987 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); | |
| 2988 } | |
| 2989 | |
| 2990 | |
| 2991 TEST(TryCatchFinallyUsingMessaging) { | |
| 
Søren Thygesen Gjesse
2008/12/04 07:53:53
I suggest to change this test into one or more mes
 
olehougaard
2008/12/04 08:44:35
Fixed.
 | |
| 2992 report_count = 0; | |
| 2993 v8::HandleScope scope; | |
| 2994 LocalContext env; | |
| 2995 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); | |
| 2996 Script::Compile(v8_str("try { throw ''; } catch (e) {}"))->Run(); | |
| 2997 CHECK_EQ(0, report_count); | |
| 2998 Script::Compile(v8_str("try { throw ''; } finally {}"))->Run(); | |
| 2999 CHECK_EQ(1, report_count); | |
| 3000 Script::Compile(v8_str("(function() { try { throw ''; } finally { return; } }) ()"))->Run(); | |
| 
Mads Ager (chromium)
2008/12/03 15:44:48
These two lines seem too long?  Break them by usin
 
olehougaard
2008/12/04 08:44:35
Fixed
 | |
| 3001 CHECK_EQ(1, report_count); | |
| 3002 Script::Compile(v8_str("(function() { try { throw ''; } finally { throw 0; } } )()"))->Run(); | |
| 3003 CHECK_EQ(2, report_count); | |
| 3004 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); | |
| 3005 } | |
| 3006 | |
| 3007 | |
| 3008 TEST(TryCatchFinallyUsingTryCatchHandler) { | |
| 3009 v8::HandleScope scope; | |
| 3010 LocalContext env; | |
| 3011 v8::TryCatch try_catch; | |
| 3012 Script::Compile(v8_str("try { throw ''; } catch (e) {}"))->Run(); | |
| 3013 CHECK(!try_catch.HasCaught()); | |
| 3014 Script::Compile(v8_str("try { throw ''; } finally {}"))->Run(); | |
| 3015 CHECK(try_catch.HasCaught()); | |
| 3016 try_catch.Reset(); | |
| 3017 Script::Compile(v8_str("(function() { try { throw ''; } finally { return; } }) ()"))->Run(); | |
| 3018 CHECK(!try_catch.HasCaught()); | |
| 3019 Script::Compile(v8_str("(function() { try { throw ''; } finally { throw 0; } } )()"))->Run(); | |
| 3020 CHECK(try_catch.HasCaught()); | |
| 2986 } | 3021 } | 
| 2987 | 3022 | 
| 2988 | 3023 | 
| 2989 // SecurityHandler can't be run twice | 3024 // SecurityHandler can't be run twice | 
| 2990 TEST(SecurityHandler) { | 3025 TEST(SecurityHandler) { | 
| 2991 v8::HandleScope scope0; | 3026 v8::HandleScope scope0; | 
| 2992 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 3027 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 
| 2993 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, | 3028 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, | 
| 2994 IndexedSecurityTestCallback); | 3029 IndexedSecurityTestCallback); | 
| 2995 // Create an environment | 3030 // Create an environment | 
| (...skipping 2356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5352 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); | 5387 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); | 
| 5353 } | 5388 } | 
| 5354 // Test CallIC. | 5389 // Test CallIC. | 
| 5355 for (int i = 0; i < 2; i++) { | 5390 for (int i = 0; i < 2; i++) { | 
| 5356 LocalContext context; | 5391 LocalContext context; | 
| 5357 context->Global()->Set(v8_str("tmp"), v8::True()); | 5392 context->Global()->Set(v8_str("tmp"), v8::True()); | 
| 5358 context->Global()->Delete(v8_str("tmp")); | 5393 context->Global()->Delete(v8_str("tmp")); | 
| 5359 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); | 5394 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); | 
| 5360 } | 5395 } | 
| 5361 } | 5396 } | 
| OLD | NEW |