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

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

Issue 20646006: Pipe a script's CORS status through V8 during compilation. (Closed) Base URL: https://chromium.googlesource.com/external/v8.git@master
Patch Set: . Created 7 years, 4 months 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/objects-inl.h ('k') | test/cctest/test-compiler.cc » ('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 3547 matching lines...) Expand 10 before | Expand all | Expand 10 after
3558 3558
3559 3559
3560 bool message_received; 3560 bool message_received;
3561 3561
3562 3562
3563 static void check_message_0(v8::Handle<v8::Message> message, 3563 static void check_message_0(v8::Handle<v8::Message> message,
3564 v8::Handle<Value> data) { 3564 v8::Handle<Value> data) {
3565 CHECK_EQ(5.76, data->NumberValue()); 3565 CHECK_EQ(5.76, data->NumberValue());
3566 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); 3566 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
3567 CHECK_EQ(7.56, message->GetScriptData()->NumberValue()); 3567 CHECK_EQ(7.56, message->GetScriptData()->NumberValue());
3568 CHECK(!message->IsSharedCrossOrigin());
3568 message_received = true; 3569 message_received = true;
3569 } 3570 }
3570 3571
3571 3572
3572 THREADED_TEST(MessageHandler0) { 3573 THREADED_TEST(MessageHandler0) {
3573 message_received = false; 3574 message_received = false;
3574 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3575 v8::HandleScope scope(v8::Isolate::GetCurrent());
3575 CHECK(!message_received); 3576 CHECK(!message_received);
3576 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); 3577 v8::V8::AddMessageListener(check_message_0, v8_num(5.76));
3577 LocalContext context; 3578 LocalContext context;
3578 v8::ScriptOrigin origin = 3579 v8::ScriptOrigin origin =
3579 v8::ScriptOrigin(v8_str("6.75")); 3580 v8::ScriptOrigin(v8_str("6.75"));
3580 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 3581 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3581 &origin); 3582 &origin);
3582 script->SetData(v8_str("7.56")); 3583 script->SetData(v8_str("7.56"));
3583 script->Run(); 3584 script->Run();
3584 CHECK(message_received); 3585 CHECK(message_received);
3585 // clear out the message listener 3586 // clear out the message listener
3586 v8::V8::RemoveMessageListeners(check_message_0); 3587 v8::V8::RemoveMessageListeners(check_message_0);
3587 } 3588 }
3588 3589
3589 3590
3590 static void check_message_1(v8::Handle<v8::Message> message, 3591 static void check_message_1(v8::Handle<v8::Message> message,
3591 v8::Handle<Value> data) { 3592 v8::Handle<Value> data) {
3592 CHECK(data->IsNumber()); 3593 CHECK(data->IsNumber());
3593 CHECK_EQ(1337, data->Int32Value()); 3594 CHECK_EQ(1337, data->Int32Value());
3595 CHECK(!message->IsSharedCrossOrigin());
3594 message_received = true; 3596 message_received = true;
3595 } 3597 }
3596 3598
3597 3599
3598 TEST(MessageHandler1) { 3600 TEST(MessageHandler1) {
3599 message_received = false; 3601 message_received = false;
3600 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3602 v8::HandleScope scope(v8::Isolate::GetCurrent());
3601 CHECK(!message_received); 3603 CHECK(!message_received);
3602 v8::V8::AddMessageListener(check_message_1); 3604 v8::V8::AddMessageListener(check_message_1);
3603 LocalContext context; 3605 LocalContext context;
3604 CompileRun("throw 1337;"); 3606 CompileRun("throw 1337;");
3605 CHECK(message_received); 3607 CHECK(message_received);
3606 // clear out the message listener 3608 // clear out the message listener
3607 v8::V8::RemoveMessageListeners(check_message_1); 3609 v8::V8::RemoveMessageListeners(check_message_1);
3608 } 3610 }
3609 3611
3610 3612
3611 static void check_message_2(v8::Handle<v8::Message> message, 3613 static void check_message_2(v8::Handle<v8::Message> message,
3612 v8::Handle<Value> data) { 3614 v8::Handle<Value> data) {
3613 LocalContext context; 3615 LocalContext context;
3614 CHECK(data->IsObject()); 3616 CHECK(data->IsObject());
3615 v8::Local<v8::Value> hidden_property = 3617 v8::Local<v8::Value> hidden_property =
3616 v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key")); 3618 v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key"));
3617 CHECK(v8_str("hidden value")->Equals(hidden_property)); 3619 CHECK(v8_str("hidden value")->Equals(hidden_property));
3620 CHECK(!message->IsSharedCrossOrigin());
3618 message_received = true; 3621 message_received = true;
3619 } 3622 }
3620 3623
3621 3624
3622 TEST(MessageHandler2) { 3625 TEST(MessageHandler2) {
3623 message_received = false; 3626 message_received = false;
3624 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3627 v8::HandleScope scope(v8::Isolate::GetCurrent());
3625 CHECK(!message_received); 3628 CHECK(!message_received);
3626 v8::V8::AddMessageListener(check_message_2); 3629 v8::V8::AddMessageListener(check_message_2);
3627 LocalContext context; 3630 LocalContext context;
3628 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error")); 3631 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error"));
3629 v8::Object::Cast(*error)->SetHiddenValue(v8_str("hidden key"), 3632 v8::Object::Cast(*error)->SetHiddenValue(v8_str("hidden key"),
3630 v8_str("hidden value")); 3633 v8_str("hidden value"));
3631 context->Global()->Set(v8_str("error"), error); 3634 context->Global()->Set(v8_str("error"), error);
3632 CompileRun("throw error;"); 3635 CompileRun("throw error;");
3633 CHECK(message_received); 3636 CHECK(message_received);
3634 // clear out the message listener 3637 // clear out the message listener
3635 v8::V8::RemoveMessageListeners(check_message_2); 3638 v8::V8::RemoveMessageListeners(check_message_2);
3636 } 3639 }
3637 3640
3638 3641
3642 static void check_message_3(v8::Handle<v8::Message> message,
3643 v8::Handle<Value> data) {
3644 CHECK(message->IsSharedCrossOrigin());
3645 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
3646 message_received = true;
3647 }
3648
3649
3650 TEST(MessageHandler3) {
3651 message_received = false;
3652 v8::HandleScope scope(v8::Isolate::GetCurrent());
3653 CHECK(!message_received);
3654 v8::V8::AddMessageListener(check_message_3);
3655 LocalContext context;
3656 v8::ScriptOrigin origin =
3657 v8::ScriptOrigin(v8_str("6.75"),
3658 v8::Integer::New(1),
3659 v8::Integer::New(2),
3660 v8::True());
3661 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3662 &origin);
3663 script->Run();
3664 CHECK(message_received);
3665 // clear out the message listener
3666 v8::V8::RemoveMessageListeners(check_message_3);
3667 }
3668
3669
3670 static void check_message_4(v8::Handle<v8::Message> message,
3671 v8::Handle<Value> data) {
3672 CHECK(!message->IsSharedCrossOrigin());
3673 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
3674 message_received = true;
3675 }
3676
3677
3678 TEST(MessageHandler4) {
3679 message_received = false;
3680 v8::HandleScope scope(v8::Isolate::GetCurrent());
3681 CHECK(!message_received);
3682 v8::V8::AddMessageListener(check_message_4);
3683 LocalContext context;
3684 v8::ScriptOrigin origin =
3685 v8::ScriptOrigin(v8_str("6.75"),
3686 v8::Integer::New(1),
3687 v8::Integer::New(2),
3688 v8::False());
3689 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3690 &origin);
3691 script->Run();
3692 CHECK(message_received);
3693 // clear out the message listener
3694 v8::V8::RemoveMessageListeners(check_message_4);
3695 }
3696
Michael Starzinger 2013/07/30 14:22:00 nit: Two empty newlines between methods.
3697 static void check_message_5a(v8::Handle<v8::Message> message,
3698 v8::Handle<Value> data) {
3699 CHECK(message->IsSharedCrossOrigin());
3700 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
3701 message_received = true;
3702 }
3703
3704
3705 static void check_message_5b(v8::Handle<v8::Message> message,
3706 v8::Handle<Value> data) {
3707 CHECK(!message->IsSharedCrossOrigin());
3708 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
3709 message_received = true;
3710 }
3711
3712
3713 TEST(MessageHandler5) {
3714 message_received = false;
3715 v8::HandleScope scope(v8::Isolate::GetCurrent());
3716 CHECK(!message_received);
3717 v8::V8::AddMessageListener(check_message_5a);
3718 LocalContext context;
3719 v8::ScriptOrigin origin =
3720 v8::ScriptOrigin(v8_str("6.75"),
3721 v8::Integer::New(1),
3722 v8::Integer::New(2),
3723 v8::True());
3724 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
3725 &origin);
3726 script->Run();
3727 CHECK(message_received);
3728 // clear out the message listener
3729 v8::V8::RemoveMessageListeners(check_message_5a);
3730 v8::V8::AddMessageListener(check_message_5b);
Michael Starzinger 2013/07/30 14:22:00 Better also reset the "message_received" variable
3731 origin =
3732 v8::ScriptOrigin(v8_str("6.75"),
3733 v8::Integer::New(1),
3734 v8::Integer::New(2),
3735 v8::False());
3736 script = Script::Compile(v8_str("throw 'error'"),
3737 &origin);
3738 script->Run();
3739 CHECK(message_received);
3740 // clear out the message listener
3741 v8::V8::RemoveMessageListeners(check_message_5b);
3742 }
3743
3744
3639 THREADED_TEST(GetSetProperty) { 3745 THREADED_TEST(GetSetProperty) {
3640 LocalContext context; 3746 LocalContext context;
3641 v8::HandleScope scope(context->GetIsolate()); 3747 v8::HandleScope scope(context->GetIsolate());
3642 context->Global()->Set(v8_str("foo"), v8_num(14)); 3748 context->Global()->Set(v8_str("foo"), v8_num(14));
3643 context->Global()->Set(v8_str("12"), v8_num(92)); 3749 context->Global()->Set(v8_str("12"), v8_num(92));
3644 context->Global()->Set(v8::Integer::New(16), v8_num(32)); 3750 context->Global()->Set(v8::Integer::New(16), v8_num(32));
3645 context->Global()->Set(v8_num(13), v8_num(56)); 3751 context->Global()->Set(v8_num(13), v8_num(56));
3646 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run(); 3752 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run();
3647 CHECK_EQ(14, foo->Int32Value()); 3753 CHECK_EQ(14, foo->Int32Value());
3648 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run(); 3754 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run();
(...skipping 16337 matching lines...) Expand 10 before | Expand all | Expand 10 after
19986 CheckCorrectThrow("%HasProperty(other, 'x')"); 20092 CheckCorrectThrow("%HasProperty(other, 'x')");
19987 CheckCorrectThrow("%HasElement(other, 1)"); 20093 CheckCorrectThrow("%HasElement(other, 1)");
19988 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); 20094 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')");
19989 CheckCorrectThrow("%GetPropertyNames(other)"); 20095 CheckCorrectThrow("%GetPropertyNames(other)");
19990 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); 20096 CheckCorrectThrow("%GetLocalPropertyNames(other, true)");
19991 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" 20097 CheckCorrectThrow("%DefineOrRedefineAccessorProperty("
19992 "other, 'x', null, null, 1)"); 20098 "other, 'x', null, null, 1)");
19993 } 20099 }
19994 20100
19995 #endif // WIN32 20101 #endif // WIN32
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | test/cctest/test-compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698