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 4370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4381 CHECK(string->Equals(v8_str("Whoops"))); | 4381 CHECK(string->Equals(v8_str("Whoops"))); |
4382 CompileRun("ReferenceError.prototype.constructor = new Object();" | 4382 CompileRun("ReferenceError.prototype.constructor = new Object();" |
4383 "ReferenceError.prototype.constructor.name = 1;" | 4383 "ReferenceError.prototype.constructor.name = 1;" |
4384 "Number.prototype.toString = function() { return 'Whoops'; };" | 4384 "Number.prototype.toString = function() { return 'Whoops'; };" |
4385 "ReferenceError.prototype.toString = Object.prototype.toString;"); | 4385 "ReferenceError.prototype.toString = Object.prototype.toString;"); |
4386 CompileRun("asdf;"); | 4386 CompileRun("asdf;"); |
4387 v8::V8::RemoveMessageListeners(check_reference_error_message); | 4387 v8::V8::RemoveMessageListeners(check_reference_error_message); |
4388 } | 4388 } |
4389 | 4389 |
4390 | 4390 |
4391 static void check_custom_error_message( | 4391 static void check_custom_error_tostring( |
4392 v8::Handle<v8::Message> message, | 4392 v8::Handle<v8::Message> message, |
4393 v8::Handle<v8::Value> data) { | 4393 v8::Handle<v8::Value> data) { |
4394 const char* uncaught_error = "Uncaught MyError toString"; | 4394 const char* uncaught_error = "Uncaught MyError toString"; |
4395 CHECK(message->Get()->Equals(v8_str(uncaught_error))); | 4395 CHECK(message->Get()->Equals(v8_str(uncaught_error))); |
4396 } | 4396 } |
4397 | 4397 |
4398 | 4398 |
4399 TEST(CustomErrorToString) { | 4399 TEST(CustomErrorToString) { |
4400 LocalContext context; | 4400 LocalContext context; |
4401 v8::HandleScope scope(context->GetIsolate()); | 4401 v8::HandleScope scope(context->GetIsolate()); |
4402 v8::V8::AddMessageListener(check_custom_error_message); | 4402 v8::V8::AddMessageListener(check_custom_error_tostring); |
4403 CompileRun( | 4403 CompileRun( |
4404 "function MyError(name, message) { " | 4404 "function MyError(name, message) { " |
4405 " this.name = name; " | 4405 " this.name = name; " |
4406 " this.message = message; " | 4406 " this.message = message; " |
4407 "} " | 4407 "} " |
4408 "MyError.prototype = Object.create(Error.prototype); " | 4408 "MyError.prototype = Object.create(Error.prototype); " |
4409 "MyError.prototype.toString = function() { " | 4409 "MyError.prototype.toString = function() { " |
4410 " return 'MyError toString'; " | 4410 " return 'MyError toString'; " |
4411 "}; " | 4411 "}; " |
4412 "throw new MyError('my name', 'my message'); "); | 4412 "throw new MyError('my name', 'my message'); "); |
| 4413 v8::V8::RemoveMessageListeners(check_custom_error_tostring); |
| 4414 } |
| 4415 |
| 4416 |
| 4417 static void check_custom_error_message( |
| 4418 v8::Handle<v8::Message> message, |
| 4419 v8::Handle<v8::Value> data) { |
| 4420 const char* uncaught_error = "Uncaught MyError: my message"; |
| 4421 printf("%s\n", *v8::String::Utf8Value(message->Get())); |
| 4422 CHECK(message->Get()->Equals(v8_str(uncaught_error))); |
| 4423 } |
| 4424 |
| 4425 |
| 4426 TEST(CustomErrorMessage) { |
| 4427 LocalContext context; |
| 4428 v8::HandleScope scope(context->GetIsolate()); |
| 4429 v8::V8::AddMessageListener(check_custom_error_message); |
| 4430 |
| 4431 // Handlebars. |
| 4432 CompileRun( |
| 4433 "function MyError(msg) { " |
| 4434 " this.name = 'MyError'; " |
| 4435 " this.message = msg; " |
| 4436 "} " |
| 4437 "MyError.prototype = new Error(); " |
| 4438 "throw new MyError('my message'); "); |
| 4439 |
| 4440 // Closure. |
| 4441 CompileRun( |
| 4442 "function MyError(msg) { " |
| 4443 " this.name = 'MyError'; " |
| 4444 " this.message = msg; " |
| 4445 "} " |
| 4446 "inherits = function(childCtor, parentCtor) { " |
| 4447 " function tempCtor() {}; " |
| 4448 " tempCtor.prototype = parentCtor.prototype; " |
| 4449 " childCtor.superClass_ = parentCtor.prototype; " |
| 4450 " childCtor.prototype = new tempCtor(); " |
| 4451 " childCtor.prototype.constructor = childCtor; " |
| 4452 "}; " |
| 4453 "inherits(MyError, Error); " |
| 4454 "throw new MyError('my message'); "); |
| 4455 |
| 4456 // Object.create. |
| 4457 CompileRun( |
| 4458 "function MyError(msg) { " |
| 4459 " this.name = 'MyError'; " |
| 4460 " this.message = msg; " |
| 4461 "} " |
| 4462 "MyError.prototype = Object.create(Error.prototype); " |
| 4463 "throw new MyError('my message'); "); |
| 4464 |
4413 v8::V8::RemoveMessageListeners(check_custom_error_message); | 4465 v8::V8::RemoveMessageListeners(check_custom_error_message); |
4414 } | 4466 } |
4415 | 4467 |
4416 | 4468 |
4417 static void receive_message(v8::Handle<v8::Message> message, | 4469 static void receive_message(v8::Handle<v8::Message> message, |
4418 v8::Handle<v8::Value> data) { | 4470 v8::Handle<v8::Value> data) { |
4419 message->Get(); | 4471 message->Get(); |
4420 message_received = true; | 4472 message_received = true; |
4421 } | 4473 } |
4422 | 4474 |
(...skipping 15672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20095 CheckCorrectThrow("%HasProperty(other, 'x')"); | 20147 CheckCorrectThrow("%HasProperty(other, 'x')"); |
20096 CheckCorrectThrow("%HasElement(other, 1)"); | 20148 CheckCorrectThrow("%HasElement(other, 1)"); |
20097 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); | 20149 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); |
20098 CheckCorrectThrow("%GetPropertyNames(other)"); | 20150 CheckCorrectThrow("%GetPropertyNames(other)"); |
20099 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); | 20151 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); |
20100 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" | 20152 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" |
20101 "other, 'x', null, null, 1)"); | 20153 "other, 'x', null, null, 1)"); |
20102 } | 20154 } |
20103 | 20155 |
20104 #endif // WIN32 | 20156 #endif // WIN32 |
OLD | NEW |