Commit fec98619 authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[properties] Fix SetLazyDataProperty for indices

(Thanks jbroman@ for the strawperson fix.)

Bug: chromium:1136800
Change-Id: I4aee55ef40069b460f59ef5b7ba7fc50ab7033cd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2463225
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70423}
parent 1f858b3f
......@@ -81,12 +81,13 @@ bool Accessors::IsJSObjectFieldAccessor(Isolate* isolate, Handle<Map> map,
}
V8_WARN_UNUSED_RESULT MaybeHandle<Object>
Accessors::ReplaceAccessorWithDataProperty(Handle<Object> receiver,
Accessors::ReplaceAccessorWithDataProperty(Isolate* isolate,
Handle<Object> receiver,
Handle<JSObject> holder,
Handle<Name> name,
Handle<Object> value) {
LookupIterator it(holder->GetIsolate(), receiver, name, holder,
LookupIterator::OWN_SKIP_INTERCEPTOR);
LookupIterator it(isolate, receiver, LookupIterator::Key(isolate, name),
holder, LookupIterator::OWN_SKIP_INTERCEPTOR);
// Skip any access checks we might hit. This accessor should never hit in a
// situation where the caller does not have access.
if (it.state() == LookupIterator::ACCESS_CHECK) {
......@@ -114,8 +115,8 @@ void Accessors::ReconfigureToDataProperty(
Handle<JSObject>::cast(Utils::OpenHandle(*info.Holder()));
Handle<Name> name = Utils::OpenHandle(*key);
Handle<Object> value = Utils::OpenHandle(*val);
MaybeHandle<Object> result =
Accessors::ReplaceAccessorWithDataProperty(receiver, holder, name, value);
MaybeHandle<Object> result = Accessors::ReplaceAccessorWithDataProperty(
isolate, receiver, holder, name, value);
if (result.is_null()) {
isolate->OptionalRescheduleException(false);
} else {
......
......@@ -102,8 +102,8 @@ class Accessors : public AllStatic {
FieldIndex* field_index);
static MaybeHandle<Object> ReplaceAccessorWithDataProperty(
Handle<Object> receiver, Handle<JSObject> holder, Handle<Name> name,
Handle<Object> value);
Isolate* isolate, Handle<Object> receiver, Handle<JSObject> holder,
Handle<Name> name, Handle<Object> value);
// Create an AccessorInfo. The setter is optional (can be nullptr).
//
......
......@@ -1460,7 +1460,7 @@ MaybeHandle<Object> Object::GetPropertyWithAccessor(LookupIterator* it) {
if (info->replace_on_access() && receiver->IsJSReceiver()) {
RETURN_ON_EXCEPTION(isolate,
Accessors::ReplaceAccessorWithDataProperty(
receiver, holder, name, result),
isolate, receiver, holder, name, result),
Object);
}
return reboxed_result;
......
......@@ -882,3 +882,27 @@ TEST(ObjectSetLazyDataProperty) {
CHECK(result.FromJust());
ExpectInt32("obj.bar = -1; obj.bar;", -1);
}
TEST(ObjectSetLazyDataPropertyForIndex) {
// Regression test for crbug.com/1136800 .
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::Object> obj = v8::Object::New(isolate);
CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
static int getter_call_count;
getter_call_count = 0;
auto result = obj->SetLazyDataProperty(
env.local(), v8_str("1"),
[](Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
getter_call_count++;
info.GetReturnValue().Set(getter_call_count);
});
CHECK(result.FromJust());
CHECK_EQ(0, getter_call_count);
for (int i = 0; i < 2; i++) {
ExpectInt32("obj[1]", 1);
CHECK_EQ(1, getter_call_count);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment