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

Unified Diff: test/cctest/test-api-interceptors.cc

Issue 2707263002: [api] Fix DescriptorInterceptor with access check. (Closed)
Patch Set: Check access if needed. 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/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api-interceptors.cc
diff --git a/test/cctest/test-api-interceptors.cc b/test/cctest/test-api-interceptors.cc
index d6a827c7f43193378f34fe0bf0cb80162dabeb0b..955b8f4df5b700ee59bf29eb59c5f4cb68b304d8 100644
--- a/test/cctest/test-api-interceptors.cc
+++ b/test/cctest/test-api-interceptors.cc
@@ -576,6 +576,51 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptor) {
}
namespace {
+int descriptor_was_called;
+
+void PropertyDescriptorCallback(
+ Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
+ // Intercept the callback by setting a different descriptor.
+ descriptor_was_called++;
+ const char* code =
+ "var desc = {value: 5};"
+ "desc;";
+ Local<Value> descriptor = v8_compile(code)
+ ->Run(info.GetIsolate()->GetCurrentContext())
+ .ToLocalChecked();
+ info.GetReturnValue().Set(descriptor);
+}
+} // namespace
+
+// Check that the descriptor callback is called on the global object.
+THREADED_TEST(DescriptorCallbackOnGlobalObject) {
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ v8::Local<v8::FunctionTemplate> templ =
+ v8::FunctionTemplate::New(CcTest::isolate());
+
+ v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate();
+ object_template->SetHandler(v8::NamedPropertyHandlerConfiguration(
+ nullptr, nullptr, PropertyDescriptorCallback, nullptr, nullptr, nullptr));
+ v8::Local<v8::Context> ctx =
+ v8::Context::New(CcTest::isolate(), nullptr, object_template);
+
+ descriptor_was_called = 0;
+
+ // Declare function.
+ v8::Local<v8::String> code = v8_str(
+ "var x = 42; var desc = Object.getOwnPropertyDescriptor(this, 'x'); "
+ "desc.value;");
+ CHECK_EQ(5, v8::Script::Compile(ctx, code)
+ .ToLocalChecked()
+ ->Run(ctx)
+ .ToLocalChecked()
+ ->Int32Value(ctx)
+ .FromJust());
+ CHECK_EQ(1, descriptor_was_called);
+}
+
+namespace {
void QueryCallbackSetDontDelete(
Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) {
info.GetReturnValue().Set(v8::PropertyAttribute::DontDelete);
@@ -4636,7 +4681,7 @@ TEST(NamedAllCanReadInterceptor) {
ExpectInt32("checked.whatever", 17);
CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')")
->IsUndefined());
- CHECK_EQ(5, access_check_data.count);
+ CHECK_EQ(6, access_check_data.count);
access_check_data.result = false;
ExpectInt32("checked.whatever", intercept_data_0.value);
@@ -4645,7 +4690,7 @@ TEST(NamedAllCanReadInterceptor) {
CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
CHECK(try_catch.HasCaught());
}
- CHECK_EQ(7, access_check_data.count);
+ CHECK_EQ(9, access_check_data.count);
intercept_data_1.should_intercept = true;
ExpectInt32("checked.whatever", intercept_data_1.value);
@@ -4654,7 +4699,7 @@ TEST(NamedAllCanReadInterceptor) {
CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
CHECK(try_catch.HasCaught());
}
- CHECK_EQ(9, access_check_data.count);
+ CHECK_EQ(12, access_check_data.count);
g_access_check_data = nullptr;
}
@@ -4723,7 +4768,7 @@ TEST(IndexedAllCanReadInterceptor) {
ExpectInt32("checked[15]", 17);
CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')")
->IsUndefined());
- CHECK_EQ(5, access_check_data.count);
+ CHECK_EQ(6, access_check_data.count);
access_check_data.result = false;
ExpectInt32("checked[15]", intercept_data_0.value);
@@ -4732,7 +4777,7 @@ TEST(IndexedAllCanReadInterceptor) {
CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
CHECK(try_catch.HasCaught());
}
- CHECK_EQ(7, access_check_data.count);
+ CHECK_EQ(9, access_check_data.count);
intercept_data_1.should_intercept = true;
ExpectInt32("checked[15]", intercept_data_1.value);
@@ -4741,7 +4786,7 @@ TEST(IndexedAllCanReadInterceptor) {
CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
CHECK(try_catch.HasCaught());
}
- CHECK_EQ(9, access_check_data.count);
+ CHECK_EQ(12, access_check_data.count);
g_access_check_data = nullptr;
}
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698