Skip to content

Commit

Permalink
Merge: [ic] Add StoreOwnIC_Slow
Browse files Browse the repository at this point in the history
This runtime function behaves like StoreDataPropertyInLiteral, except it
can throw, since it's also used for defining public class fields. Unlike
the literal use case, class field can end up throwing due to field
initializers doing things like freezing the instance.

Bug: chromium:1264828

(cherry picked from commit 1cc12b278e22d9ad4f0154e4b9e63cbb707b4657)

Change-Id: I3ea4d15ad9b906c26763f022c8e22b757fa80b6c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3401871
Reviewed-by: Igor Sheludko <[email protected]>
Reviewed-by: Shu-yu Guo <[email protected]>
Commit-Queue: Lutz Vahl <[email protected]>
Cr-Commit-Position: refs/branch-heads/9.7@{#40}
Cr-Branched-From: 49162da-refs/heads/9.7.106@{#1}
Cr-Branched-From: a7e9b8f-refs/heads/main@{#77674}
  • Loading branch information
syg authored and V8 LUCI CQ committed Jan 20, 2022
1 parent 41de661 commit 8313f18
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/ic/accessor-assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1296,13 +1296,16 @@ void AccessorAssembler::HandleStoreICHandlerCase(
if (ic_mode == ICMode::kGlobalIC) {
TailCallRuntime(Runtime::kStoreGlobalIC_Slow, p->context(), p->value(),
p->slot(), p->vector(), p->receiver(), p->name());
} else if (p->IsStoreOwn()) {
TailCallRuntime(Runtime::kStoreDataPropertyInLiteral, p->context(),
p->receiver(), p->name(), p->value());
} else {
TailCallRuntime(p->IsDefineOwn() ? Runtime::kKeyedDefineOwnIC_Slow
: Runtime::kKeyedStoreIC_Slow,
p->context(), p->value(), p->receiver(), p->name());
Runtime::FunctionId id;
if (p->IsStoreOwn()) {
id = Runtime::kStoreOwnIC_Slow;
} else if (p->IsDefineOwn()) {
id = Runtime::kKeyedDefineOwnIC_Slow;
} else {
id = Runtime::kKeyedStoreIC_Slow;
}
TailCallRuntime(id, p->context(), p->value(), p->receiver(), p->name());
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/ic/ic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,27 @@ RUNTIME_FUNCTION(Runtime_StoreOwnIC_Miss) {
RETURN_RESULT_OR_FAILURE(isolate, ic.Store(receiver, key, value));
}

RUNTIME_FUNCTION(Runtime_StoreOwnIC_Slow) {
HandleScope scope(isolate);
DCHECK_EQ(3, args.length());

Handle<Object> value = args.at(0);
Handle<Object> object = args.at(1);
Handle<Object> key = args.at(2);

// Unlike DefineOwn, StoreOwn doesn't handle private fields and is used for
// defining data properties in object literals and defining public class
// fields.
DCHECK(!key->IsSymbol() || !Symbol::cast(*key).is_private_name());

PropertyKey lookup_key(isolate, key);
LookupIterator it(isolate, object, lookup_key, LookupIterator::OWN);
MAYBE_RETURN(JSObject::DefineOwnPropertyIgnoreAttributes(
&it, value, NONE, Nothing<ShouldThrow>()),
ReadOnlyRoots(isolate).exception());
return *value;
}

RUNTIME_FUNCTION(Runtime_StoreGlobalIC_Miss) {
HandleScope scope(isolate);
DCHECK_EQ(4, args.length());
Expand Down
1 change: 1 addition & 0 deletions src/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ namespace internal {
F(KeyedStoreIC_Miss, 5, 1) \
F(KeyedDefineOwnIC_Miss, 5, 1) \
F(StoreInArrayLiteralIC_Miss, 5, 1) \
F(StoreOwnIC_Slow, 3, 1) \
F(KeyedStoreIC_Slow, 3, 1) \
F(KeyedDefineOwnIC_Slow, 3, 1) \
F(LoadElementWithInterceptor, 2, 1) \
Expand Down
15 changes: 15 additions & 0 deletions test/mjsunit/regress/regress-crbug-1264828.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --no-lazy-feedback-allocation

{
class C {
x = Object.freeze(this);
}
// Call once to install slow handler.
assertThrows(() => { new C(); });
// Hit the slow handler.
assertThrows(() => { new C(); });
}

0 comments on commit 8313f18

Please sign in to comment.