diff options
Diffstat (limited to 'deps/v8/test/unittests/api/access-check-unittest.cc')
-rw-r--r-- | deps/v8/test/unittests/api/access-check-unittest.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/deps/v8/test/unittests/api/access-check-unittest.cc b/deps/v8/test/unittests/api/access-check-unittest.cc index 8bfb507a7c..65e20d2510 100644 --- a/deps/v8/test/unittests/api/access-check-unittest.cc +++ b/deps/v8/test/unittests/api/access-check-unittest.cc @@ -71,4 +71,52 @@ TEST_F(AccessCheckTest, GetOwnPropertyDescriptor) { " .set.call(other, 42);"); } +namespace { +bool failed_access_check_callback_called; + +v8::Local<v8::String> v8_str(const char* x) { + return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), x, + v8::NewStringType::kNormal) + .ToLocalChecked(); +} + +class AccessCheckTestConsoleDelegate : public debug::ConsoleDelegate { + public: + void Log(const debug::ConsoleCallArguments& args, + const debug::ConsoleContext& context) { + FAIL(); + } +}; + +} // namespace + +// Ensure that {console.log} does an access check for its arguments. +TEST_F(AccessCheckTest, ConsoleLog) { + isolate()->SetFailedAccessCheckCallbackFunction( + [](v8::Local<v8::Object> host, v8::AccessType type, + v8::Local<v8::Value> data) { + failed_access_check_callback_called = true; + }); + AccessCheckTestConsoleDelegate console{}; + debug::SetConsoleDelegate(isolate(), &console); + + Local<ObjectTemplate> object_template = ObjectTemplate::New(isolate()); + object_template->SetAccessCheckCallback(AccessCheck); + + Local<Context> context1 = Context::New(isolate(), nullptr); + Local<Context> context2 = Context::New(isolate(), nullptr); + + Local<Object> object1 = + object_template->NewInstance(context1).ToLocalChecked(); + EXPECT_TRUE(context2->Global() + ->Set(context2, v8_str("object_from_context1"), object1) + .IsJust()); + + Context::Scope context_scope(context2); + failed_access_check_callback_called = false; + CompileRun(isolate(), "console.log(object_from_context1);").ToLocalChecked(); + + ASSERT_TRUE(failed_access_check_callback_called); +} + } // namespace v8 |