OLD | NEW |
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 5535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5546 " try {" | 5546 " try {" |
5547 " CCatcher('throw 7;');" | 5547 " CCatcher('throw 7;');" |
5548 " } finally {" | 5548 " } finally {" |
5549 " }" | 5549 " }" |
5550 "} catch (e) {" | 5550 "} catch (e) {" |
5551 "}"); | 5551 "}"); |
5552 CHECK(result->IsTrue()); | 5552 CHECK(result->IsTrue()); |
5553 } | 5553 } |
5554 | 5554 |
5555 | 5555 |
5556 static void check_reference_error_message(v8::Local<v8::Message> message, | |
5557 v8::Local<v8::Value> data) { | |
5558 const char* reference_error = "Uncaught ReferenceError: asdf is not defined"; | |
5559 Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); | |
5560 const char* reference_error2 = "Uncaught Error: asdf is not defined"; | |
5561 CHECK(message->Get()->Equals(context, v8_str(reference_error)).FromJust() || | |
5562 message->Get()->Equals(context, v8_str(reference_error2)).FromJust()); | |
5563 } | |
5564 | |
5565 | |
5566 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
5567 ApiTestFuzzer::Fuzz(); | |
5568 CHECK(false); | |
5569 } | |
5570 | |
5571 | |
5572 // Test that overwritten methods are not invoked on uncaught exception | |
5573 // formatting. However, they are invoked when performing normal error | |
5574 // string conversions. | |
5575 TEST(APIThrowMessageOverwrittenToString) { | |
5576 v8::Isolate* isolate = CcTest::isolate(); | |
5577 v8::HandleScope scope(isolate); | |
5578 isolate->AddMessageListener(check_reference_error_message); | |
5579 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | |
5580 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail)); | |
5581 LocalContext context(NULL, templ); | |
5582 CompileRun("asdf;"); | |
5583 CompileRun( | |
5584 "var limit = {};" | |
5585 "limit.valueOf = fail;" | |
5586 "Error.stackTraceLimit = limit;"); | |
5587 CompileRun("asdf"); | |
5588 CompileRun("Array.prototype.pop = fail;"); | |
5589 CompileRun("Object.prototype.hasOwnProperty = fail;"); | |
5590 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }"); | |
5591 CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }"); | |
5592 CompileRun("String.prototype.toString = function f() { return 'Yikes'; }"); | |
5593 CompileRun( | |
5594 "ReferenceError.prototype.toString =" | |
5595 " function() { return 'Whoops' }"); | |
5596 CompileRun("asdf;"); | |
5597 CompileRun("ReferenceError.prototype.constructor.name = void 0;"); | |
5598 CompileRun("asdf;"); | |
5599 CompileRun("ReferenceError.prototype.constructor = void 0;"); | |
5600 CompileRun("asdf;"); | |
5601 CompileRun("ReferenceError.prototype.__proto__ = new Object();"); | |
5602 CompileRun("asdf;"); | |
5603 CompileRun("ReferenceError.prototype = new Object();"); | |
5604 CompileRun("asdf;"); | |
5605 v8::Local<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }"); | |
5606 CHECK(string->Equals(context.local(), v8_str("Whoops")).FromJust()); | |
5607 CompileRun( | |
5608 "ReferenceError.prototype.constructor = new Object();" | |
5609 "ReferenceError.prototype.constructor.name = 1;" | |
5610 "Number.prototype.toString = function() { return 'Whoops'; };" | |
5611 "ReferenceError.prototype.toString = Object.prototype.toString;"); | |
5612 CompileRun("asdf;"); | |
5613 isolate->RemoveMessageListeners(check_reference_error_message); | |
5614 } | |
5615 | |
5616 | |
5617 static void check_custom_error_tostring(v8::Local<v8::Message> message, | 5556 static void check_custom_error_tostring(v8::Local<v8::Message> message, |
5618 v8::Local<v8::Value> data) { | 5557 v8::Local<v8::Value> data) { |
5619 const char* uncaught_error = "Uncaught MyError toString"; | 5558 const char* uncaught_error = "Uncaught MyError toString"; |
5620 CHECK(message->Get() | 5559 CHECK(message->Get() |
5621 ->Equals(CcTest::isolate()->GetCurrentContext(), | 5560 ->Equals(CcTest::isolate()->GetCurrentContext(), |
5622 v8_str(uncaught_error)) | 5561 v8_str(uncaught_error)) |
5623 .FromJust()); | 5562 .FromJust()); |
5624 } | 5563 } |
5625 | 5564 |
5626 | 5565 |
(...skipping 18202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23829 env2->Global()->Set(env2.local(), v8_str("obj2"), object2).FromJust()); | 23768 env2->Global()->Set(env2.local(), v8_str("obj2"), object2).FromJust()); |
23830 ExpectString("typeof obj2.values", "function"); | 23769 ExpectString("typeof obj2.values", "function"); |
23831 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); | 23770 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); |
23832 | 23771 |
23833 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); | 23772 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); |
23834 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); | 23773 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); |
23835 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); | 23774 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); |
23836 CHECK_EQ(fn2->GetCreationContext(), *ctx2); | 23775 CHECK_EQ(fn2->GetCreationContext(), *ctx2); |
23837 } | 23776 } |
23838 } | 23777 } |
OLD | NEW |