Do not use DOMGuarded for maplike
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Dec 2019 19:10:42 +0000 (19:10 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Dec 2019 19:10:42 +0000 (19:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204879

Reviewed by Darin Adler.

Update maplike according setlike model where we support syncing at creation of the JS wrapper
and syncing whenever setlike/maplike methods are called.
Removing DOMGuardedObject makes implementation more lightweight, there is less things to implement on DOM side
and it allows collecting the private map to free memory if needed.

Covered by existing tests and rebased binding tests.

* Modules/highlight/HighlightMap.cpp:
(WebCore::HighlightMap::initializeMapLike):
* Modules/highlight/HighlightMap.h:
(WebCore::HighlightMap::synchronizeBackingMap): Deleted.
(WebCore::HighlightMap::backingMap): Deleted.
* Modules/mediastream/RTCStatsReport.h:
(WebCore::RTCStatsReport::create):
(WebCore::RTCStatsReport::initializeMapLike):
(WebCore::RTCStatsReport::RTCStatsReport):
(WebCore::RTCStatsReport::synchronizeBackingMap): Deleted.
(WebCore::RTCStatsReport::backingMap): Deleted.
(WebCore::RTCStatsReport::addStats): Deleted.
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::LibWebRTCMediaEndpoint::createStatsCollector):
* Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.cpp:
(WebCore::LibWebRTCStatsCollector::~LibWebRTCStatsCollector):
(WebCore::initializeRTCStatsReportBackingMap):
(WebCore::LibWebRTCStatsCollector::OnStatsDelivered):
* Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.h:
* bindings/js/JSDOMMapLike.cpp:
(WebCore::getBackingMap):
(WebCore::clearBackingMap):
(WebCore::setToBackingMap):
(WebCore::forwardAttributeGetterToBackingMap):
(WebCore::forwardFunctionCallToBackingMap):
(WebCore::forwardForEachCallToBackingMap):
(WebCore::initializeBackingMap): Deleted.
(WebCore::createBackingMap): Deleted.
* bindings/js/JSDOMMapLike.h:
(WebCore::DOMMapAdapter::DOMMapAdapter):
(WebCore::DOMMapAdapter::set):
(WebCore::DOMMapAdapter::clear):
(WebCore::getAndInitializeBackingMap):
(WebCore::forwardSizeToMapLike):
(WebCore::forwardEntriesToMapLike):
(WebCore::forwardKeysToMapLike):
(WebCore::forwardValuesToMapLike):
(WebCore::forwardClearToMapLike):
(WebCore::forwardForEachToMapLike):
(WebCore::forwardGetToMapLike):
(WebCore::forwardHasToMapLike):
(WebCore::forwardSetToMapLike):
(WebCore::forwardDeleteToMapLike):
(): Deleted.
(WebCore::DOMMapLike::set): Deleted.
(WebCore::synchronizeBackingMap): Deleted.
* bindings/js/JSDOMSetLike.cpp:
* bindings/js/JSDOMSetLike.h:
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
* bindings/scripts/test/JS/JSMapLike.cpp:
(WebCore::JSMapLike::finishCreation):
* bindings/scripts/test/JS/JSReadOnlyMapLike.cpp:
(WebCore::JSReadOnlyMapLike::finishCreation):
* testing/InternalsMapLike.cpp:
(WebCore::InternalsMapLike::initializeMapLike):
(WebCore::InternalsMapLike::synchronizeBackingMap): Deleted.
* testing/InternalsMapLike.h:
(WebCore::InternalsMapLike::backingMap): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253276 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/highlight/HighlightMap.cpp
Source/WebCore/Modules/highlight/HighlightMap.h
Source/WebCore/Modules/mediastream/RTCStatsReport.h
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.h
Source/WebCore/bindings/js/JSDOMMapLike.cpp
Source/WebCore/bindings/js/JSDOMMapLike.h
Source/WebCore/bindings/js/JSDOMSetLike.cpp
Source/WebCore/bindings/js/JSDOMSetLike.h
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSMapLike.cpp
Source/WebCore/bindings/scripts/test/JS/JSReadOnlyMapLike.cpp
Source/WebCore/testing/InternalsMapLike.cpp
Source/WebCore/testing/InternalsMapLike.h

index 66b7607..4fc503d 100644 (file)
@@ -1,5 +1,79 @@
 2019-12-08  youenn fablet  <youenn@apple.com>
 
+        Do not use DOMGuarded for maplike
+        https://bugs.webkit.org/show_bug.cgi?id=204879
+
+        Reviewed by Darin Adler.
+
+        Update maplike according setlike model where we support syncing at creation of the JS wrapper
+        and syncing whenever setlike/maplike methods are called.
+        Removing DOMGuardedObject makes implementation more lightweight, there is less things to implement on DOM side
+        and it allows collecting the private map to free memory if needed.
+
+        Covered by existing tests and rebased binding tests.
+
+        * Modules/highlight/HighlightMap.cpp:
+        (WebCore::HighlightMap::initializeMapLike):
+        * Modules/highlight/HighlightMap.h:
+        (WebCore::HighlightMap::synchronizeBackingMap): Deleted.
+        (WebCore::HighlightMap::backingMap): Deleted.
+        * Modules/mediastream/RTCStatsReport.h:
+        (WebCore::RTCStatsReport::create):
+        (WebCore::RTCStatsReport::initializeMapLike):
+        (WebCore::RTCStatsReport::RTCStatsReport):
+        (WebCore::RTCStatsReport::synchronizeBackingMap): Deleted.
+        (WebCore::RTCStatsReport::backingMap): Deleted.
+        (WebCore::RTCStatsReport::addStats): Deleted.
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::LibWebRTCMediaEndpoint::createStatsCollector):
+        * Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.cpp:
+        (WebCore::LibWebRTCStatsCollector::~LibWebRTCStatsCollector):
+        (WebCore::initializeRTCStatsReportBackingMap):
+        (WebCore::LibWebRTCStatsCollector::OnStatsDelivered):
+        * Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.h:
+        * bindings/js/JSDOMMapLike.cpp:
+        (WebCore::getBackingMap):
+        (WebCore::clearBackingMap):
+        (WebCore::setToBackingMap):
+        (WebCore::forwardAttributeGetterToBackingMap):
+        (WebCore::forwardFunctionCallToBackingMap):
+        (WebCore::forwardForEachCallToBackingMap):
+        (WebCore::initializeBackingMap): Deleted.
+        (WebCore::createBackingMap): Deleted.
+        * bindings/js/JSDOMMapLike.h:
+        (WebCore::DOMMapAdapter::DOMMapAdapter):
+        (WebCore::DOMMapAdapter::set):
+        (WebCore::DOMMapAdapter::clear):
+        (WebCore::getAndInitializeBackingMap):
+        (WebCore::forwardSizeToMapLike):
+        (WebCore::forwardEntriesToMapLike):
+        (WebCore::forwardKeysToMapLike):
+        (WebCore::forwardValuesToMapLike):
+        (WebCore::forwardClearToMapLike):
+        (WebCore::forwardForEachToMapLike):
+        (WebCore::forwardGetToMapLike):
+        (WebCore::forwardHasToMapLike):
+        (WebCore::forwardSetToMapLike):
+        (WebCore::forwardDeleteToMapLike):
+        (): Deleted.
+        (WebCore::DOMMapLike::set): Deleted.
+        (WebCore::synchronizeBackingMap): Deleted.
+        * bindings/js/JSDOMSetLike.cpp:
+        * bindings/js/JSDOMSetLike.h:
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation):
+        * bindings/scripts/test/JS/JSMapLike.cpp:
+        (WebCore::JSMapLike::finishCreation):
+        * bindings/scripts/test/JS/JSReadOnlyMapLike.cpp:
+        (WebCore::JSReadOnlyMapLike::finishCreation):
+        * testing/InternalsMapLike.cpp:
+        (WebCore::InternalsMapLike::initializeMapLike):
+        (WebCore::InternalsMapLike::synchronizeBackingMap): Deleted.
+        * testing/InternalsMapLike.h:
+        (WebCore::InternalsMapLike::backingMap): Deleted.
+
+2019-12-08  youenn fablet  <youenn@apple.com>
+
         Support different resolutions for video tracks captured from UIProcess
         https://bugs.webkit.org/show_bug.cgi?id=204945
 
index b248ef7..433cd6e 100644 (file)
@@ -26,6 +26,9 @@
 #include "config.h"
 #include "HighlightMap.h"
 
+#include "JSDOMMapLike.h"
+#include "JSHighlightRangeGroup.h"
+
 namespace WebCore {
 
 void HighlightMap::addHighlightGroup(String& cssStyle, HighlightRangeGroup &group)
@@ -34,6 +37,12 @@ void HighlightMap::addHighlightGroup(String& cssStyle, HighlightRangeGroup &grou
     UNUSED_PARAM(group);
 }
 
+void HighlightMap::initializeMapLike(DOMMapAdapter& map)
+{
+    for (auto& keyValue : m_map)
+        map.set<IDLDOMString, IDLInterface<HighlightRangeGroup>>(keyValue.key, keyValue.value);
+}
+
 void HighlightMap::setFromMapLike(String&&, Ref<HighlightRangeGroup>&&)
 {
 }
index 641e24b..69a70b0 100644 (file)
 #pragma once
 
 #include "HighlightRangeGroup.h"
-#include "JSDOMMapLike.h"
 #include <wtf/HashMap.h>
 #include <wtf/RefCounted.h>
 
 namespace WebCore {
 
+class DOMMapAdapter;
 class DOMString;
 class HighlightRangeGroup;
 
 class HighlightMap : public RefCounted<HighlightMap> {
 public:
     static Ref<HighlightMap> create() { return adoptRef(*new HighlightMap); }
-    
+
     void addHighlightGroup(String&, HighlightRangeGroup&);
-    
-    void synchronizeBackingMap(Ref<DOMMapLike>&& mapLike) { m_mapLike = WTFMove(mapLike); }
-    DOMMapLike* backingMap() { return m_mapLike.get(); }
+    void initializeMapLike(DOMMapAdapter&);
 
     // Bindings support.
     String namedItem(const AtomString& name) const;
@@ -55,8 +53,7 @@ public:
     
 private:
     HighlightMap() = default;
-    HashMap<String, RefPtr<HighlightRangeGroup>> m_map;
-    RefPtr<DOMMapLike> m_mapLike;
+    HashMap<String, Ref<HighlightRangeGroup>> m_map;
 };
 
 }
index a8be605..ad73219 100644 (file)
 
 #pragma once
 
-#include "JSDOMMapLike.h"
+#include "LibWebRTCStatsCollector.h"
 
 namespace WebCore {
 
+class DOMMapAdapter;
+
 class RTCStatsReport : public RefCounted<RTCStatsReport> {
 public:
-    static Ref<RTCStatsReport> create() { return adoptRef(*new RTCStatsReport); }
-
-    void synchronizeBackingMap(Ref<DOMMapLike>&& mapLike) { m_mapLike = WTFMove(mapLike); }
-    DOMMapLike* backingMap() { return m_mapLike.get(); }
-
-    template<typename Value> void addStats(typename Value::ParameterType&& value) { m_mapLike->set<IDLDOMString, Value>(value.id, std::forward<typename Value::ParameterType>(value)); }
+    using MapInitializer = Function<void(DOMMapAdapter&)>;
+    static Ref<RTCStatsReport> create(MapInitializer&& mapInitializer) { return adoptRef(*new RTCStatsReport(WTFMove(mapInitializer))); }
 
+    void initializeMapLike(DOMMapAdapter& adapter) { m_mapInitializer(adapter); }
 
     enum class Type {
         Codec,
@@ -236,10 +235,14 @@ public:
     };
 
 private:
-    RTCStatsReport() = default;
+    explicit RTCStatsReport(MapInitializer&&);
 
-private:
-    RefPtr<DOMMapLike> m_mapLike;
+    MapInitializer m_mapInitializer;
 };
 
+inline RTCStatsReport::RTCStatsReport(MapInitializer&& mapInitializer)
+    : m_mapInitializer(WTFMove(mapInitializer))
+{
+}
+
 } // namespace WebCore
index 388731f..5def1c1 100644 (file)
@@ -286,19 +286,12 @@ void LibWebRTCMediaEndpoint::doCreateAnswer()
 
 rtc::scoped_refptr<LibWebRTCStatsCollector> LibWebRTCMediaEndpoint::createStatsCollector(Ref<DeferredPromise>&& promise)
 {
-    return LibWebRTCStatsCollector::create([promise = WTFMove(promise), protectedThis = makeRef(*this)]() mutable -> RefPtr<RTCStatsReport> {
+    return LibWebRTCStatsCollector::create([promise = WTFMove(promise), protectedThis = makeRef(*this)](auto&& report) mutable {
         ASSERT(isMainThread());
-        if (protectedThis->isStopped())
-            return nullptr;
-
-        auto report = RTCStatsReport::create();
-
-        promise->resolve<IDLInterface<RTCStatsReport>>(report.copyRef());
+        if (protectedThis->isStopped() || !report)
+            return;
 
-        // The promise resolution might fail in which case no backing map will be created.
-        if (!report->backingMap())
-            return nullptr;
-        return report;
+        promise->resolve<IDLInterface<RTCStatsReport>>(report.releaseNonNull());
     });
 }
 
index 62ad823..8a67c07 100644 (file)
@@ -27,6 +27,7 @@
 
 #if USE(LIBWEBRTC)
 
+#include "JSDOMMapLike.h"
 #include "JSRTCStatsReport.h"
 #include "Performance.h"
 #include <wtf/MainThread.h>
@@ -44,7 +45,7 @@ LibWebRTCStatsCollector::~LibWebRTCStatsCollector()
         return;
 
     callOnMainThread([callback = WTFMove(m_callback)]() mutable {
-        callback();
+        callback(nullptr);
     });
 }
 
@@ -380,58 +381,60 @@ static inline void fillRTCPeerConnectionStats(RTCStatsReport::PeerConnectionStat
         stats.dataChannelsClosed = *rtcStats.data_channels_closed;
 }
 
-void LibWebRTCStatsCollector::OnStatsDelivered(const rtc::scoped_refptr<const webrtc::RTCStatsReport>& rtcReport)
+static inline void initializeRTCStatsReportBackingMap(DOMMapAdapter& report, const webrtc::RTCStatsReport& rtcReport)
 {
-    callOnMainThread([protectedThis = rtc::scoped_refptr<LibWebRTCStatsCollector>(this), rtcReport] {
-        auto report = protectedThis->m_callback();
-        if (!report)
-            return;
-
-        ASSERT(report->backingMap());
-
-        for (const auto& rtcStats : *rtcReport) {
-            if (rtcStats.type() == webrtc::RTCInboundRTPStreamStats::kType) {
-                RTCStatsReport::InboundRTPStreamStats stats;
-                fillInboundRTPStreamStats(stats, static_cast<const webrtc::RTCInboundRTPStreamStats&>(rtcStats));
-                report->addStats<IDLDictionary<RTCStatsReport::InboundRTPStreamStats>>(WTFMove(stats));
-            } else if (rtcStats.type() == webrtc::RTCOutboundRTPStreamStats::kType) {
-                RTCStatsReport::OutboundRTPStreamStats stats;
-                fillOutboundRTPStreamStats(stats, static_cast<const webrtc::RTCOutboundRTPStreamStats&>(rtcStats));
-                report->addStats<IDLDictionary<RTCStatsReport::OutboundRTPStreamStats>>(WTFMove(stats));
-            } else if (rtcStats.type() == webrtc::RTCMediaStreamTrackStats::kType) {
-                RTCStatsReport::MediaStreamTrackStats stats;
-                fillRTCMediaStreamTrackStats(stats, static_cast<const webrtc::RTCMediaStreamTrackStats&>(rtcStats));
-                report->addStats<IDLDictionary<RTCStatsReport::MediaStreamTrackStats>>(WTFMove(stats));
-            } else if (rtcStats.type() == webrtc::RTCDataChannelStats::kType) {
-                RTCStatsReport::DataChannelStats stats;
-                fillRTCDataChannelStats(stats, static_cast<const webrtc::RTCDataChannelStats&>(rtcStats));
-                report->addStats<IDLDictionary<RTCStatsReport::DataChannelStats>>(WTFMove(stats));
-            } else if (rtcStats.type() == webrtc::RTCIceCandidatePairStats::kType) {
-                RTCStatsReport::IceCandidatePairStats stats;
-                fillRTCIceCandidatePairStats(stats, static_cast<const webrtc::RTCIceCandidatePairStats&>(rtcStats));
-                report->addStats<IDLDictionary<RTCStatsReport::IceCandidatePairStats>>(WTFMove(stats));
-            } else if (rtcStats.type() == webrtc::RTCRemoteIceCandidateStats::kType || rtcStats.type() == webrtc::RTCLocalIceCandidateStats::kType) {
-                RTCStatsReport::IceCandidateStats stats;
-                fillRTCIceCandidateStats(stats, static_cast<const webrtc::RTCIceCandidateStats&>(rtcStats));
-                report->addStats<IDLDictionary<RTCStatsReport::IceCandidateStats>>(WTFMove(stats));
-            } else if (rtcStats.type() == webrtc::RTCCertificateStats::kType) {
-                RTCStatsReport::CertificateStats stats;
-                fillRTCCertificateStats(stats, static_cast<const webrtc::RTCCertificateStats&>(rtcStats));
-                report->addStats<IDLDictionary<RTCStatsReport::CertificateStats>>(WTFMove(stats));
-            } else if (rtcStats.type() == webrtc::RTCCodecStats::kType) {
-                RTCStatsReport::CodecStats stats;
-                fillRTCCodecStats(stats, static_cast<const webrtc::RTCCodecStats&>(rtcStats));
-                report->addStats<IDLDictionary<RTCStatsReport::CodecStats>>(WTFMove(stats));
-            } else if (rtcStats.type() == webrtc::RTCTransportStats::kType) {
-                RTCStatsReport::TransportStats stats;
-                fillRTCTransportStats(stats, static_cast<const webrtc::RTCTransportStats&>(rtcStats));
-                report->addStats<IDLDictionary<RTCStatsReport::TransportStats>>(WTFMove(stats));
-            } else if (rtcStats.type() == webrtc::RTCPeerConnectionStats::kType) {
-                RTCStatsReport::PeerConnectionStats stats;
-                fillRTCPeerConnectionStats(stats, static_cast<const webrtc::RTCPeerConnectionStats&>(rtcStats));
-                report->addStats<IDLDictionary<RTCStatsReport::PeerConnectionStats>>(WTFMove(stats));
-            }
+    for (const auto& rtcStats : rtcReport) {
+        if (rtcStats.type() == webrtc::RTCInboundRTPStreamStats::kType) {
+            RTCStatsReport::InboundRTPStreamStats stats;
+            fillInboundRTPStreamStats(stats, static_cast<const webrtc::RTCInboundRTPStreamStats&>(rtcStats));
+            report.set<IDLDOMString, IDLDictionary<RTCStatsReport::InboundRTPStreamStats>>(stats.id, WTFMove(stats));
+        } else if (rtcStats.type() == webrtc::RTCOutboundRTPStreamStats::kType) {
+            RTCStatsReport::OutboundRTPStreamStats stats;
+            fillOutboundRTPStreamStats(stats, static_cast<const webrtc::RTCOutboundRTPStreamStats&>(rtcStats));
+            report.set<IDLDOMString, IDLDictionary<RTCStatsReport::OutboundRTPStreamStats>>(stats.id, WTFMove(stats));
+        } else if (rtcStats.type() == webrtc::RTCMediaStreamTrackStats::kType) {
+            RTCStatsReport::MediaStreamTrackStats stats;
+            fillRTCMediaStreamTrackStats(stats, static_cast<const webrtc::RTCMediaStreamTrackStats&>(rtcStats));
+            report.set<IDLDOMString, IDLDictionary<RTCStatsReport::MediaStreamTrackStats>>(stats.id, WTFMove(stats));
+        } else if (rtcStats.type() == webrtc::RTCDataChannelStats::kType) {
+            RTCStatsReport::DataChannelStats stats;
+            fillRTCDataChannelStats(stats, static_cast<const webrtc::RTCDataChannelStats&>(rtcStats));
+            report.set<IDLDOMString, IDLDictionary<RTCStatsReport::DataChannelStats>>(stats.id, WTFMove(stats));
+        } else if (rtcStats.type() == webrtc::RTCIceCandidatePairStats::kType) {
+            RTCStatsReport::IceCandidatePairStats stats;
+            fillRTCIceCandidatePairStats(stats, static_cast<const webrtc::RTCIceCandidatePairStats&>(rtcStats));
+            report.set<IDLDOMString, IDLDictionary<RTCStatsReport::IceCandidatePairStats>>(stats.id, WTFMove(stats));
+        } else if (rtcStats.type() == webrtc::RTCRemoteIceCandidateStats::kType || rtcStats.type() == webrtc::RTCLocalIceCandidateStats::kType) {
+            RTCStatsReport::IceCandidateStats stats;
+            fillRTCIceCandidateStats(stats, static_cast<const webrtc::RTCIceCandidateStats&>(rtcStats));
+            report.set<IDLDOMString, IDLDictionary<RTCStatsReport::IceCandidateStats>>(stats.id, WTFMove(stats));
+        } else if (rtcStats.type() == webrtc::RTCCertificateStats::kType) {
+            RTCStatsReport::CertificateStats stats;
+            fillRTCCertificateStats(stats, static_cast<const webrtc::RTCCertificateStats&>(rtcStats));
+            report.set<IDLDOMString, IDLDictionary<RTCStatsReport::CertificateStats>>(stats.id, WTFMove(stats));
+        } else if (rtcStats.type() == webrtc::RTCCodecStats::kType) {
+            RTCStatsReport::CodecStats stats;
+            fillRTCCodecStats(stats, static_cast<const webrtc::RTCCodecStats&>(rtcStats));
+            report.set<IDLDOMString, IDLDictionary<RTCStatsReport::CodecStats>>(stats.id, WTFMove(stats));
+        } else if (rtcStats.type() == webrtc::RTCTransportStats::kType) {
+            RTCStatsReport::TransportStats stats;
+            fillRTCTransportStats(stats, static_cast<const webrtc::RTCTransportStats&>(rtcStats));
+            report.set<IDLDOMString, IDLDictionary<RTCStatsReport::TransportStats>>(stats.id, WTFMove(stats));
+        } else if (rtcStats.type() == webrtc::RTCPeerConnectionStats::kType) {
+            RTCStatsReport::PeerConnectionStats stats;
+            fillRTCPeerConnectionStats(stats, static_cast<const webrtc::RTCPeerConnectionStats&>(rtcStats));
+            report.set<IDLDOMString, IDLDictionary<RTCStatsReport::PeerConnectionStats>>(stats.id, WTFMove(stats));
         }
+    }
+}
+
+void LibWebRTCStatsCollector::OnStatsDelivered(const rtc::scoped_refptr<const webrtc::RTCStatsReport>& rtcReport)
+{
+    callOnMainThread([this, protectedThis = rtc::scoped_refptr<LibWebRTCStatsCollector>(this), rtcReport]() {
+        m_callback(RTCStatsReport::create([rtcReport](auto& mapAdapter) {
+            if (rtcReport)
+                initializeRTCStatsReportBackingMap(mapAdapter, *rtcReport);
+        }));
     });
 }
 
index 32ad87f..f2b42ca 100644 (file)
@@ -38,11 +38,14 @@ ALLOW_UNUSED_PARAMETERS_END
 
 namespace WebCore {
 
+class DOMMapAdapter;
 class RTCStatsReport;
 
+void initializeRTCStatsReportBackingMap(RTCStatsReport&);
+
 class LibWebRTCStatsCollector : public webrtc::RTCStatsCollectorCallback {
 public:
-    using CollectorCallback = CompletionHandler<RefPtr<RTCStatsReport>()>;
+    using CollectorCallback = CompletionHandler<void(RefPtr<RTCStatsReport>&&)>;
     static rtc::scoped_refptr<LibWebRTCStatsCollector> create(CollectorCallback&& callback) { return new rtc::RefCountedObject<LibWebRTCStatsCollector>(WTFMove(callback)); }
 
     explicit LibWebRTCStatsCollector(CollectorCallback&&);
index f7e61fe..eb09fe7 100644 (file)
 
 #include "WebCoreJSClientData.h"
 #include <JavaScriptCore/CatchScope.h>
+#include <JavaScriptCore/JSMap.h>
 
 namespace WebCore {
 
-static inline JSC::JSObject& getBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject& mapLike)
+std::pair<bool, std::reference_wrapper<JSC::JSObject>> getBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject& mapLike)
 {
     auto& vm = lexicalGlobalObject.vm();
     auto backingMap = mapLike.get(&lexicalGlobalObject, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().backingMapPrivateName());
-    return *JSC::asObject(backingMap);
+    if (!backingMap.isUndefined())
+        return { false, *JSC::asObject(backingMap) };
+
+    auto scope = DECLARE_CATCH_SCOPE(vm);
+
+    backingMap = JSC::JSMap::create(&lexicalGlobalObject, vm, lexicalGlobalObject.mapStructure());
+    scope.releaseAssertNoException();
+
+    mapLike.putDirect(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().backingMapPrivateName(), backingMap, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum));
+    return { true, *JSC::asObject(backingMap) };
 }
 
-void initializeBackingMap(JSC::VM& vm, JSC::JSObject& mapLike, JSC::JSMap& backingMap)
+void clearBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject& backingMap)
 {
-    mapLike.putDirect(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().backingMapPrivateName(), &backingMap, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum));
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    auto function = backingMap.get(&lexicalGlobalObject, vm.propertyNames->clear);
+
+    JSC::CallData callData;
+    auto callType = JSC::getCallData(vm, function, callData);
+    if (callType == JSC::CallType::None)
+        return;
+
+    JSC::MarkedArgumentBuffer arguments;
+    JSC::call(&lexicalGlobalObject, function, callType, callData, &backingMap, arguments);
 }
 
-JSC::JSMap& createBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSGlobalObject& globalObject, JSC::JSObject& mapLike)
+void setToBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject& backingMap, JSC::JSValue key, JSC::JSValue value)
 {
-    auto& vm = lexicalGlobalObject.vm();
-    auto scope = DECLARE_CATCH_SCOPE(vm);
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    auto function = backingMap.get(&lexicalGlobalObject, vm.propertyNames->set);
 
-    ASSERT(mapLike.get(&lexicalGlobalObject, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().backingMapPrivateName()).isUndefined());
-    auto backingMap = JSC::JSMap::create(&lexicalGlobalObject, vm, globalObject.mapStructure());
-    scope.releaseAssertNoException();
-    mapLike.putDirect(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().backingMapPrivateName(), backingMap, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum));
-    return *backingMap;
+    JSC::CallData callData;
+    auto callType = JSC::getCallData(vm, function, callData);
+    if (callType == JSC::CallType::None)
+        return;
+
+    JSC::MarkedArgumentBuffer arguments;
+    arguments.append(key);
+    arguments.append(value);
+    JSC::call(&lexicalGlobalObject, function, callType, callData, &backingMap, arguments);
 }
 
-JSC::JSValue forwardAttributeGetterToBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject& mapLike, const JSC::Identifier& attributeName)
+JSC::JSValue forwardAttributeGetterToBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject& backingMap, const JSC::Identifier& attributeName)
 {
-    return getBackingMap(lexicalGlobalObject, mapLike).get(&lexicalGlobalObject, attributeName);
+    return backingMap.get(&lexicalGlobalObject, attributeName);
 }
 
-JSC::JSValue forwardFunctionCallToBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, JSC::JSObject& mapLike, const JSC::Identifier& functionName)
+JSC::JSValue forwardFunctionCallToBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, JSC::JSObject& backingMap, const JSC::Identifier& functionName)
 {
-    auto& backingMap = getBackingMap(lexicalGlobalObject, mapLike);
-
-    JSC::JSValue function = backingMap.get(&lexicalGlobalObject, functionName);
-    ASSERT(function);
+    auto function = backingMap.get(&lexicalGlobalObject, functionName);
 
     JSC::CallData callData;
-    JSC::CallType callType = JSC::getCallData(lexicalGlobalObject.vm(), function, callData);
-    ASSERT(callType != JSC::CallType::None);
+    auto callType = JSC::getCallData(lexicalGlobalObject.vm(), function, callData);
+    if (callType == JSC::CallType::None)
+        return JSC::jsUndefined();
+
     JSC::MarkedArgumentBuffer arguments;
     for (size_t cptr = 0; cptr < callFrame.argumentCount(); ++cptr)
         arguments.append(callFrame.uncheckedArgument(cptr));
@@ -77,21 +99,24 @@ JSC::JSValue forwardFunctionCallToBackingMap(JSC::JSGlobalObject& lexicalGlobalO
     return JSC::call(&lexicalGlobalObject, function, callType, callData, &backingMap, arguments);
 }
 
-JSC::JSValue forwardForEachCallToBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, JSDOMGlobalObject& globalObject, JSC::JSObject& mapLike)
+JSC::JSValue forwardForEachCallToBackingMap(JSDOMGlobalObject& globalObject, JSC::CallFrame& callFrame, JSC::JSObject& mapLike)
 {
     auto* function = globalObject.builtinInternalFunctions().jsDOMBindingInternals().m_mapLikeForEachFunction.get();
     ASSERT(function);
 
-    getBackingMap(lexicalGlobalObject, mapLike);
-
     JSC::CallData callData;
-    JSC::CallType callType = JSC::getCallData(lexicalGlobalObject.vm(), function, callData);
+    auto callType = JSC::getCallData(globalObject.vm(), function, callData);
     ASSERT(callType != JSC::CallType::None);
     JSC::MarkedArgumentBuffer arguments;
     for (size_t cptr = 0; cptr < callFrame.argumentCount(); ++cptr)
         arguments.append(callFrame.uncheckedArgument(cptr));
     ASSERT(!arguments.hasOverflowed());
-    return JSC::call(&lexicalGlobalObject, function, callType, callData, &mapLike, arguments);
+    return JSC::call(&globalObject, function, callType, callData, &mapLike, arguments);
+}
+
+void DOMMapAdapter::clear()
+{
+    clearBackingMap(m_lexicalGlobalObject, m_backingMap);
 }
 
 }
index e8f5e03..0953a04 100644 (file)
 
 #include "JSDOMBinding.h"
 #include "JSDOMConvert.h"
-#include "JSDOMGuardedObject.h"
 #include <JavaScriptCore/BuiltinNames.h>
 #include <JavaScriptCore/CommonIdentifiers.h>
-#include <JavaScriptCore/JSMap.h>
 
 namespace WebCore {
 
-WEBCORE_EXPORT JSC::JSMap& createBackingMap(JSC::JSGlobalObject&, JSC::JSGlobalObject&, JSC::JSObject&);
-WEBCORE_EXPORT void initializeBackingMap(JSC::VM&, JSC::JSObject&, JSC::JSMap&);
+WEBCORE_EXPORT std::pair<bool, std::reference_wrapper<JSC::JSObject>> getBackingMap(JSC::JSGlobalObject&, JSC::JSObject& mapLike);
 WEBCORE_EXPORT JSC::JSValue forwardAttributeGetterToBackingMap(JSC::JSGlobalObject&, JSC::JSObject&, const JSC::Identifier&);
 WEBCORE_EXPORT JSC::JSValue forwardFunctionCallToBackingMap(JSC::JSGlobalObject&, JSC::CallFrame&, JSC::JSObject&, const JSC::Identifier&);
-WEBCORE_EXPORT JSC::JSValue forwardForEachCallToBackingMap(JSC::JSGlobalObject&, JSC::CallFrame&, JSDOMGlobalObject&, JSC::JSObject&);
+WEBCORE_EXPORT JSC::JSValue forwardForEachCallToBackingMap(JSDOMGlobalObject&, JSC::CallFrame&, JSC::JSObject&);
+WEBCORE_EXPORT void clearBackingMap(JSC::JSGlobalObject&, JSC::JSObject&);
+WEBCORE_EXPORT void setToBackingMap(JSC::JSGlobalObject&, JSC::JSObject&, JSC::JSValue, JSC::JSValue);
 
-template<typename WrapperClass> void synchronizeBackingMap(JSC::JSGlobalObject&, JSDOMGlobalObject&, WrapperClass&);
 template<typename WrapperClass> JSC::JSValue forwardSizeToMapLike(JSC::JSGlobalObject&, WrapperClass&);
 template<typename WrapperClass> JSC::JSValue forwardEntriesToMapLike(JSC::JSGlobalObject&, JSC::CallFrame&, WrapperClass&);
 template<typename WrapperClass> JSC::JSValue forwardKeysToMapLike(JSC::JSGlobalObject&, JSC::CallFrame&, WrapperClass&);
@@ -52,100 +50,107 @@ template<typename WrapperClass, typename ItemType> JSC::JSValue forwardHasToMapL
 template<typename WrapperClass, typename ItemType, typename ValueType> JSC::JSValue forwardSetToMapLike(JSC::JSGlobalObject&, JSC::CallFrame&, WrapperClass&, ItemType&&, ValueType&&);
 template<typename WrapperClass, typename ItemType> JSC::JSValue forwardDeleteToMapLike(JSC::JSGlobalObject&, JSC::CallFrame&, WrapperClass&, ItemType&&);
 
-class DOMMapLike final : public DOMGuarded<JSC::JSMap> {
+class DOMMapAdapter {
 public:
-    static Ref<DOMMapLike> create(JSDOMGlobalObject& globalObject, JSC::JSMap& map) { return adoptRef(*new DOMMapLike(globalObject, map)); }
+    DOMMapAdapter(JSC::JSGlobalObject&, JSC::JSObject&);
+    template<typename IDLKeyType, typename IDLValueType> void set(typename IDLKeyType::ParameterType, typename IDLValueType::ParameterType);
+    void clear();
 
-    template<typename Key, typename Value> void set(typename Key::ParameterType, typename Value::ParameterType);
-
-    JSC::JSMap* backingMap() { return guarded(); }
-
-protected:
-    DOMMapLike(JSDOMGlobalObject& globalObject, JSC::JSMap& map) : DOMGuarded<JSC::JSMap>(globalObject, map) { }
+private:
+    JSC::JSGlobalObject& m_lexicalGlobalObject;
+    JSC::JSObject& m_backingMap;
 };
 
-template<typename Key, typename Value> inline void DOMMapLike::set(typename Key::ParameterType key, typename Value::ParameterType value)
+inline DOMMapAdapter::DOMMapAdapter(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSObject& backingMap)
+    : m_lexicalGlobalObject(lexicalGlobalObject)
+    , m_backingMap(backingMap)
 {
-    if (isEmpty())
-        return;
-    auto* lexicalGlobalObject = globalObject();
-    JSC::JSLockHolder locker(lexicalGlobalObject);
-    backingMap()->set(lexicalGlobalObject,
-        toJS<Key>(*lexicalGlobalObject, *globalObject(), std::forward<typename Key::ParameterType>(key)),
-        toJS<Value>(*lexicalGlobalObject, *globalObject(), std::forward<typename Value::ParameterType>(value)));
 }
 
-template<typename WrapperClass> inline void synchronizeBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, WrapperClass& mapLike)
+template<typename IDLKeyType, typename IDLValueType>
+void DOMMapAdapter::set(typename IDLKeyType::ParameterType key, typename IDLValueType::ParameterType value)
 {
-    auto backingMap = mapLike.wrapped().backingMap();
-    if (backingMap) {
-        ASSERT(backingMap->backingMap());
-        initializeBackingMap(JSC::getVM(&lexicalGlobalObject), mapLike, *backingMap->backingMap());
-        return;
+    JSC::JSLockHolder locker(&m_lexicalGlobalObject);
+    auto jsKey = toJS<IDLKeyType>(m_lexicalGlobalObject, *JSC::jsCast<JSDOMGlobalObject*>(&m_lexicalGlobalObject), std::forward<typename IDLKeyType::ParameterType>(key));
+    auto jsValue = toJS<IDLValueType>(m_lexicalGlobalObject, *JSC::jsCast<JSDOMGlobalObject*>(&m_lexicalGlobalObject), std::forward<typename IDLValueType::ParameterType>(value));
+    setToBackingMap(m_lexicalGlobalObject, m_backingMap, jsKey, jsValue);
+}
+
+template<typename WrapperClass> JSC::JSObject& getAndInitializeBackingMap(JSC::JSGlobalObject& lexicalGlobalObject, WrapperClass& mapLike)
+{
+    auto pair = getBackingMap(lexicalGlobalObject, mapLike);
+    if (pair.first) {
+        DOMMapAdapter adapter { lexicalGlobalObject, pair.second.get() };
+        mapLike.wrapped().initializeMapLike(adapter);
     }
-    auto& map = createBackingMap(lexicalGlobalObject, globalObject, mapLike);
-    mapLike.wrapped().synchronizeBackingMap(DOMMapLike::create(globalObject, map));
+    return pair.second.get();
 }
 
-template<typename WrapperClass> inline JSC::JSValue forwardSizeToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, WrapperClass& mapLike)
+template<typename WrapperClass> JSC::JSValue forwardSizeToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, WrapperClass& mapLike)
 {
-    JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);
-    return forwardAttributeGetterToBackingMap(lexicalGlobalObject, mapLike, vm.propertyNames->size);
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    return forwardAttributeGetterToBackingMap(lexicalGlobalObject, getAndInitializeBackingMap(lexicalGlobalObject, mapLike), vm.propertyNames->size);
 }
 
-template<typename WrapperClass> inline JSC::JSValue forwardEntriesToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike)
+template<typename WrapperClass> JSC::JSValue forwardEntriesToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike)
 {
-    JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);
-    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, mapLike, vm.propertyNames->builtinNames().entriesPublicName());
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, getAndInitializeBackingMap(lexicalGlobalObject, mapLike), vm.propertyNames->builtinNames().entriesPublicName());
 }
 
-template<typename WrapperClass> inline JSC::JSValue forwardKeysToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike)
+template<typename WrapperClass> JSC::JSValue forwardKeysToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike)
 {
-    JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);
-    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, mapLike, vm.propertyNames->builtinNames().keysPublicName());
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, getAndInitializeBackingMap(lexicalGlobalObject, mapLike), vm.propertyNames->builtinNames().keysPublicName());
 }
 
-template<typename WrapperClass> inline JSC::JSValue forwardValuesToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike)
+template<typename WrapperClass> JSC::JSValue forwardValuesToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike)
 {
-    JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);
-    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, mapLike, vm.propertyNames->builtinNames().valuesPublicName());
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, getAndInitializeBackingMap(lexicalGlobalObject, mapLike), vm.propertyNames->builtinNames().valuesPublicName());
 }
 
-template<typename WrapperClass> inline JSC::JSValue forwardClearToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike)
+template<typename WrapperClass> JSC::JSValue forwardClearToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike)
 {
     mapLike.wrapped().clear();
-    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, mapLike, JSC::getVM(&lexicalGlobalObject).propertyNames->clear);
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, getAndInitializeBackingMap(lexicalGlobalObject, mapLike), vm.propertyNames->clear);
 }
 
-template<typename WrapperClass, typename Callback> inline JSC::JSValue forwardForEachToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike, Callback&&)
+template<typename WrapperClass, typename Callback> JSC::JSValue forwardForEachToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike, Callback&&)
 {
-    return forwardForEachCallToBackingMap(lexicalGlobalObject, callFrame, *mapLike.globalObject(), mapLike);
+    getAndInitializeBackingMap(lexicalGlobalObject, mapLike);
+    return forwardForEachCallToBackingMap(*JSC::jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject), callFrame, mapLike);
 }
 
-template<typename WrapperClass, typename ItemType> inline JSC::JSValue forwardGetToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike, ItemType&&)
+template<typename WrapperClass, typename ItemType> JSC::JSValue forwardGetToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike, ItemType&&)
 {
-    JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);
-    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, mapLike, vm.propertyNames->builtinNames().getPublicName());
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, getAndInitializeBackingMap(lexicalGlobalObject, mapLike), vm.propertyNames->builtinNames().getPublicName());
 }
 
-template<typename WrapperClass, typename ItemType> inline JSC::JSValue forwardHasToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike, ItemType&&)
+template<typename WrapperClass, typename ItemType> JSC::JSValue forwardHasToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike, ItemType&&)
 {
-    JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);
-    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, mapLike, vm.propertyNames->builtinNames().hasPublicName());
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    return forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, getAndInitializeBackingMap(lexicalGlobalObject, mapLike), vm.propertyNames->builtinNames().hasPublicName());
 }
 
-template<typename WrapperClass, typename KeyType, typename ValueType> inline JSC::JSValue forwardSetToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike, KeyType&& key, ValueType&& value)
+template<typename WrapperClass, typename KeyType, typename ValueType> JSC::JSValue forwardSetToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike, KeyType&& key, ValueType&& value)
 {
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
     mapLike.wrapped().setFromMapLike(std::forward<KeyType>(key), std::forward<ValueType>(value));
-    forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, mapLike, JSC::getVM(&lexicalGlobalObject).propertyNames->set);
+    forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, getAndInitializeBackingMap(lexicalGlobalObject, mapLike), vm.propertyNames->set);
     return &mapLike;
 }
 
-template<typename WrapperClass, typename ItemType> inline JSC::JSValue forwardDeleteToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike, ItemType&& item)
+template<typename WrapperClass, typename ItemType> JSC::JSValue forwardDeleteToMapLike(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, WrapperClass& mapLike, ItemType&& item)
 {
     auto isDeleted = mapLike.wrapped().remove(std::forward<ItemType>(item));
     UNUSED_PARAM(isDeleted);
-    auto result = forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, mapLike, JSC::getVM(&lexicalGlobalObject).propertyNames->deleteKeyword);
+
+    auto& vm = JSC::getVM(&lexicalGlobalObject);
+    auto result = forwardFunctionCallToBackingMap(lexicalGlobalObject, callFrame, getAndInitializeBackingMap(lexicalGlobalObject, mapLike), vm.propertyNames->deleteKeyword);
+
     ASSERT_UNUSED(result, result.asBoolean() == isDeleted);
     return result;
 }
index f1fab31..1de7a81 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "WebCoreJSClientData.h"
 #include <JavaScriptCore/CatchScope.h>
+#include <JavaScriptCore/JSSet.h>
 
 namespace WebCore {
 
index c81ea1d..1188b36 100644 (file)
@@ -30,7 +30,6 @@
 #include "JSDOMGlobalObject.h"
 #include <JavaScriptCore/BuiltinNames.h>
 #include <JavaScriptCore/CommonIdentifiers.h>
-#include <JavaScriptCore/JSSet.h>
 
 namespace WebCore {
 
index d578626..2fc466e 100644 (file)
@@ -4404,10 +4404,6 @@ sub GenerateImplementation
         push(@implContent, "    putDirect(vm, vm.propertyNames->toPrimitiveSymbol, jsUndefined(), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);\n");
     }
 
-    if ($interface->mapLike) {
-        push(@implContent, "    synchronizeBackingMap(*globalObject(), *globalObject(), *this);\n");
-    }
-
     # Support for RuntimeEnabled attributes on instances.
     foreach my $attribute (@{$interface->attributes}) {
         next unless NeedsRuntimeCheck($interface, $attribute);
index d10d088..d68deaf 100644 (file)
@@ -144,7 +144,6 @@ void JSMapLike::finishCreation(VM& vm)
 
     static_assert(!std::is_base_of<ActiveDOMObject, MapLike>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");
 
-    synchronizeBackingMap(*globalObject(), *globalObject(), *this);
 }
 
 JSObject* JSMapLike::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
index 3e65dd7..e8a0da3 100644 (file)
@@ -138,7 +138,6 @@ void JSReadOnlyMapLike::finishCreation(VM& vm)
 
     static_assert(!std::is_base_of<ActiveDOMObject, ReadOnlyMapLike>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");
 
-    synchronizeBackingMap(*globalObject(), *globalObject(), *this);
 }
 
 JSObject* JSReadOnlyMapLike::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
index f1f8e3d..43dfed4 100644 (file)
@@ -27,9 +27,8 @@
 #include "InternalsMapLike.h"
 
 #include "IDLTypes.h"
-#include <wtf/HashMap.h>
+#include "JSDOMMapLike.h"
 #include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -38,11 +37,10 @@ InternalsMapLike::InternalsMapLike()
     m_values.add("init", 0);
 }
 
-void InternalsMapLike::synchronizeBackingMap(Ref<DOMMapLike>&& mapLike)
+void InternalsMapLike::initializeMapLike(DOMMapAdapter& map)
 {
-    m_mapLike = WTFMove(mapLike);
     for (auto& keyValue : m_values)
-        m_mapLike->set<IDLDOMString, IDLUnsignedLong>(keyValue.key, keyValue.value);
+        map.set<IDLDOMString, IDLUnsignedLong>(keyValue.key, keyValue.value);
 }
 
 void InternalsMapLike::setFromMapLike(String&& key, unsigned value)
index b733f5c..1172ee4 100644 (file)
 
 #pragma once
 
-#include "JSDOMMapLike.h"
 #include <wtf/Forward.h>
+#include <wtf/HashMap.h>
 #include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
+class DOMMapAdapter;
+
 class InternalsMapLike : public RefCounted<InternalsMapLike> {
 public:
     static Ref<InternalsMapLike> create() { return adoptRef(*new InternalsMapLike); }
 
+    void initializeMapLike(DOMMapAdapter&);
     void setFromMapLike(String&&, unsigned);
     void clear();
     bool remove(const String&);
 
-    void synchronizeBackingMap(Ref<DOMMapLike>&&);
-    DOMMapLike* backingMap() { return m_mapLike.get(); }
-
     Vector<String> inspectKeys() const;
     Vector<unsigned> inspectValues() const;
 
 private:
     InternalsMapLike();
     HashMap<String, unsigned> m_values;
-    RefPtr<DOMMapLike> m_mapLike;
 };
 
 } // namespace WebCore