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

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

Issue 1510173002: Revert of Make Error.prototype.toString spec compliant; and fix various side-effect-free error printing metho… (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | test/mjsunit/error-constructors.js » ('j') | 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 5594 matching lines...) Expand 10 before | Expand all | Expand 10 after
5605 "ReferenceError.prototype.constructor.name = 1;" 5605 "ReferenceError.prototype.constructor.name = 1;"
5606 "Number.prototype.toString = function() { return 'Whoops'; };" 5606 "Number.prototype.toString = function() { return 'Whoops'; };"
5607 "ReferenceError.prototype.toString = Object.prototype.toString;"); 5607 "ReferenceError.prototype.toString = Object.prototype.toString;");
5608 CompileRun("asdf;"); 5608 CompileRun("asdf;");
5609 isolate->RemoveMessageListeners(check_reference_error_message); 5609 isolate->RemoveMessageListeners(check_reference_error_message);
5610 } 5610 }
5611 5611
5612 5612
5613 static void check_custom_error_tostring(v8::Local<v8::Message> message, 5613 static void check_custom_error_tostring(v8::Local<v8::Message> message,
5614 v8::Local<v8::Value> data) { 5614 v8::Local<v8::Value> data) {
5615 const char* uncaught_error = "Uncaught my name: my message"; 5615 const char* uncaught_error = "Uncaught MyError toString";
5616 CHECK(message->Get() 5616 CHECK(message->Get()
5617 ->Equals(CcTest::isolate()->GetCurrentContext(), 5617 ->Equals(CcTest::isolate()->GetCurrentContext(),
5618 v8_str(uncaught_error)) 5618 v8_str(uncaught_error))
5619 .FromJust()); 5619 .FromJust());
5620 } 5620 }
5621 5621
5622 5622
5623 TEST(CustomErrorToString) { 5623 TEST(CustomErrorToString) {
5624 LocalContext context; 5624 LocalContext context;
5625 v8::HandleScope scope(context->GetIsolate()); 5625 v8::HandleScope scope(context->GetIsolate());
5626 context->GetIsolate()->AddMessageListener(check_custom_error_tostring); 5626 context->GetIsolate()->AddMessageListener(check_custom_error_tostring);
5627 CompileRun( 5627 CompileRun(
5628 "function MyError(name, message) { " 5628 "function MyError(name, message) { "
5629 " this.name = name; " 5629 " this.name = name; "
5630 " this.message = message; " 5630 " this.message = message; "
5631 "} " 5631 "} "
5632 "MyError.prototype = Object.create(Error.prototype); " 5632 "MyError.prototype = Object.create(Error.prototype); "
5633 "MyError.prototype.toString = function() { "
5634 " return 'MyError toString'; "
5635 "}; "
5633 "throw new MyError('my name', 'my message'); "); 5636 "throw new MyError('my name', 'my message'); ");
5634 context->GetIsolate()->RemoveMessageListeners(check_custom_error_tostring); 5637 context->GetIsolate()->RemoveMessageListeners(check_custom_error_tostring);
5635 } 5638 }
5636 5639
5637 5640
5638 static void check_custom_error_message(v8::Local<v8::Message> message, 5641 static void check_custom_error_message(v8::Local<v8::Message> message,
5639 v8::Local<v8::Value> data) { 5642 v8::Local<v8::Value> data) {
5640 const char* uncaught_error = "Uncaught MyError: my message"; 5643 const char* uncaught_error = "Uncaught MyError: my message";
5641 printf("%s\n", *v8::String::Utf8Value(message->Get())); 5644 printf("%s\n", *v8::String::Utf8Value(message->Get()));
5642 CHECK(message->Get() 5645 CHECK(message->Get()
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
5684 "} " 5687 "} "
5685 "MyError.prototype = Object.create(Error.prototype); " 5688 "MyError.prototype = Object.create(Error.prototype); "
5686 "throw new MyError('my message'); "); 5689 "throw new MyError('my message'); ");
5687 5690
5688 context->GetIsolate()->RemoveMessageListeners(check_custom_error_message); 5691 context->GetIsolate()->RemoveMessageListeners(check_custom_error_message);
5689 } 5692 }
5690 5693
5691 5694
5692 static void check_custom_rethrowing_message(v8::Local<v8::Message> message, 5695 static void check_custom_rethrowing_message(v8::Local<v8::Message> message,
5693 v8::Local<v8::Value> data) { 5696 v8::Local<v8::Value> data) {
5694 const char* uncaught_error = "Uncaught [object Object]"; 5697 const char* uncaught_error = "Uncaught exception";
5695 CHECK(message->Get() 5698 CHECK(message->Get()
5696 ->Equals(CcTest::isolate()->GetCurrentContext(), 5699 ->Equals(CcTest::isolate()->GetCurrentContext(),
5697 v8_str(uncaught_error)) 5700 v8_str(uncaught_error))
5698 .FromJust()); 5701 .FromJust());
5699 } 5702 }
5700 5703
5701 5704
5702 TEST(CustomErrorRethrowsOnToString) { 5705 TEST(CustomErrorRethrowsOnToString) {
5703 LocalContext context; 5706 LocalContext context;
5704 v8::HandleScope scope(context->GetIsolate()); 5707 v8::HandleScope scope(context->GetIsolate());
(...skipping 18117 matching lines...) Expand 10 before | Expand all | Expand 10 after
23822 env2->Global()->Set(env2.local(), v8_str("obj2"), object2).FromJust()); 23825 env2->Global()->Set(env2.local(), v8_str("obj2"), object2).FromJust());
23823 ExpectString("typeof obj2.values", "function"); 23826 ExpectString("typeof obj2.values", "function");
23824 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); 23827 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values")));
23825 23828
23826 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); 23829 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values")));
23827 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); 23830 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2));
23828 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); 23831 auto ctx2 = v8::Utils::OpenHandle(*env2.local());
23829 CHECK_EQ(fn2->GetCreationContext(), *ctx2); 23832 CHECK_EQ(fn2->GetCreationContext(), *ctx2);
23830 } 23833 }
23831 } 23834 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | test/mjsunit/error-constructors.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698