Title: [234789] trunk
Revision
234789
Author
[email protected]
Date
2018-08-12 17:02:19 -0700 (Sun, 12 Aug 2018)

Log Message

Break reference cycle in ErrorEvent by using JSValueInWrappedObject
https://bugs.webkit.org/show_bug.cgi?id=188491

Reviewed by Darin Adler.

Source/WebCore:

ErrorEvent should not use Strong<Unkonwn> to hold error JSValue. This patch integrates
JSValueInWrappedObject into ErrorEvent.

* Modules/webvr/VRDisplayEvent.h:
Fix unified build errors due to added JSErrorEventCustom.cpp. It changes the files grouped in unified build.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSErrorEventCustom.cpp: Copied from Source/WebCore/Modules/webvr/VRDisplayEvent.h.
(WebCore::JSErrorEvent::visitAdditionalChildren):
Add custom mark function for JSValueInWrappedObject.

* bindings/js/JSEventListener.h:
* bindings/js/WindowProxy.cpp:
Fix unified build errors due to added JSErrorEventCustom.cpp. It changes the files grouped in unified build.

* dom/ErrorEvent.cpp:
(WebCore::ErrorEvent::ErrorEvent):
(WebCore::ErrorEvent::error):
(WebCore::ErrorEvent::trySerializeError):
Align the implementation to PushStateEvent::trySerializeState.

* dom/ErrorEvent.h:
* dom/ErrorEvent.idl:

LayoutTests:

* fast/dom/reference-cycle-leaks-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (234788 => 234789)


--- trunk/LayoutTests/ChangeLog	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/LayoutTests/ChangeLog	2018-08-13 00:02:19 UTC (rev 234789)
@@ -1,3 +1,12 @@
+2018-08-12  Yusuke Suzuki  <[email protected]>
+
+        Break reference cycle in ErrorEvent by using JSValueInWrappedObject
+        https://bugs.webkit.org/show_bug.cgi?id=188491
+
+        Reviewed by Darin Adler.
+
+        * fast/dom/reference-cycle-leaks-expected.txt:
+
 2018-08-12  Aditya Keerthi  <[email protected]>
 
         [macOS] Color wells should appear pressed when presenting a color picker

Modified: trunk/LayoutTests/fast/dom/reference-cycle-leaks-expected.txt (234788 => 234789)


--- trunk/LayoutTests/fast/dom/reference-cycle-leaks-expected.txt	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/LayoutTests/fast/dom/reference-cycle-leaks-expected.txt	2018-08-13 00:02:19 UTC (rev 234789)
@@ -10,7 +10,7 @@
 PASS checkForNodeLeaks(createTreeWalkerFilterCycle) is "did not leak"
 PASS checkForNodeLeaks(createPromiseCycle) is "did not leak"
 PASS checkForNodeLeaks(createCustomEventDetailsCycle) is "did not leak"
-FAIL checkForNodeLeaks(createErrorEventDataCycle) should be did not leak. Was leaked.
+PASS checkForNodeLeaks(createErrorEventDataCycle) is "did not leak"
 ---- Did not test ExtendableMessageEvent because it is not enabled.
 PASS checkForNodeLeaks(createMessageEventDataCycle) is "did not leak"
 PASS checkForNodeLeaks(createPopStateEventStateCycle) is "did not leak"

Modified: trunk/Source/WebCore/ChangeLog (234788 => 234789)


--- trunk/Source/WebCore/ChangeLog	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/Source/WebCore/ChangeLog	2018-08-13 00:02:19 UTC (rev 234789)
@@ -1,3 +1,35 @@
+2018-08-12  Yusuke Suzuki  <[email protected]>
+
+        Break reference cycle in ErrorEvent by using JSValueInWrappedObject
+        https://bugs.webkit.org/show_bug.cgi?id=188491
+
+        Reviewed by Darin Adler.
+
+        ErrorEvent should not use Strong<Unkonwn> to hold error JSValue. This patch integrates
+        JSValueInWrappedObject into ErrorEvent.
+
+        * Modules/webvr/VRDisplayEvent.h:
+        Fix unified build errors due to added JSErrorEventCustom.cpp. It changes the files grouped in unified build.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSErrorEventCustom.cpp: Copied from Source/WebCore/Modules/webvr/VRDisplayEvent.h.
+        (WebCore::JSErrorEvent::visitAdditionalChildren):
+        Add custom mark function for JSValueInWrappedObject.
+
+        * bindings/js/JSEventListener.h:
+        * bindings/js/WindowProxy.cpp:
+        Fix unified build errors due to added JSErrorEventCustom.cpp. It changes the files grouped in unified build.
+
+        * dom/ErrorEvent.cpp:
+        (WebCore::ErrorEvent::ErrorEvent):
+        (WebCore::ErrorEvent::error):
+        (WebCore::ErrorEvent::trySerializeError):
+        Align the implementation to PushStateEvent::trySerializeState.
+
+        * dom/ErrorEvent.h:
+        * dom/ErrorEvent.idl:
+
 2018-08-12  Aditya Keerthi  <[email protected]>
 
         [macOS] Color wells should appear pressed when presenting a color picker

Modified: trunk/Source/WebCore/Modules/webvr/VRDisplayEvent.h (234788 => 234789)


--- trunk/Source/WebCore/Modules/webvr/VRDisplayEvent.h	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/Source/WebCore/Modules/webvr/VRDisplayEvent.h	2018-08-13 00:02:19 UTC (rev 234789)
@@ -25,12 +25,11 @@
 #pragma once
 
 #include "Event.h"
+#include "VRDisplay.h"
 #include "VRDisplayEventReason.h"
 
 namespace WebCore {
 
-class VRDisplay;
-
 class VRDisplayEvent final : public Event {
 public:
     static Ref<VRDisplayEvent> create(const AtomicString& type, const RefPtr<VRDisplay>& display, std::optional<VRDisplayEventReason>&& reason)

Modified: trunk/Source/WebCore/Sources.txt (234788 => 234789)


--- trunk/Source/WebCore/Sources.txt	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/Source/WebCore/Sources.txt	2018-08-13 00:02:19 UTC (rev 234789)
@@ -397,6 +397,7 @@
 bindings/js/JSDocumentCustom.cpp
 bindings/js/JSDocumentFragmentCustom.cpp
 bindings/js/JSElementCustom.cpp
+bindings/js/JSErrorEventCustom.cpp
 bindings/js/JSErrorHandler.cpp
 bindings/js/JSEventCustom.cpp
 bindings/js/JSEventListener.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (234788 => 234789)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-08-13 00:02:19 UTC (rev 234789)
@@ -7170,6 +7170,7 @@
 		3FFFF9AC159D9B060020BBD5 /* ViewportStyleResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewportStyleResolver.h; sourceTree = "<group>"; };
 		4107908A1FC3E4F20061B27A /* ClientOrigin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClientOrigin.h; sourceTree = "<group>"; };
 		410B7E711045FAB000D8224F /* JSMessageEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMessageEventCustom.cpp; sourceTree = "<group>"; };
+		D2CDB5ED638F43AF86F07AA2 /* JSErrorEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSErrorEventCustom.cpp; sourceTree = "<group>"; };
 		41103AA71E39790A00769F03 /* RealtimeOutgoingAudioSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeOutgoingAudioSource.cpp; sourceTree = "<group>"; };
 		41103AA71E39790A00769F14 /* RealtimeOutgoingAudioSourceCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeOutgoingAudioSourceCocoa.cpp; sourceTree = "<group>"; };
 		41103AA81E39790A00769F03 /* RealtimeOutgoingAudioSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeOutgoingAudioSource.h; sourceTree = "<group>"; };
@@ -19890,6 +19891,7 @@
 				0F94A3951EF1B10500FBAFFB /* JSDOMQuadCustom.cpp */,
 				BC2ED5540C6B9BD300920BFF /* JSElementCustom.cpp */,
 				ADEC78F718EE5308001315C2 /* JSElementCustom.h */,
+				D2CDB5ED638F43AF86F07AA2 /* JSErrorEventCustom.cpp */,
 				BCEFAF4D0C317E6900FA81F6 /* JSEventCustom.cpp */,
 				E34EE49F1DC2D57500EAA9D3 /* JSEventCustom.h */,
 				BC60901E0E91B8EC000C68B5 /* JSEventTargetCustom.cpp */,

Copied: trunk/Source/WebCore/bindings/js/JSErrorEventCustom.cpp (from rev 234788, trunk/Source/WebCore/Modules/webvr/VRDisplayEvent.h) (0 => 234789)


--- trunk/Source/WebCore/bindings/js/JSErrorEventCustom.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSErrorEventCustom.cpp	2018-08-13 00:02:19 UTC (rev 234789)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2018 Yusuke Suzuki <[email protected]>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSErrorEvent.h"
+
+namespace WebCore {
+
+void JSErrorEvent::visitAdditionalChildren(JSC::SlotVisitor& visitor)
+{
+    wrapped().originalError().visit(visitor);
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/JSEventListener.h (234788 => 234789)


--- trunk/Source/WebCore/bindings/js/JSEventListener.h	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/Source/WebCore/bindings/js/JSEventListener.h	2018-08-13 00:02:19 UTC (rev 234789)
@@ -32,6 +32,7 @@
 namespace WebCore {
 
 class DOMWindow;
+class Document;
 class EventTarget;
 class HTMLElement;
 

Modified: trunk/Source/WebCore/bindings/js/WindowProxy.cpp (234788 => 234789)


--- trunk/Source/WebCore/bindings/js/WindowProxy.cpp	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/Source/WebCore/bindings/js/WindowProxy.cpp	2018-08-13 00:02:19 UTC (rev 234789)
@@ -36,6 +36,8 @@
 
 namespace WebCore {
 
+using namespace JSC;
+
 static void collectGarbageAfterWindowProxyDestruction()
 {
     // Make sure to GC Extra Soon(tm) during memory pressure conditions

Modified: trunk/Source/WebCore/dom/ErrorEvent.cpp (234788 => 234789)


--- trunk/Source/WebCore/dom/ErrorEvent.cpp	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/Source/WebCore/dom/ErrorEvent.cpp	2018-08-13 00:02:19 UTC (rev 234789)
@@ -40,13 +40,13 @@
 namespace WebCore {
 using namespace JSC;
 
-ErrorEvent::ErrorEvent(ExecState& state, const AtomicString& type, const Init& initializer, IsTrusted isTrusted)
+ErrorEvent::ErrorEvent(const AtomicString& type, const Init& initializer, IsTrusted isTrusted)
     : Event(type, initializer, isTrusted)
     , m_message(initializer.message)
     , m_fileName(initializer.filename)
     , m_lineNumber(initializer.lineno)
     , m_columnNumber(initializer.colno)
-    , m_error(state.vm(), initializer.error)
+    , m_error(initializer.error)
 {
 }
 
@@ -56,7 +56,7 @@
     , m_fileName(fileName)
     , m_lineNumber(lineNumber)
     , m_columnNumber(columnNumber)
-    , m_error(error)
+    , m_error(error.get())
 {
 }
 
@@ -69,7 +69,7 @@
 
 JSValue ErrorEvent::error(ExecState& state, JSGlobalObject& globalObject)
 {    
-    auto error = m_error.get();
+    JSValue error = m_error;
     if (!error)
         return jsNull();
 
@@ -87,11 +87,11 @@
 
 RefPtr<SerializedScriptValue> ErrorEvent::trySerializeError(ExecState& exec)
 {
-    if (!m_triedToSerialize) {
-        m_serializedDetail = SerializedScriptValue::create(exec, m_error.get(), SerializationErrorMode::NonThrowing);
+    if (!m_serializedError && !m_triedToSerialize) {
+        m_serializedError = SerializedScriptValue::create(exec, m_error, SerializationErrorMode::NonThrowing);
         m_triedToSerialize = true;
     }
-    return m_serializedDetail;
+    return m_serializedError;
 }
 
 bool ErrorEvent::isErrorEvent() const

Modified: trunk/Source/WebCore/dom/ErrorEvent.h (234788 => 234789)


--- trunk/Source/WebCore/dom/ErrorEvent.h	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/Source/WebCore/dom/ErrorEvent.h	2018-08-13 00:02:19 UTC (rev 234789)
@@ -32,6 +32,7 @@
 #pragma once
 
 #include "Event.h"
+#include "JSValueInWrappedObject.h"
 #include "SerializedScriptValue.h"
 #include <_javascript_Core/Strong.h>
 #include <wtf/text/WTFString.h>
@@ -53,9 +54,9 @@
         JSC::JSValue error;
     };
 
-    static Ref<ErrorEvent> create(JSC::ExecState& state, const AtomicString& type, const Init& initializer, IsTrusted isTrusted = IsTrusted::No)
+    static Ref<ErrorEvent> create(const AtomicString& type, const Init& initializer, IsTrusted isTrusted = IsTrusted::No)
     {
-        return adoptRef(*new ErrorEvent(state, type, initializer, isTrusted));
+        return adoptRef(*new ErrorEvent(type, initializer, isTrusted));
     }
 
     virtual ~ErrorEvent();
@@ -66,14 +67,17 @@
     unsigned colno() const { return m_columnNumber; }
     JSC::JSValue error(JSC::ExecState&, JSC::JSGlobalObject&);
 
+    const JSValueInWrappedObject& originalError() const { return m_error; }
+    SerializedScriptValue* serializedError() const { return m_serializedError.get(); }
+
     EventInterface eventInterface() const override;
 
+    RefPtr<SerializedScriptValue> trySerializeError(JSC::ExecState&);
+
 private:
     ErrorEvent(const String& message, const String& fileName, unsigned lineNumber, unsigned columnNumber, JSC::Strong<JSC::Unknown> error);
-    ErrorEvent(JSC::ExecState&, const AtomicString&, const Init&, IsTrusted);
+    ErrorEvent(const AtomicString&, const Init&, IsTrusted);
 
-    RefPtr<SerializedScriptValue> trySerializeError(JSC::ExecState&);
-
     bool isErrorEvent() const override;
 
     String m_message;
@@ -80,10 +84,8 @@
     String m_fileName;
     unsigned m_lineNumber;
     unsigned m_columnNumber;
-    // FIXME: The following use of JSC::Strong is incorrect and can lead to storage leaks
-    // due to reference cycles; we should use JSValueInWrappedObject instead.
-    JSC::Strong<JSC::Unknown> m_error;
-    RefPtr<SerializedScriptValue> m_serializedDetail;
+    JSValueInWrappedObject m_error;
+    RefPtr<SerializedScriptValue> m_serializedError;
     bool m_triedToSerialize { false };
 };
 

Modified: trunk/Source/WebCore/dom/ErrorEvent.idl (234788 => 234789)


--- trunk/Source/WebCore/dom/ErrorEvent.idl	2018-08-12 20:19:25 UTC (rev 234788)
+++ trunk/Source/WebCore/dom/ErrorEvent.idl	2018-08-13 00:02:19 UTC (rev 234789)
@@ -31,8 +31,8 @@
 
 [
     Constructor(DOMString type, optional ErrorEventInit eventInitDict),
-    ConstructorCallWith=ScriptState,
     Exposed=(Window,Worker),
+    JSCustomMarkFunction,
 ] interface ErrorEvent : Event {
     readonly attribute DOMString message;
     readonly attribute USVString filename;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to