Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: cherry-pick 0ba513f05 from V8 upstream #11712

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 5
#define V8_MINOR_VERSION 6
#define V8_BUILD_NUMBER 326
#define V8_PATCH_LEVEL 55
#define V8_PATCH_LEVEL 56

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
9 changes: 8 additions & 1 deletion deps/v8/src/objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7330,7 +7330,13 @@ namespace {

Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
PropertyDescriptor* desc) {
if (it->state() == LookupIterator::INTERCEPTOR) {
bool has_access = true;
if (it->state() == LookupIterator::ACCESS_CHECK) {
has_access = it->HasAccess() || JSObject::AllCanRead(it);
it->Next();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this sound? I see LookupIterator::Next() has a DCHECK_NE(JSPROXY, state_) but if I read JSObject::AllCanRead() right, it can stop at a JSPROXY instance. It seems like the logic should be:

if (has_access) it->Next();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The access check is on the object_template, which is created by the embedder. We cannot configure templates as JSProxies. I'd say it's sound.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, if you say so.

}

if (has_access && it->state() == LookupIterator::INTERCEPTOR) {
Isolate* isolate = it->isolate();
Handle<InterceptorInfo> interceptor = it->GetInterceptor();
if (!interceptor->descriptor()->IsUndefined(isolate)) {
Expand Down Expand Up @@ -7374,6 +7380,7 @@ Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
}
}
}
it->Restart();
return Just(false);
}
} // namespace
Expand Down
56 changes: 50 additions & 6 deletions deps/v8/test/cctest/test-api-interceptors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,50 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptorThrow) {

CHECK_EQ(set_was_called, false);
}
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);
}

bool get_was_called_in_order = false;
bool define_was_called_in_order = false;
Expand Down Expand Up @@ -4516,7 +4560,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);
Expand All @@ -4525,7 +4569,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);
Expand All @@ -4534,7 +4578,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;
}

Expand Down Expand Up @@ -4603,7 +4647,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);
Expand All @@ -4612,7 +4656,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);
Expand All @@ -4621,7 +4665,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;
}
Expand Down