From 94658a20fef01d70f0ecd0e49ee197c399e61b59 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Wed, 5 Feb 2020 22:08:39 +0000 Subject: [PATCH] Bug 1611855 - Worklet must be part of the same parent's agentCluster - part 3 - update the scope after a writing, r=smaug Differential Revision: https://phabricator.services.mozilla.com/D61183 --HG-- extra : moz-landing-system : lando --- dom/base/StructuredCloneHolder.cpp | 4 ++++ js/public/StructuredClone.h | 5 +++++ js/src/vm/StructuredClone.cpp | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dom/base/StructuredCloneHolder.cpp b/dom/base/StructuredCloneHolder.cpp index cb0989f2b459..75120329fd71 100644 --- a/dom/base/StructuredCloneHolder.cpp +++ b/dom/base/StructuredCloneHolder.cpp @@ -193,6 +193,10 @@ bool StructuredCloneHolderBase::Write( return false; } + // Let's update our scope to the final one. The new one could be more + // restrictive of the current one. + MOZ_ASSERT(mStructuredCloneScope >= mBuffer->scope()); + mStructuredCloneScope = mBuffer->scope(); return true; } diff --git a/js/public/StructuredClone.h b/js/public/StructuredClone.h index df262d3e2c23..723efb040073 100644 --- a/js/public/StructuredClone.h +++ b/js/public/StructuredClone.h @@ -552,6 +552,11 @@ class MOZ_NON_MEMMOVABLE JS_PUBLIC_API JSStructuredCloneData { } void discardTransferables(); + + private: + // This internal method exposes the real value of scope_. It's meant to be + // used only when starting the writing. + JS::StructuredCloneScope scopeForInternalWriting() const { return scope_; } }; /** diff --git a/js/src/vm/StructuredClone.cpp b/js/src/vm/StructuredClone.cpp index 39a34c7e695a..2e943b2897c0 100644 --- a/js/src/vm/StructuredClone.cpp +++ b/js/src/vm/StructuredClone.cpp @@ -3211,9 +3211,9 @@ bool JSAutoStructuredCloneBuffer::write( const JS::CloneDataPolicy& cloneDataPolicy, const JSStructuredCloneCallbacks* optionalCallbacks, void* closure) { clear(); - bool ok = - JS_WriteStructuredClone(cx, value, &data_, data_.scope(), cloneDataPolicy, - optionalCallbacks, closure, transferable); + bool ok = JS_WriteStructuredClone( + cx, value, &data_, data_.scopeForInternalWriting(), cloneDataPolicy, + optionalCallbacks, closure, transferable); if (ok) { data_.ownTransferables_ = OwnTransferablePolicy::OwnsTransferablesIfAny;