Browse Source

chore: cherry-pick 1 changes from 0-M124 (#41985)

* chore: [28-x-y] cherry-pick 1 changes from 0-M124

* 3f6bf073649a454317690914939766f62bc65ad7 from chromium

* chore: update patches

---------

Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Pedro Pontes 11 months ago
parent
commit
cd25fbfd73

+ 1 - 0
patches/chromium/.patches

@@ -156,3 +156,4 @@ cherry-pick-98bcf9ef5cdd.patch
 cherry-pick-013961609785.patch
 a11y_avoid_clearing_resetting_focus_on_an_already_focus_event.patch
 cherry-pick-b2cc7b7ac538.patch
+m120-lts_merge_fix_domarraybuffer_isdetached_and_comment_out.patch

+ 416 - 0
patches/chromium/m120-lts_merge_fix_domarraybuffer_isdetached_and_comment_out.patch

@@ -0,0 +1,416 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Marja=20H=C3=B6ltt=C3=A4?= <[email protected]>
+Date: Thu, 16 May 2024 17:11:21 +0000
+Subject: Merge "Fix DOMArrayBuffer::IsDetached()" and "Comment out a CHECK
+ that a DOMAB has maximally one non-detached JSAB"
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+M120 merge issues:
+   - MainWorld didn't have the variant with an Isolate argument:
+   cherry-picked the CL that adds that variant.
+   - DOMDataStore didn't have a templated Get():
+   Used GetWrapper() instead.
+   - Also needed to fic build issues because Get/GetWrapper
+   needs an argument that inherits directly from ScriptWrappable
+   - On main, Get/GetWrapper works with const ScriptWrappable pointers,
+   needed to do a const_cast for M120.
+
+Changes with the merge:
+- Manual rebase on top of the branch
+- Disabled the Gamepad tests; something has changed in the test
+setup, so that the past state doesn't allow adding a TestEnvironment
+like the current state does.
+
+1)
+
+A DOMArrayBuffer was maintaining its own "is_detached_" state, and
+would consider itself non-detached even if the corresponding
+JSArrayBuffer (or, all of them, in case there are several) was
+detached.
+
+Piping in the v8::Isolate would be a too big change for this fix, so this is using v8::Isolate::GetCurrent() for now.
+
+2)
+
+Comment out a CHECK that a DOMAB has maximally one non-detached JSAB
+
+Based on crash reports, this assumption is not true and has to be
+investigated.
+
+Removing this newly introduced CHECK to be able to merge fixes in this
+area - we still violate this invariant but the fixes are a step into
+the right direction.
+
+Fix in question:
+https://chromium-review.googlesource.com/5387887
+which also introduced this CHECK.
+
+Bug: b/330759272
+
+(cherry picked from commit 04e7550d7aa3bf4ac4e49d7074972d357de139e6)
+
+(cherry picked from commit 4545e401c4a6a2ac5dce39d8af4b3e69f8e902eb)
+
+Change-Id: I672e17df84ff85536b0cd4f4021ccc460b5fd233
+Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5499291
+Reviewed-by: Marja Hölttä <[email protected]>
+Reviewed-by: Matt Reynolds <[email protected]>
+Commit-Queue: Roger Felipe Zanoni da Silva <[email protected]>
+Owners-Override: Mohamed Omar <[email protected]>
+Cr-Commit-Position: refs/branch-heads/6099@{#2021}
+Cr-Branched-From: e6ee4500f7d6549a9ac1354f8d056da49ef406be-refs/heads/main@{#1217362}
+
+diff --git a/third_party/blink/renderer/core/typed_arrays/dom_array_buffer.cc b/third_party/blink/renderer/core/typed_arrays/dom_array_buffer.cc
+index c85839f1a0bf43bc21611b490bf8b7b17ad385da..d4597e55bb4146cd413479863ff680be56022d3a 100644
+--- a/third_party/blink/renderer/core/typed_arrays/dom_array_buffer.cc
++++ b/third_party/blink/renderer/core/typed_arrays/dom_array_buffer.cc
+@@ -46,12 +46,25 @@ const WrapperTypeInfo& DOMArrayBuffer::wrapper_type_info_ =
+ 
+ static void AccumulateArrayBuffersForAllWorlds(
+     v8::Isolate* isolate,
+-    DOMArrayBuffer* object,
++    const DOMArrayBuffer* object,
+     v8::LocalVector<v8::ArrayBuffer>& buffers) {
++  ScriptWrappable* wrappable =
++      dynamic_cast<ScriptWrappable*>(const_cast<DOMArrayBuffer*>(object));
++  if (!object->has_non_main_world_wrappers() && IsMainThread()) {
++    const DOMWrapperWorld& world = DOMWrapperWorld::MainWorld();
++    v8::Local<v8::Object> wrapper =
++        world.DomDataStore().GetWrapper(wrappable, isolate);
++    if (!wrapper.IsEmpty()) {
++      buffers.push_back(v8::Local<v8::ArrayBuffer>::Cast(wrapper));
++    }
++    return;
++  }
++
+   Vector<scoped_refptr<DOMWrapperWorld>> worlds;
+   DOMWrapperWorld::AllWorldsInCurrentThread(worlds);
+   for (const auto& world : worlds) {
+-    v8::Local<v8::Object> wrapper = world->DomDataStore().Get(object, isolate);
++    v8::Local<v8::Object> wrapper =
++        world->DomDataStore().Get(wrappable, isolate);
+     if (!wrapper.IsEmpty())
+       buffers.push_back(v8::Local<v8::ArrayBuffer>::Cast(wrapper));
+   }
+@@ -256,6 +269,51 @@ v8::MaybeLocal<v8::Value> DOMArrayBuffer::Wrap(ScriptState* script_state) {
+                               wrapper);
+ }
+ 
++bool DOMArrayBuffer::IsDetached() const {
++  if (contents_.BackingStore() == nullptr) {
++    return is_detached_;
++  }
++  if (is_detached_) {
++    return true;
++  }
++
++  v8::Isolate* isolate = v8::Isolate::GetCurrent();
++  v8::HandleScope handle_scope(isolate);
++  v8::LocalVector<v8::ArrayBuffer> buffer_handles(isolate);
++  AccumulateArrayBuffersForAllWorlds(isolate, this, buffer_handles);
++
++  // There may be several v8::ArrayBuffers corresponding to the DOMArrayBuffer,
++  // but at most one of them may be non-detached.
++  int nondetached_count = 0;
++  int detached_count = 0;
++
++  for (const auto& buffer_handle : buffer_handles) {
++    if (buffer_handle->WasDetached()) {
++      ++detached_count;
++    } else {
++      ++nondetached_count;
++    }
++  }
++  // This CHECK fires even though it should not. TODO(330759272): Investigate
++  // under which conditions we end up with multiple non-detached JSABs for the
++  // same DOMAB and potentially restore this check.
++
++  // CHECK_LE(nondetached_count, 1);
++
++  return nondetached_count == 0 && detached_count > 0;
++}
++
++v8::Local<v8::Object> DOMArrayBuffer::AssociateWithWrapper(
++    v8::Isolate* isolate,
++    const WrapperTypeInfo* wrapper_type_info,
++    v8::Local<v8::Object> wrapper) {
++  if (!DOMWrapperWorld::Current(isolate).IsMainWorld()) {
++    has_non_main_world_wrappers_ = true;
++  }
++  return ScriptWrappable::AssociateWithWrapper(isolate, wrapper_type_info,
++                                               wrapper);
++}
++
+ DOMArrayBuffer* DOMArrayBuffer::Slice(size_t begin, size_t end) const {
+   begin = std::min(begin, ByteLength());
+   end = std::min(end, ByteLength());
+diff --git a/third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h b/third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h
+index 17d75fe891a78ffa480207a2b595b9f942ca5e38..881497e93dd6bec0f2f0908068d72dbf7b072362 100644
+--- a/third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h
++++ b/third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h
+@@ -87,6 +87,17 @@ class CORE_EXPORT DOMArrayBuffer : public DOMArrayBufferBase {
+ 
+   void Trace(Visitor*) const override;
+ 
++  bool IsDetached() const override;
++
++  v8::Local<v8::Object> AssociateWithWrapper(
++      v8::Isolate* isolate,
++      const WrapperTypeInfo* wrapper_type_info,
++      v8::Local<v8::Object> wrapper) override;
++
++  bool has_non_main_world_wrappers() const {
++    return has_non_main_world_wrappers_;
++  }
++
+  private:
+   v8::Maybe<bool> TransferDetachable(v8::Isolate*,
+                                      v8::Local<v8::Value> detach_key,
+@@ -97,6 +108,8 @@ class CORE_EXPORT DOMArrayBuffer : public DOMArrayBufferBase {
+   // support only v8::String as the detach key type. It's also convenient that
+   // we can write `array_buffer->SetDetachKey(isolate, "my key")`.
+   TraceWrapperV8Reference<v8::String> detach_key_;
++
++  bool has_non_main_world_wrappers_ = false;
+ };
+ 
+ }  // namespace blink
+diff --git a/third_party/blink/renderer/core/typed_arrays/dom_array_buffer_base.h b/third_party/blink/renderer/core/typed_arrays/dom_array_buffer_base.h
+index 95511438595715d030e5f18760b210cf7e58311a..985044ccc1de97dca903b22e5f41e55be52f2533 100644
+--- a/third_party/blink/renderer/core/typed_arrays/dom_array_buffer_base.h
++++ b/third_party/blink/renderer/core/typed_arrays/dom_array_buffer_base.h
+@@ -27,7 +27,9 @@ class CORE_EXPORT DOMArrayBufferBase : public ScriptWrappable {
+ 
+   size_t ByteLength() const { return contents_.DataLength(); }
+ 
+-  bool IsDetached() const { return is_detached_; }
++  // TODO(331348222): It doesn't make sense to detach DomSharedArrayBuffers,
++  // remove that possibility.
++  virtual bool IsDetached() const { return is_detached_; }
+ 
+   void Detach() { is_detached_ = true; }
+ 
+diff --git a/third_party/blink/renderer/modules/gamepad/BUILD.gn b/third_party/blink/renderer/modules/gamepad/BUILD.gn
+index 572d8ce27fa808707ae17ed05f14e2ed103f131e..a871cbd002795bf49ad48f0002ac4996135f8b10 100644
+--- a/third_party/blink/renderer/modules/gamepad/BUILD.gn
++++ b/third_party/blink/renderer/modules/gamepad/BUILD.gn
+@@ -55,6 +55,7 @@ source_set("unit_tests") {
+     "//testing/gtest",
+     "//third_party/blink/renderer/modules",
+     "//third_party/blink/renderer/platform",
++    "//third_party/blink/renderer/platform:test_support",
+     "//third_party/blink/renderer/platform/wtf",
+   ]
+ }
+diff --git a/third_party/blink/renderer/modules/gamepad/gamepad_comparisons_test.cc b/third_party/blink/renderer/modules/gamepad/gamepad_comparisons_test.cc
+index e0a7f48630ba423b19641232c026d72ba71dfc4b..c1efb58ef0e682763735e07711ffa43b2532104b 100644
+--- a/third_party/blink/renderer/modules/gamepad/gamepad_comparisons_test.cc
++++ b/third_party/blink/renderer/modules/gamepad/gamepad_comparisons_test.cc
+@@ -243,27 +243,27 @@ class GamepadComparisonsTest : public testing::Test {
+   }
+ };
+ 
+-TEST_F(GamepadComparisonsTest, EmptyListCausesNoActivation) {
++TEST_F(GamepadComparisonsTest, DISABLED_EmptyListCausesNoActivation) {
+   auto list = CreateEmptyGamepadList();
+   EXPECT_FALSE(GamepadComparisons::HasUserActivation(list));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, NeutralGamepadCausesNoActivation) {
++TEST_F(GamepadComparisonsTest, DISABLED_NeutralGamepadCausesNoActivation) {
+   auto list = CreateGamepadListWithNeutralGamepad();
+   EXPECT_FALSE(GamepadComparisons::HasUserActivation(list));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, AxisTiltCausesNoActivation) {
++TEST_F(GamepadComparisonsTest, DISABLED_AxisTiltCausesNoActivation) {
+   auto list = CreateGamepadListWithAxisTilt();
+   EXPECT_FALSE(GamepadComparisons::HasUserActivation(list));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, ButtonDownCausesActivation) {
++TEST_F(GamepadComparisonsTest, DISABLED_ButtonDownCausesActivation) {
+   auto list = CreateGamepadListWithButtonDown();
+   EXPECT_TRUE(GamepadComparisons::HasUserActivation(list));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareEmptyLists) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareEmptyLists) {
+   // Simulate no connected gamepads.
+   auto list1 = CreateEmptyGamepadList();
+   auto list2 = CreateEmptyGamepadList();
+@@ -278,7 +278,7 @@ TEST_F(GamepadComparisonsTest, CompareEmptyLists) {
+   EXPECT_FALSE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareNeutrals) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareNeutrals) {
+   // Simulate a neutral gamepad with no input changes.
+   auto list1 = CreateGamepadListWithNeutralGamepad();
+   auto list2 = CreateGamepadListWithNeutralGamepad();
+@@ -293,7 +293,7 @@ TEST_F(GamepadComparisonsTest, CompareNeutrals) {
+   EXPECT_FALSE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareEmptyListWithNeutral) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareEmptyListWithNeutral) {
+   // Simulate a connection.
+   auto list1 = CreateEmptyGamepadList();
+   auto list2 = CreateGamepadListWithNeutralGamepad();
+@@ -308,7 +308,7 @@ TEST_F(GamepadComparisonsTest, CompareEmptyListWithNeutral) {
+   EXPECT_FALSE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareNeutralWithEmptyList) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareNeutralWithEmptyList) {
+   // Simulate a disconnection.
+   auto list1 = CreateGamepadListWithNeutralGamepad();
+   auto list2 = CreateEmptyGamepadList();
+@@ -323,7 +323,7 @@ TEST_F(GamepadComparisonsTest, CompareNeutralWithEmptyList) {
+   EXPECT_FALSE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareNeutralWithAxisTilt) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareNeutralWithAxisTilt) {
+   // Simulate tilting an axis away from neutral.
+   auto list1 = CreateGamepadListWithNeutralGamepad();
+   auto list2 = CreateGamepadListWithAxisTilt();
+@@ -351,7 +351,7 @@ TEST_F(GamepadComparisonsTest, CompareNeutralWithAxisTilt) {
+   EXPECT_FALSE(compareResult2.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareNeutralWithButtonDown) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareNeutralWithButtonDown) {
+   // Simulate pressing a digital (on/off) button.
+   auto list1 = CreateGamepadListWithNeutralGamepad();
+   auto list2 = CreateGamepadListWithButtonDown();
+@@ -379,7 +379,7 @@ TEST_F(GamepadComparisonsTest, CompareNeutralWithButtonDown) {
+   EXPECT_FALSE(compareResult2.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareButtonDownWithNeutral) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareButtonDownWithNeutral) {
+   // Simulate releasing a digital (on/off) button.
+   auto list1 = CreateGamepadListWithButtonDown();
+   auto list2 = CreateGamepadListWithNeutralGamepad();
+@@ -395,7 +395,7 @@ TEST_F(GamepadComparisonsTest, CompareButtonDownWithNeutral) {
+   EXPECT_TRUE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareNeutralWithButtonTouched) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareNeutralWithButtonTouched) {
+   // Simulate touching an analog button or trigger.
+   auto list1 = CreateGamepadListWithNeutralGamepad();
+   auto list2 = CreateGamepadListWithButtonTouched();
+@@ -411,7 +411,8 @@ TEST_F(GamepadComparisonsTest, CompareNeutralWithButtonTouched) {
+   EXPECT_FALSE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareButtonTouchedWithButtonJustDown) {
++TEST_F(GamepadComparisonsTest,
++       DISABLED_CompareButtonTouchedWithButtonJustDown) {
+   // Simulate pressing an analog button or trigger enough to register a button
+   // press.
+   auto list1 = CreateGamepadListWithButtonTouched();
+@@ -428,7 +429,7 @@ TEST_F(GamepadComparisonsTest, CompareButtonTouchedWithButtonJustDown) {
+   EXPECT_FALSE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareButtonJustDownWithButtonDown) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareButtonJustDownWithButtonDown) {
+   // Simulate continuing to press an analog button or trigger until it reaches
+   // the maximum value.
+   auto list1 = CreateGamepadListWithButtonJustDown();
+@@ -445,7 +446,7 @@ TEST_F(GamepadComparisonsTest, CompareButtonJustDownWithButtonDown) {
+   EXPECT_FALSE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareButtonDownWithButtonJustDown) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareButtonDownWithButtonJustDown) {
+   // Simulate releasing an analog button or trigger until it is just barely
+   // pressed.
+   auto list1 = CreateGamepadListWithButtonDown();
+@@ -462,7 +463,8 @@ TEST_F(GamepadComparisonsTest, CompareButtonDownWithButtonJustDown) {
+   EXPECT_FALSE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareButtonJustDownWithButtonTouched) {
++TEST_F(GamepadComparisonsTest,
++       DISABLED_CompareButtonJustDownWithButtonTouched) {
+   // Simulate releasing an analog button or trigger until it is no longer
+   // pressed.
+   auto list1 = CreateGamepadListWithButtonJustDown();
+@@ -479,7 +481,7 @@ TEST_F(GamepadComparisonsTest, CompareButtonJustDownWithButtonTouched) {
+   EXPECT_TRUE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareButtonTouchedWithNeutral) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareButtonTouchedWithNeutral) {
+   // Simulate releasing an analog button or trigger until it is neutral.
+   auto list1 = CreateGamepadListWithButtonTouched();
+   auto list2 = CreateGamepadListWithNeutralGamepad();
+@@ -495,7 +497,7 @@ TEST_F(GamepadComparisonsTest, CompareButtonTouchedWithNeutral) {
+   EXPECT_FALSE(compareResult.IsButtonUp(0, 0));
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareDifferentTouch) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareDifferentTouch) {
+   auto list1 = CreateGamepadListWithTopLeftTouch();
+   auto list2 = CreateGamepadListWithCenterTouch();
+ 
+@@ -504,7 +506,7 @@ TEST_F(GamepadComparisonsTest, CompareDifferentTouch) {
+   EXPECT_TRUE(compareResult.IsDifferent());
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareDifferentSurface) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareDifferentSurface) {
+   auto list1 = CreateGamepadListWithTopLeftTouch();
+   auto list2 = CreateGamepadListWithTopLeftTouchSurface1();
+ 
+@@ -513,7 +515,7 @@ TEST_F(GamepadComparisonsTest, CompareDifferentSurface) {
+   EXPECT_TRUE(compareResult.IsDifferent());
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareDifferentTouchId) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareDifferentTouchId) {
+   auto list1 = CreateGamepadListWithTopLeftTouchesTouchId1();
+   auto list2 = CreateGamepadListWithTopLeftTouchesTouchId3();
+ 
+@@ -523,7 +525,7 @@ TEST_F(GamepadComparisonsTest, CompareDifferentTouchId) {
+   EXPECT_TRUE(compareResult.IsDifferent());
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareSameTouch1) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareSameTouch1) {
+   auto list1 = CreateGamepadListWithTopLeftTouch();
+ 
+   auto compareResult = GamepadComparisons::Compare(
+@@ -531,7 +533,7 @@ TEST_F(GamepadComparisonsTest, CompareSameTouch1) {
+   EXPECT_FALSE(compareResult.IsDifferent());
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareSameTouch2) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareSameTouch2) {
+   auto list1 = CreateGamepadListWithTopLeftTouchesTouchId3();
+ 
+   auto compareResult = GamepadComparisons::Compare(
+@@ -539,7 +541,7 @@ TEST_F(GamepadComparisonsTest, CompareSameTouch2) {
+   EXPECT_FALSE(compareResult.IsDifferent());
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareSurfaceNoSurfaceTouch) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareSurfaceNoSurfaceTouch) {
+   auto list1 = CreateGamepadListWithTopLeftTouchSurface1();
+   auto list2 = CreateGamepadListWithTopLeftTouch();
+ 
+@@ -548,7 +550,7 @@ TEST_F(GamepadComparisonsTest, CompareSurfaceNoSurfaceTouch) {
+   EXPECT_TRUE(compareResult.IsDifferent());
+ }
+ 
+-TEST_F(GamepadComparisonsTest, CompareDifferentSurfaceTouch) {
++TEST_F(GamepadComparisonsTest, DISABLED_CompareDifferentSurfaceTouch) {
+   auto list1 = CreateGamepadListWithTopLeftTouchSurface1();
+   auto list2 = CreateGamepadListWithTopLeftTouchSurface2();
+