Skip to content

Commit 0b690a9

Browse files
fhinkelgibfahn
authored andcommitted
deps: cherry-pick 37a3a15c3 from V8 upstream
Original commit message: [api] Intercept DefineProperty after Descriptor query Analog to other interceptors, intercept the DefineProperty call only after obtaining the property descriptor. This behavior allows us to mirror calls on a sandboxed object as it is needed in Node. See for example #13265 Bug: Change-Id: I73b8f8908d13473939b37fb6727858d0bee6bda3 Reviewed-on: https://chromium-review.googlesource.com/725295 Reviewed-by: Andreas Haas <[email protected]> Commit-Queue: Franziska Hinkelmann <[email protected]> Cr-Commit-Position: refs/heads/master@{#48683} PR-URL: #16294 Backport-PR-URL: #16413 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent b71a33c commit 0b690a9

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

deps/v8/src/lookup.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class V8_EXPORT_PRIVATE LookupIterator final BASE_EMBEDDED {
2222
kInterceptor = 1 << 0,
2323
kPrototypeChain = 1 << 1,
2424

25-
// Convience combinations of bits.
25+
// Convenience combinations of bits.
2626
OWN_SKIP_INTERCEPTOR = 0,
2727
OWN = kInterceptor,
2828
PROTOTYPE_CHAIN_SKIP_INTERCEPTOR = kPrototypeChain,

deps/v8/src/objects.cc

+14-11
Original file line numberDiff line numberDiff line change
@@ -6713,17 +6713,6 @@ Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(Isolate* isolate,
67136713
it.Next();
67146714
}
67156715

6716-
// Handle interceptor
6717-
if (it.state() == LookupIterator::INTERCEPTOR) {
6718-
if (it.HolderIsReceiverOrHiddenPrototype()) {
6719-
Maybe<bool> result = DefinePropertyWithInterceptorInternal(
6720-
&it, it.GetInterceptor(), should_throw, *desc);
6721-
if (result.IsNothing() || result.FromJust()) {
6722-
return result;
6723-
}
6724-
}
6725-
}
6726-
67276716
return OrdinaryDefineOwnProperty(&it, desc, should_throw);
67286717
}
67296718

@@ -6739,6 +6728,20 @@ Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
67396728
PropertyDescriptor current;
67406729
MAYBE_RETURN(GetOwnPropertyDescriptor(it, &current), Nothing<bool>());
67416730

6731+
it->Restart();
6732+
// Handle interceptor
6733+
for (; it->IsFound(); it->Next()) {
6734+
if (it->state() == LookupIterator::INTERCEPTOR) {
6735+
if (it->HolderIsReceiverOrHiddenPrototype()) {
6736+
Maybe<bool> result = DefinePropertyWithInterceptorInternal(
6737+
it, it->GetInterceptor(), should_throw, *desc);
6738+
if (result.IsNothing() || result.FromJust()) {
6739+
return result;
6740+
}
6741+
}
6742+
}
6743+
}
6744+
67426745
// TODO(jkummerow/verwaest): It would be nice if we didn't have to reset
67436746
// the iterator every time. Currently, the reasons why we need it are:
67446747
// - handle interceptors correctly

deps/v8/test/cctest/test-api-interceptors.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -716,20 +716,21 @@ bool define_was_called_in_order = false;
716716
void GetterCallbackOrder(Local<Name> property,
717717
const v8::PropertyCallbackInfo<v8::Value>& info) {
718718
get_was_called_in_order = true;
719-
CHECK(define_was_called_in_order);
719+
CHECK(!define_was_called_in_order);
720720
info.GetReturnValue().Set(property);
721721
}
722722

723723
void DefinerCallbackOrder(Local<Name> property,
724724
const v8::PropertyDescriptor& desc,
725725
const v8::PropertyCallbackInfo<v8::Value>& info) {
726-
CHECK(!get_was_called_in_order); // Define called before get.
726+
// Get called before DefineProperty because we query the descriptor first.
727+
CHECK(get_was_called_in_order);
727728
define_was_called_in_order = true;
728729
}
729730

730731
} // namespace
731732

732-
// Check that definer callback is called before getter callback.
733+
// Check that getter callback is called before definer callback.
733734
THREADED_TEST(DefinerCallbackGetAndDefine) {
734735
v8::HandleScope scope(CcTest::isolate());
735736
v8::Local<v8::FunctionTemplate> templ =

0 commit comments

Comments
 (0)