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

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

Issue 1507273002: 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
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 MyError toString"; 5615 const char* uncaught_error = "Uncaught my name: my message";
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 "}; "
5636 "throw new MyError('my name', 'my message'); "); 5633 "throw new MyError('my name', 'my message'); ");
5637 context->GetIsolate()->RemoveMessageListeners(check_custom_error_tostring); 5634 context->GetIsolate()->RemoveMessageListeners(check_custom_error_tostring);
5638 } 5635 }
5639 5636
5640 5637
5641 static void check_custom_error_message(v8::Local<v8::Message> message, 5638 static void check_custom_error_message(v8::Local<v8::Message> message,
5642 v8::Local<v8::Value> data) { 5639 v8::Local<v8::Value> data) {
5643 const char* uncaught_error = "Uncaught MyError: my message"; 5640 const char* uncaught_error = "Uncaught MyError: my message";
5644 printf("%s\n", *v8::String::Utf8Value(message->Get())); 5641 printf("%s\n", *v8::String::Utf8Value(message->Get()));
5645 CHECK(message->Get() 5642 CHECK(message->Get()
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
5687 "} " 5684 "} "
5688 "MyError.prototype = Object.create(Error.prototype); " 5685 "MyError.prototype = Object.create(Error.prototype); "
5689 "throw new MyError('my message'); "); 5686 "throw new MyError('my message'); ");
5690 5687
5691 context->GetIsolate()->RemoveMessageListeners(check_custom_error_message); 5688 context->GetIsolate()->RemoveMessageListeners(check_custom_error_message);
5692 } 5689 }
5693 5690
5694 5691
5695 static void check_custom_rethrowing_message(v8::Local<v8::Message> message, 5692 static void check_custom_rethrowing_message(v8::Local<v8::Message> message,
5696 v8::Local<v8::Value> data) { 5693 v8::Local<v8::Value> data) {
5697 const char* uncaught_error = "Uncaught exception"; 5694 const char* uncaught_error = "Uncaught [object Object]";
5698 CHECK(message->Get() 5695 CHECK(message->Get()
5699 ->Equals(CcTest::isolate()->GetCurrentContext(), 5696 ->Equals(CcTest::isolate()->GetCurrentContext(),
5700 v8_str(uncaught_error)) 5697 v8_str(uncaught_error))
5701 .FromJust()); 5698 .FromJust());
5702 } 5699 }
5703 5700
5704 5701
5705 TEST(CustomErrorRethrowsOnToString) { 5702 TEST(CustomErrorRethrowsOnToString) {
5706 LocalContext context; 5703 LocalContext context;
5707 v8::HandleScope scope(context->GetIsolate()); 5704 v8::HandleScope scope(context->GetIsolate());
(...skipping 18117 matching lines...) Expand 10 before | Expand all | Expand 10 after
23825 env2->Global()->Set(env2.local(), v8_str("obj2"), object2).FromJust()); 23822 env2->Global()->Set(env2.local(), v8_str("obj2"), object2).FromJust());
23826 ExpectString("typeof obj2.values", "function"); 23823 ExpectString("typeof obj2.values", "function");
23827 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); 23824 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values")));
23828 23825
23829 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); 23826 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values")));
23830 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); 23827 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2));
23831 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); 23828 auto ctx2 = v8::Utils::OpenHandle(*env2.local());
23832 CHECK_EQ(fn2->GetCreationContext(), *ctx2); 23829 CHECK_EQ(fn2->GetCreationContext(), *ctx2);
23833 } 23830 }
23834 } 23831 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698