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

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

Issue 18298012: Check for scheduled exceptions after a failed-access-check callback. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comment 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 19769 matching lines...) Expand 10 before | Expand all | Expand 10 after
19780 context1->Global()->Set(v8_str("array"), array); 19780 context1->Global()->Set(v8_str("array"), array);
19781 ExpectString("JSON.stringify(array)", "[\"a\",\"b\"]"); 19781 ExpectString("JSON.stringify(array)", "[\"a\",\"b\"]");
19782 array->TurnOnAccessCheck(); 19782 array->TurnOnAccessCheck();
19783 ExpectString("JSON.stringify(array)", "[]"); 19783 ExpectString("JSON.stringify(array)", "[]");
19784 ExpectString("JSON.stringify([array])", "[[]]"); 19784 ExpectString("JSON.stringify([array])", "[[]]");
19785 ExpectString("JSON.stringify({'a' : array})", "{\"a\":[]}"); 19785 ExpectString("JSON.stringify({'a' : array})", "{\"a\":[]}");
19786 } 19786 }
19787 } 19787 }
19788 19788
19789 19789
19790 TEST(Bug2778) { 19790 bool access_check_fail_thrown = false;
19791 // Check that Object.observe includes access check. 19791 bool catch_callback_called = false;
19792 i::FLAG_harmony_observation = true; 19792
19793
19794 // Failed access check callback that performs a GC on each invocation.
19795 void FailedAccessCheckThrows(Local<v8::Object> target,
19796 v8::AccessType type,
19797 Local<v8::Value> data) {
19798 access_check_fail_thrown = true;
19799 i::PrintF("Access check failed. Error thrown.\n");
19800 v8::ThrowException(v8::Exception::Error(v8_str("cross context")));
19801 }
19802
19803
19804 void CatcherCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
19805 for (int i = 0; i < args.Length(); i++) {
19806 i::PrintF("%s\n", *String::Utf8Value(args[i]));
19807 }
19808 catch_callback_called = true;
19809 }
19810
19811
19812 void HasOwnPropertyCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
19813 args[0]->ToObject()->HasOwnProperty(args[1]->ToString());
19814 }
19815
19816
19817 void CheckCorrectThrow(const char* script) {
19818 // Test that the script, when wrapped into a try-catch, triggers the catch
19819 // clause due to failed access check throwing an exception.
19820 // The subsequent try-catch should run without any exception.
19821 access_check_fail_thrown = false;
19822 catch_callback_called = false;
19823 i::ScopedVector<char> source(1024);
19824 i::OS::SNPrintF(source, "try { %s; } catch (e) { catcher(e); }", script);
19825 CompileRun(source.start());
19826 CHECK(access_check_fail_thrown);
19827 CHECK(catch_callback_called);
19828
19829 access_check_fail_thrown = false;
19830 catch_callback_called = false;
19831 CompileRun("try { [1, 2, 3].sort(); } catch (e) { catcher(e) };");
19832 CHECK(!access_check_fail_thrown);
19833 CHECK(!catch_callback_called);
19834 }
19835
19836
19837 TEST(AccessCheckThrows) {
19838 i::FLAG_allow_natives_syntax = true;
19793 v8::V8::Initialize(); 19839 v8::V8::Initialize();
19794 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 19840 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows);
19795 v8::HandleScope scope(isolate); 19841 v8::HandleScope scope(v8::Isolate::GetCurrent());
19842
19796 // Create an ObjectTemplate for global objects and install access 19843 // Create an ObjectTemplate for global objects and install access
19797 // check callbacks that will block access. 19844 // check callbacks that will block access.
19798 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 19845 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
19799 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked, 19846 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked,
19800 IndexAccessAlwaysBlocked); 19847 IndexAccessAlwaysBlocked);
19801 19848
19802 // Create a context and set an x property on it's global object. 19849 // Create a context and set an x property on it's global object.
19803 LocalContext outer_context(NULL, global_template); 19850 LocalContext context0(NULL, global_template);
19804 v8::Handle<v8::Object> outer_global = outer_context->Global(); 19851 context0->Global()->Set(v8_str("x"), v8_num(42));
19805 outer_global->Set(v8_str("x"), v8_num(42)); 19852 v8::Handle<v8::Object> global0 = context0->Global();
19806 19853
19807 // Enter a new context. 19854 // Create a context with a different security token so that the
19808 v8::Handle<v8::Context> inner_context = v8::Context::New(isolate); 19855 // failed access check callback will be called on each access.
19809 { v8::Context::Scope inner(inner_context); 19856 LocalContext context1(NULL, global_template);
19810 v8::Handle<v8::Object> inner_global = inner_context->Global(); 19857 context1->Global()->Set(v8_str("other"), global0);
19811 inner_global->Set(v8_str("other"), outer_global); 19858
19812 v8::Handle<v8::FunctionTemplate> unreachable = 19859 v8::Handle<v8::FunctionTemplate> catcher_fun =
19813 v8::FunctionTemplate::New(UnreachableCallback); 19860 v8::FunctionTemplate::New(CatcherCallback);
19814 inner_global->Set(v8_str("unreachable"), unreachable->GetFunction()); 19861 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction());
19815 ExpectUndefined("other.x"); // Verify that access checks are in place. 19862
19816 CompileRun("Object.observe(other, unreachable);"); // Install observer. 19863 v8::Handle<v8::FunctionTemplate> has_own_property_fun =
19864 v8::FunctionTemplate::New(HasOwnPropertyCallback);
19865 context1->Global()->Set(v8_str("has_own_property"),
19866 has_own_property_fun->GetFunction());
19867
19868 { v8::TryCatch try_catch;
19869 access_check_fail_thrown = false;
19870 CompileRun("other.x;");
19871 CHECK(access_check_fail_thrown);
19872 CHECK(try_catch.HasCaught());
19817 } 19873 }
19818 19874
19819 ExpectInt32("x", 42); 19875 CheckCorrectThrow("other.x");
19820 // This must not be observable by the observer set up in the inner context. 19876 CheckCorrectThrow("other[1]");
19821 CompileRun("var a = 123;"); 19877 CheckCorrectThrow("JSON.stringify(other)");
19878 CheckCorrectThrow("has_own_property(other, 'x')");
19879 CheckCorrectThrow("%GetProperty(other, 'x')");
19880 CheckCorrectThrow("%SetProperty(other, 'x', 'foo', 1, 0)");
19881 CheckCorrectThrow("%IgnoreAttributesAndSetProperty(other, 'x', 'foo')");
19882 CheckCorrectThrow("%DeleteProperty(other, 'x', 0)");
19883 CheckCorrectThrow("%DeleteProperty(other, '1', 0)");
19884 CheckCorrectThrow("%HasLocalProperty(other, 'x')");
19885 CheckCorrectThrow("%HasProperty(other, 'x')");
19886 CheckCorrectThrow("%HasElement(other, 1)");
19887 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')");
19888 CheckCorrectThrow("%GetPropertyNames(other)");
19889 CheckCorrectThrow("%GetLocalPropertyNames(other, true)");
19890 CheckCorrectThrow("%DefineOrRedefineAccessorProperty("
19891 "other, 'x', null, null, 1)");
19822 } 19892 }
19823 19893
19824 #endif // WIN32 19894 #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