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 3493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3504 | 3504 |
3505 | 3505 |
3506 bool message_received; | 3506 bool message_received; |
3507 | 3507 |
3508 | 3508 |
3509 static void check_message_0(v8::Handle<v8::Message> message, | 3509 static void check_message_0(v8::Handle<v8::Message> message, |
3510 v8::Handle<Value> data) { | 3510 v8::Handle<Value> data) { |
3511 CHECK_EQ(5.76, data->NumberValue()); | 3511 CHECK_EQ(5.76, data->NumberValue()); |
3512 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); | 3512 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); |
3513 CHECK_EQ(7.56, message->GetScriptData()->NumberValue()); | 3513 CHECK_EQ(7.56, message->GetScriptData()->NumberValue()); |
3514 CHECK(!message->DidPassAccessCheck()); | |
3514 message_received = true; | 3515 message_received = true; |
3515 } | 3516 } |
3516 | 3517 |
3517 | 3518 |
3518 THREADED_TEST(MessageHandler0) { | 3519 THREADED_TEST(MessageHandler0) { |
3519 message_received = false; | 3520 message_received = false; |
3520 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 3521 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
3521 CHECK(!message_received); | 3522 CHECK(!message_received); |
3522 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); | 3523 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); |
3523 LocalContext context; | 3524 LocalContext context; |
3524 v8::ScriptOrigin origin = | 3525 v8::ScriptOrigin origin = |
3525 v8::ScriptOrigin(v8_str("6.75")); | 3526 v8::ScriptOrigin(v8_str("6.75")); |
3526 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), | 3527 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), |
3527 &origin); | 3528 &origin); |
3528 script->SetData(v8_str("7.56")); | 3529 script->SetData(v8_str("7.56")); |
3529 script->Run(); | 3530 script->Run(); |
3530 CHECK(message_received); | 3531 CHECK(message_received); |
3531 // clear out the message listener | 3532 // clear out the message listener |
3532 v8::V8::RemoveMessageListeners(check_message_0); | 3533 v8::V8::RemoveMessageListeners(check_message_0); |
3533 } | 3534 } |
3534 | 3535 |
3535 | 3536 |
3536 static void check_message_1(v8::Handle<v8::Message> message, | 3537 static void check_message_1(v8::Handle<v8::Message> message, |
3537 v8::Handle<Value> data) { | 3538 v8::Handle<Value> data) { |
3538 CHECK(data->IsNumber()); | 3539 CHECK(data->IsNumber()); |
3539 CHECK_EQ(1337, data->Int32Value()); | 3540 CHECK_EQ(1337, data->Int32Value()); |
3541 CHECK(!message->DidPassAccessCheck()); | |
3540 message_received = true; | 3542 message_received = true; |
3541 } | 3543 } |
3542 | 3544 |
3543 | 3545 |
3544 TEST(MessageHandler1) { | 3546 TEST(MessageHandler1) { |
3545 message_received = false; | 3547 message_received = false; |
3546 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 3548 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
3547 CHECK(!message_received); | 3549 CHECK(!message_received); |
3548 v8::V8::AddMessageListener(check_message_1); | 3550 v8::V8::AddMessageListener(check_message_1); |
3549 LocalContext context; | 3551 LocalContext context; |
3550 CompileRun("throw 1337;"); | 3552 CompileRun("throw 1337;"); |
3551 CHECK(message_received); | 3553 CHECK(message_received); |
3552 // clear out the message listener | 3554 // clear out the message listener |
3553 v8::V8::RemoveMessageListeners(check_message_1); | 3555 v8::V8::RemoveMessageListeners(check_message_1); |
3554 } | 3556 } |
3555 | 3557 |
3556 | 3558 |
3557 static void check_message_2(v8::Handle<v8::Message> message, | 3559 static void check_message_2(v8::Handle<v8::Message> message, |
3558 v8::Handle<Value> data) { | 3560 v8::Handle<Value> data) { |
3559 LocalContext context; | 3561 LocalContext context; |
3560 CHECK(data->IsObject()); | 3562 CHECK(data->IsObject()); |
3561 v8::Local<v8::Value> hidden_property = | 3563 v8::Local<v8::Value> hidden_property = |
3562 v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key")); | 3564 v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key")); |
3563 CHECK(v8_str("hidden value")->Equals(hidden_property)); | 3565 CHECK(v8_str("hidden value")->Equals(hidden_property)); |
3564 message_received = true; | 3566 message_received = true; |
3565 } | 3567 } |
3566 | 3568 |
3567 | 3569 |
3570 static void check_message_3(v8::Handle<v8::Message> message, | |
3571 v8::Handle<Value> data) { | |
3572 CHECK(message->DidPassAccessCheck()); | |
3573 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); | |
3574 message_received = true; | |
3575 } | |
3576 | |
3577 | |
3578 THREADED_TEST(MessageHandler3) { | |
Michael Starzinger
2013/07/30 09:52:55
This test is not thread-safe as it uses global sta
| |
3579 message_received = false; | |
3580 v8::HandleScope scope(v8::Isolate::GetCurrent()); | |
3581 CHECK(!message_received); | |
3582 v8::V8::AddMessageListener(check_message_3); | |
3583 LocalContext context; | |
3584 v8::ScriptOrigin origin = | |
3585 v8::ScriptOrigin(v8_str("6.75"), | |
3586 v8::Integer::New(1), | |
3587 v8::Integer::New(2), | |
3588 v8::True()); | |
3589 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), | |
3590 &origin); | |
3591 script->Run(); | |
3592 CHECK(message_received); | |
3593 // clear out the message listener | |
3594 v8::V8::RemoveMessageListeners(check_message_3); | |
3595 } | |
3596 | |
3597 | |
3568 TEST(MessageHandler2) { | 3598 TEST(MessageHandler2) { |
Michael Starzinger
2013/07/30 09:52:55
nit: Can we move the new test to below this one so
Mike West
2013/07/30 10:01:58
That looks like poor copy/paste on my part. I'll m
| |
3569 message_received = false; | 3599 message_received = false; |
3570 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 3600 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
3571 CHECK(!message_received); | 3601 CHECK(!message_received); |
3572 v8::V8::AddMessageListener(check_message_2); | 3602 v8::V8::AddMessageListener(check_message_2); |
3573 LocalContext context; | 3603 LocalContext context; |
3574 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error")); | 3604 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error")); |
3575 v8::Object::Cast(*error)->SetHiddenValue(v8_str("hidden key"), | 3605 v8::Object::Cast(*error)->SetHiddenValue(v8_str("hidden key"), |
3576 v8_str("hidden value")); | 3606 v8_str("hidden value")); |
3577 context->Global()->Set(v8_str("error"), error); | 3607 context->Global()->Set(v8_str("error"), error); |
3578 CompileRun("throw error;"); | 3608 CompileRun("throw error;"); |
(...skipping 16353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19932 CheckCorrectThrow("%HasProperty(other, 'x')"); | 19962 CheckCorrectThrow("%HasProperty(other, 'x')"); |
19933 CheckCorrectThrow("%HasElement(other, 1)"); | 19963 CheckCorrectThrow("%HasElement(other, 1)"); |
19934 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); | 19964 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); |
19935 CheckCorrectThrow("%GetPropertyNames(other)"); | 19965 CheckCorrectThrow("%GetPropertyNames(other)"); |
19936 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); | 19966 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); |
19937 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" | 19967 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" |
19938 "other, 'x', null, null, 1)"); | 19968 "other, 'x', null, null, 1)"); |
19939 } | 19969 } |
19940 | 19970 |
19941 #endif // WIN32 | 19971 #endif // WIN32 |
OLD | NEW |