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

Unified Diff: test/cctest/test-access-checks.cc

Issue 2677653002: Fix receiver checks for v8::Function on a remote context. (Closed)
Patch Set: . Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/bootstrapper.cc ('k') | test/unittests/api/remote-object-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-access-checks.cc
diff --git a/test/cctest/test-access-checks.cc b/test/cctest/test-access-checks.cc
index 727444b532f04eb3881dddbcaf284178b1f9a2db..f260a15c6e4a29efc5fb18906c81a353390c91e0 100644
--- a/test/cctest/test-access-checks.cc
+++ b/test/cctest/test-access-checks.cc
@@ -102,6 +102,23 @@ void IndexedEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
info.GetReturnValue().Set(names);
}
+void MethodGetter(v8::Local<v8::Name> property,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+
+ v8::Local<v8::External> data = info.Data().As<v8::External>();
+ v8::Local<v8::FunctionTemplate>& function_template =
+ *reinterpret_cast<v8::Local<v8::FunctionTemplate>*>(data->Value());
+
+ info.GetReturnValue().Set(
+ function_template->GetFunction(context).ToLocalChecked());
+}
+
+void MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().Set(8);
+}
+
void NamedGetterThrowsException(
v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
@@ -288,6 +305,44 @@ TEST(AccessCheckWithInterceptor) {
CheckCrossContextAccess(isolate, context1, context0->Global());
}
+TEST(CallFunctionWithRemoteContextReceiver) {
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope scope(isolate);
+ v8::Local<v8::FunctionTemplate> global_template =
+ v8::FunctionTemplate::New(isolate);
+
+ v8::Local<v8::Signature> signature =
+ v8::Signature::New(isolate, global_template);
+ v8::Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New(
+ isolate, MethodCallback, v8::External::New(isolate, &function_template),
+ signature);
+
+ global_template->InstanceTemplate()->SetAccessCheckCallbackAndHandler(
+ AccessCheck, v8::NamedPropertyHandlerConfiguration(
+ MethodGetter, nullptr, nullptr, nullptr, nullptr,
+ v8::External::New(isolate, &function_template)),
+ v8::IndexedPropertyHandlerConfiguration());
+
+ v8::Local<v8::Object> accessed_object =
+ v8::Context::NewRemoteContext(isolate,
+ global_template->InstanceTemplate())
+ .ToLocalChecked();
+ v8::Local<v8::Context> accessing_context =
+ v8::Context::New(isolate, nullptr, global_template->InstanceTemplate());
+
+ v8::HandleScope handle_scope(isolate);
+ accessing_context->Global()
+ ->Set(accessing_context, v8_str("other"), accessed_object)
+ .FromJust();
+ v8::Context::Scope context_scope(accessing_context);
+
+ {
+ v8::TryCatch try_catch(isolate);
+ ExpectInt32("this.other.method()", 8);
+ CHECK(!try_catch.HasCaught());
+ }
+}
+
TEST(AccessCheckWithExceptionThrowingInterceptor) {
v8::Isolate* isolate = CcTest::isolate();
isolate->SetFailedAccessCheckCallbackFunction([](v8::Local<v8::Object> target,
« no previous file with comments | « src/bootstrapper.cc ('k') | test/unittests/api/remote-object-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698