OLD | NEW |
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 2270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2281 " try {" | 2281 " try {" |
2282 " CCatcher('throw 7;');" | 2282 " CCatcher('throw 7;');" |
2283 " } finally {" | 2283 " } finally {" |
2284 " }" | 2284 " }" |
2285 "} catch (e) {" | 2285 "} catch (e) {" |
2286 "}"); | 2286 "}"); |
2287 CHECK(result->IsTrue()); | 2287 CHECK(result->IsTrue()); |
2288 } | 2288 } |
2289 | 2289 |
2290 | 2290 |
| 2291 static void check_reference_error_message( |
| 2292 v8::Handle<v8::Message> message, |
| 2293 v8::Handle<v8::Value> data) { |
| 2294 const char* reference_error = "Uncaught ReferenceError: asdf is not defined"; |
| 2295 CHECK(message->Get()->Equals(v8_str(reference_error))); |
| 2296 } |
| 2297 |
| 2298 |
| 2299 // Test that overwritten toString methods are not invoked on uncaught |
| 2300 // exception formatting. However, they are invoked when performing |
| 2301 // normal error string conversions. |
| 2302 THREADED_TEST(APIThrowMessageOverwrittenToString) { |
| 2303 v8::HandleScope scope; |
| 2304 v8::V8::AddMessageListener(check_reference_error_message); |
| 2305 LocalContext context; |
| 2306 CompileRun("ReferenceError.prototype.toString =" |
| 2307 " function() { return 'Whoops' }"); |
| 2308 CompileRun("asdf;"); |
| 2309 v8::Handle<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }"); |
| 2310 CHECK(string->Equals(v8_str("Whoops"))); |
| 2311 v8::V8::RemoveMessageListeners(check_message); |
| 2312 } |
| 2313 |
| 2314 |
2291 static void receive_message(v8::Handle<v8::Message> message, | 2315 static void receive_message(v8::Handle<v8::Message> message, |
2292 v8::Handle<v8::Value> data) { | 2316 v8::Handle<v8::Value> data) { |
2293 message->Get(); | 2317 message->Get(); |
2294 message_received = true; | 2318 message_received = true; |
2295 } | 2319 } |
2296 | 2320 |
2297 | 2321 |
2298 TEST(APIThrowMessage) { | 2322 TEST(APIThrowMessage) { |
2299 message_received = false; | 2323 message_received = false; |
2300 v8::HandleScope scope; | 2324 v8::HandleScope scope; |
(...skipping 9772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12073 v8::Context::Scope context_scope(context.local()); | 12097 v8::Context::Scope context_scope(context.local()); |
12074 | 12098 |
12075 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); | 12099 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); |
12076 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 12100 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); |
12077 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 12101 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
12078 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 12102 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
12079 "var result = []; for (var k in o) result.push(k); result")); | 12103 "var result = []; for (var k in o) result.push(k); result")); |
12080 CHECK_EQ(1, result->Length()); | 12104 CHECK_EQ(1, result->Length()); |
12081 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 12105 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
12082 } | 12106 } |
OLD | NEW |