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_tostring( | 4391 static void check_custom_error_message( |
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_tostring); | 4402 v8::V8::AddMessageListener(check_custom_error_message); |
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 | |
4465 v8::V8::RemoveMessageListeners(check_custom_error_message); | 4413 v8::V8::RemoveMessageListeners(check_custom_error_message); |
4466 } | 4414 } |
4467 | 4415 |
4468 | 4416 |
4469 static void receive_message(v8::Handle<v8::Message> message, | 4417 static void receive_message(v8::Handle<v8::Message> message, |
4470 v8::Handle<v8::Value> data) { | 4418 v8::Handle<v8::Value> data) { |
4471 message->Get(); | 4419 message->Get(); |
4472 message_received = true; | 4420 message_received = true; |
4473 } | 4421 } |
4474 | 4422 |
(...skipping 15433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19908 LocalContext context; | 19856 LocalContext context; |
19909 v8::HandleScope scope(context->GetIsolate()); | 19857 v8::HandleScope scope(context->GetIsolate()); |
19910 Local<FunctionTemplate> templ = FunctionTemplate::New(DummyCallHandler); | 19858 Local<FunctionTemplate> templ = FunctionTemplate::New(DummyCallHandler); |
19911 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;"); | 19859 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;"); |
19912 Local<Function> function = templ->GetFunction(); | 19860 Local<Function> function = templ->GetFunction(); |
19913 CHECK(!function.IsEmpty()); | 19861 CHECK(!function.IsEmpty()); |
19914 CHECK(function->IsFunction()); | 19862 CHECK(function->IsFunction()); |
19915 } | 19863 } |
19916 | 19864 |
19917 | 19865 |
19918 THREADED_TEST(JSONParse) { | |
19919 LocalContext context; | |
19920 HandleScope scope(context->GetIsolate()); | |
19921 Local<Object> obj = v8::JSON::Parse(v8_str("{\"x\":42}")); | |
19922 Handle<Object> global = context->Global(); | |
19923 global->Set(v8_str("obj"), obj); | |
19924 ExpectString("JSON.stringify(obj)", "{\"x\":42}"); | |
19925 } | |
19926 | |
19927 | |
19928 #ifndef WIN32 | 19866 #ifndef WIN32 |
19929 class ThreadInterruptTest { | 19867 class ThreadInterruptTest { |
19930 public: | 19868 public: |
19931 ThreadInterruptTest() : sem_(NULL), sem_value_(0) { } | 19869 ThreadInterruptTest() : sem_(NULL), sem_value_(0) { } |
19932 ~ThreadInterruptTest() { delete sem_; } | 19870 ~ThreadInterruptTest() { delete sem_; } |
19933 | 19871 |
19934 void RunTest() { | 19872 void RunTest() { |
19935 sem_ = i::OS::CreateSemaphore(0); | 19873 sem_ = i::OS::CreateSemaphore(0); |
19936 | 19874 |
19937 InterruptThread i_thread(this); | 19875 InterruptThread i_thread(this); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20157 CheckCorrectThrow("%HasProperty(other, 'x')"); | 20095 CheckCorrectThrow("%HasProperty(other, 'x')"); |
20158 CheckCorrectThrow("%HasElement(other, 1)"); | 20096 CheckCorrectThrow("%HasElement(other, 1)"); |
20159 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); | 20097 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); |
20160 CheckCorrectThrow("%GetPropertyNames(other)"); | 20098 CheckCorrectThrow("%GetPropertyNames(other)"); |
20161 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); | 20099 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); |
20162 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" | 20100 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" |
20163 "other, 'x', null, null, 1)"); | 20101 "other, 'x', null, null, 1)"); |
20164 } | 20102 } |
20165 | 20103 |
20166 #endif // WIN32 | 20104 #endif // WIN32 |
OLD | NEW |