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

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

Issue 19053002: Promote exceptions thrown inside failed-access-check callback. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | no next file » | 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 19697 matching lines...) Expand 10 before | Expand all | Expand 10 after
19708 19708
19709 i::Semaphore* sem_; 19709 i::Semaphore* sem_;
19710 volatile int sem_value_; 19710 volatile int sem_value_;
19711 }; 19711 };
19712 19712
19713 19713
19714 THREADED_TEST(SemaphoreInterruption) { 19714 THREADED_TEST(SemaphoreInterruption) {
19715 ThreadInterruptTest().RunTest(); 19715 ThreadInterruptTest().RunTest();
19716 } 19716 }
19717 19717
19718
19719 bool access_check_fail_thrown = false;
19720 bool catch_callback_called = false;
19721
19722 static bool NamedAccessAlwaysBlocked(Local<v8::Object> global,
19723 Local<Value> name,
19724 v8::AccessType type,
19725 Local<Value> data) {
19726 i::PrintF("Named access blocked.\n");
19727 return false;
19728 }
19729
19730
19731 static bool IndexAccessAlwaysBlocked(Local<v8::Object> global,
19732 uint32_t key,
19733 v8::AccessType type,
19734 Local<Value> data) {
19735 i::PrintF("Indexed access blocked.\n");
19736 return false;
19737 }
19738
19739
19740 // Failed access check callback that performs a GC on each invocation.
19741 void FailedAccessCheckThrows(Local<v8::Object> target,
19742 v8::AccessType type,
19743 Local<v8::Value> data) {
19744 access_check_fail_thrown = true;
19745 i::PrintF("Access check failed. Error thrown.\n");
19746 v8::ThrowException(v8::Exception::Error(v8_str("cross context")));
19747 }
19748
19749
19750 void CatcherCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
19751 for (int i = 0; i < args.Length(); i++) {
19752 i::PrintF("%s\n", *String::Utf8Value(args[i]));
19753 }
19754 catch_callback_called = true;
19755 }
19756
19757
19758 void HasOwnPropertyCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
19759 args[0]->ToObject()->HasOwnProperty(args[1]->ToString());
19760 }
19761
19762
19763 void CheckCorrectThrow(const char* script) {
19764 // Test that the script, when wrapped into a try-catch, triggers the catch
19765 // clause due to failed access check throwing an exception.
19766 // The subsequent try-catch should run without any exception.
19767 access_check_fail_thrown = false;
19768 catch_callback_called = false;
19769 i::ScopedVector<char> source(1024);
19770 i::OS::SNPrintF(source, "try { %s; } catch (e) { catcher(e); }", script);
19771 CompileRun(source.start());
19772 CHECK(access_check_fail_thrown);
19773 CHECK(catch_callback_called);
19774
19775 access_check_fail_thrown = false;
19776 catch_callback_called = false;
19777 CompileRun("try { [1, 2, 3].sort(); } catch (e) { catcher(e) };");
19778 CHECK(!access_check_fail_thrown);
19779 CHECK(!catch_callback_called);
19780 }
19781
19782
19783 TEST(AccessCheckThrows) {
19784 i::FLAG_allow_natives_syntax = true;
19785 v8::V8::Initialize();
19786 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows);
19787 v8::HandleScope scope(v8::Isolate::GetCurrent());
19788
19789 // Create an ObjectTemplate for global objects and install access
19790 // check callbacks that will block access.
19791 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
19792 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked,
19793 IndexAccessAlwaysBlocked);
19794
19795 // Create a context and set an x property on it's global object.
19796 LocalContext context0(NULL, global_template);
19797 context0->Global()->Set(v8_str("x"), v8_num(42));
19798 v8::Handle<v8::Object> global0 = context0->Global();
19799
19800 // Create a context with a different security token so that the
19801 // failed access check callback will be called on each access.
19802 LocalContext context1(NULL, global_template);
19803 context1->Global()->Set(v8_str("other"), global0);
19804
19805 v8::Handle<v8::FunctionTemplate> catcher_fun =
19806 v8::FunctionTemplate::New(CatcherCallback);
19807 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction());
19808
19809 v8::Handle<v8::FunctionTemplate> has_own_property_fun =
19810 v8::FunctionTemplate::New(HasOwnPropertyCallback);
19811 context1->Global()->Set(v8_str("has_own_property"),
19812 has_own_property_fun->GetFunction());
19813
19814 { v8::TryCatch try_catch;
19815 access_check_fail_thrown = false;
19816 CompileRun("other.x;");
19817 CHECK(access_check_fail_thrown);
19818 CHECK(try_catch.HasCaught());
19819 }
19820
19821 CheckCorrectThrow("other.x");
19822 CheckCorrectThrow("other[1]");
19823 CheckCorrectThrow("has_own_property(other, 'x')");
19824 CheckCorrectThrow("%GetProperty(other, 'x')");
19825 CheckCorrectThrow("%SetProperty(other, 'x', 'foo', 1, 0)");
19826 CheckCorrectThrow("%IgnoreAttributesAndSetProperty(other, 'x', 'foo')");
19827 CheckCorrectThrow("%DeleteProperty(other, 'x', 0)");
19828 CheckCorrectThrow("%DeleteProperty(other, '1', 0)");
19829 CheckCorrectThrow("%HasLocalProperty(other, 'x')");
19830 CheckCorrectThrow("%HasProperty(other, 'x')");
19831 CheckCorrectThrow("%HasElement(other, 1)");
19832 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')");
19833 CheckCorrectThrow("%GetPropertyNames(other)");
19834 CheckCorrectThrow("%GetLocalPropertyNames(other, true)");
19835 CheckCorrectThrow("%DefineOrRedefineAccessorProperty("
19836 "other, 'x', null, null, 1)");
19837 }
19838
19839
19718 #endif // WIN32 19840 #endif // WIN32
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698