From 7a25ca546cdfd751f4f113fa130cd57fe3d09a9a Mon Sep 17 00:00:00 2001 From: roytam1 Date: Wed, 24 Nov 2021 09:53:39 +0800 Subject: [PATCH] import changes from `dev' branch of rmottola/Arctic-Fox: - fix patch ordering coming from PM repo (3a8768f44) - Bug 1119074 - If we're stopping event propagation from XUL popups, also stop them from crossing process boundaries r=smaug,felipe (965e2193e) - Bug 1082145 - |js::WatchGuts| can leak |wpmap|. r=erahm (12c86f3d3) - No Bug - Improve Interpreter stack accessor assertions. (rs=Waldo) (8ba7a702c) - Bug 874842 - Return Event instead of nsIDOMEvent (748b57fd2) - Bug 1165966 - Add test cases r=terrence (79a909d5b) - Bug 1167025: Do not mix bool and int in bitwise-or in blendpsMask; r=sunfish (f0f23c0c4) - Bug 1158323 - Make sure we set a base rect on document elements that have margins set. r=tn (c253a2ef8) - Bug 1178847 - Move the code from ChromeProcessController::InitializeRoot to APZCCallbackHelper so it can be reused in the child process. r=botond (16d539bcb) - Bug 1165966 - Add error checking when populating safepoints r=bhackett (c66d249d1) - spacing and pointer style (cddc1bac4) - Bug 1196027 - check the actual current marking mode instead of the permanent intention, r=terrence (eddcfd7fb) - Bug 1206590: Move gcWeakMapList from JSCompartment to JS::Zone. r=terrence (7e5e0d505) - Bug 1181908 part 1. Fix support for JSOP_OBJECT in scripts parsed on background threads by clearing the unboxedLayouts list on the background thread parsing compartment when merging the parse result to the target compartment. r=jandem (25c6a3b01) - Bug 1163207 - Make RematerializedFrame store the real callee. (r=shu) (ce276e91c) - Bug 1164448 - Handle unwound rectifier frames as exit frames in JitProfilingFrameIterator. r=jandem (bb639b4e2) - Bug 1164448 - Add test. r=jandem (83f5cc608) - Bug 1196497 - Don't assert that the replacer continues to pass IsArray during JSON.stringify. (If the replacer was a revocable proxy to an array, revoking the proxy would make the replacer no longer IsArray.) r=evilpie (442c3823f) - Bug 1177247 - Prevent HandlePossibleViewportChange from clobbering a restored scroll position from forward/back navigation. r=botond (4202ac757) - Bug 1182772, optimize ProcessGlobal out from CC graph (and also TabChild's EventListeners), r=mccr8 (ccb2278bf) - Bug 1139155 - Add a mechanism to know when the APZ is done processing. r=botond (17328e5be) - Bug 1171537 - Allow URIs to be the empty string in TabParent::RecvCreateWindow. r=billm. (e280e994c) - Bug 1173219 - Return nsresults from TabParent::RecvCreateWindow to make opening windows more robust. r=billm (9f0633b15) - Bug 1142817 - Use UniquePtr in testXDR_sourceMap. r=erahm (7ec437162) --- dom/base/DOMRequest.cpp | 5 +- dom/base/EventSource.cpp | 42 +--- dom/base/WebSocket.cpp | 22 +-- dom/base/nsCCUncollectableMarker.cpp | 12 +- dom/base/nsDOMDataChannel.cpp | 19 +- dom/base/nsDocument.cpp | 10 +- dom/base/nsGlobalWindow.cpp | 9 +- dom/base/nsPerformance.cpp | 17 +- dom/base/nsXMLHttpRequest.cpp | 8 +- dom/bluetooth/bluetooth1/BluetoothAdapter.cpp | 7 +- dom/bluetooth/bluetooth2/BluetoothAdapter.cpp | 7 +- dom/bluetooth/bluetooth2/BluetoothGatt.cpp | 12 +- dom/browser-element/BrowserElementParent.cpp | 15 +- dom/events/AnimationEvent.cpp | 12 +- dom/events/AnimationEvent.h | 5 + dom/events/AsyncEventDispatcher.cpp | 11 +- dom/events/BeforeAfterKeyboardEvent.cpp | 12 +- dom/events/BeforeAfterKeyboardEvent.h | 5 + dom/events/BeforeUnloadEvent.cpp | 12 +- dom/events/BeforeUnloadEvent.h | 5 + dom/events/ClipboardEvent.cpp | 12 +- dom/events/ClipboardEvent.h | 5 + dom/events/CommandEvent.cpp | 12 +- dom/events/CommandEvent.h | 5 + dom/events/CompositionEvent.cpp | 10 +- dom/events/CompositionEvent.h | 5 + dom/events/CustomEvent.cpp | 12 +- dom/events/CustomEvent.h | 5 + dom/events/DOMEventTargetHelper.cpp | 3 +- dom/events/DataContainerEvent.cpp | 12 +- dom/events/DataContainerEvent.h | 5 + dom/events/DeviceMotionEvent.cpp | 14 +- dom/events/DeviceMotionEvent.h | 5 + dom/events/DragEvent.cpp | 10 +- dom/events/DragEvent.h | 5 + dom/events/Event.cpp | 18 +- dom/events/Event.h | 6 + dom/events/EventDispatcher.cpp | 138 +++++++------ dom/events/EventDispatcher.h | 12 +- dom/events/EventListenerManager.cpp | 6 +- dom/events/EventStateManager.cpp | 17 +- dom/events/FocusEvent.cpp | 11 +- dom/events/FocusEvent.h | 5 + dom/events/InputEvent.cpp | 11 +- dom/events/InputEvent.h | 5 + dom/events/KeyboardEvent.cpp | 11 +- dom/events/KeyboardEvent.h | 5 + dom/events/MessageEvent.cpp | 13 +- dom/events/MessageEvent.h | 5 + dom/events/MouseEvent.cpp | 11 +- dom/events/MouseEvent.h | 5 + dom/events/MouseScrollEvent.cpp | 12 +- dom/events/MouseScrollEvent.h | 5 + dom/events/MutationEvent.cpp | 11 +- dom/events/MutationEvent.h | 5 + dom/events/NotifyPaintEvent.cpp | 14 +- dom/events/NotifyPaintEvent.h | 8 + dom/events/PointerEvent.cpp | 11 +- dom/events/PointerEvent.h | 5 + dom/events/ScrollAreaEvent.cpp | 10 +- dom/events/ScrollAreaEvent.h | 5 + dom/events/SimpleGestureEvent.cpp | 12 +- dom/events/SimpleGestureEvent.h | 5 + dom/events/StorageEvent.cpp | 15 +- dom/events/StorageEvent.h | 4 +- dom/events/TouchEvent.cpp | 11 +- dom/events/TouchEvent.h | 5 + dom/events/TransitionEvent.cpp | 12 +- dom/events/TransitionEvent.h | 5 + dom/events/UIEvent.cpp | 11 +- dom/events/UIEvent.h | 5 + dom/events/WheelEvent.cpp | 11 +- dom/events/WheelEvent.h | 5 + dom/events/XULCommandEvent.cpp | 12 +- dom/events/XULCommandEvent.h | 5 + dom/events/moz.build | 1 + dom/html/HTMLInputElement.cpp | 14 +- dom/interfaces/events/nsIDOMEvent.idl | 162 +-------------- dom/ipc/PBrowser.ipdl | 5 +- dom/ipc/TabChild.cpp | 29 ++- dom/ipc/TabMessageUtils.cpp | 9 +- dom/ipc/TabParent.cpp | 81 +++++--- dom/ipc/TabParent.h | 1 + dom/media/MediaRecorder.cpp | 7 +- dom/media/TextTrackList.cpp | 9 +- dom/notification/DesktopNotification.cpp | 16 +- dom/notification/Notification.cpp | 3 +- dom/offline/nsDOMOfflineResourceList.cpp | 7 +- dom/presentation/PresentationSession.cpp | 14 +- dom/smil/TimeEvent.cpp | 11 +- dom/smil/TimeEvent.h | 5 + dom/speakermanager/SpeakerManager.cpp | 26 ++- dom/svg/SVGZoomEvent.cpp | 13 +- dom/svg/SVGZoomEvent.h | 5 + dom/workers/ServiceWorkerManager.cpp | 10 +- dom/workers/WorkerPrivate.cpp | 17 +- dom/workers/XMLHttpRequest.cpp | 13 +- dom/xml/nsXMLPrettyPrinter.cpp | 21 +- gfx/layers/apz/src/AsyncPanZoomController.cpp | 1 + gfx/layers/apz/util/APZCCallbackHelper.cpp | 30 +++ gfx/layers/apz/util/APZCCallbackHelper.h | 4 + .../apz/util/ChromeProcessController.cpp | 25 +-- js/src/gc/Marking.cpp | 4 +- js/src/gc/Zone.cpp | 8 + js/src/gc/Zone.h | 4 + js/src/jit-test/tests/gc/bug-1165966.js | 6 + js/src/jit-test/tests/profiler/bug1164448.js | 25 +++ js/src/jit/BacktrackingAllocator.cpp | 15 +- js/src/jit/JitFrames.cpp | 29 +++ js/src/jit/RematerializedFrame.cpp | 7 + js/src/jit/RematerializedFrame.h | 6 +- js/src/jit/x86-shared/Assembler-x86-shared.h | 2 +- js/src/jsapi-tests/testXDR.cpp | 5 +- js/src/jscompartment.cpp | 9 - js/src/jscompartment.h | 4 - js/src/jsgc.cpp | 184 +++++++++--------- js/src/jsobj.cpp | 1 + js/src/json.cpp | 6 +- js/src/jsweakmap.cpp | 47 +++-- js/src/jsweakmap.h | 46 ++--- ...tringify-replacer-array-revocable-proxy.js | 39 ++++ js/src/vm/Debugger.h | 8 +- js/src/vm/Stack.h | 2 +- layout/base/nsPresContext.cpp | 16 +- layout/xul/nsMenuFrame.cpp | 15 +- layout/xul/nsRootBoxFrame.cpp | 8 + layout/xul/nsXULPopupManager.cpp | 12 +- 127 files changed, 966 insertions(+), 931 deletions(-) create mode 100644 js/src/jit-test/tests/gc/bug-1165966.js create mode 100644 js/src/jit-test/tests/profiler/bug1164448.js create mode 100644 js/src/tests/ecma_6/Proxy/json-stringify-replacer-array-revocable-proxy.js diff --git a/dom/base/DOMRequest.cpp b/dom/base/DOMRequest.cpp index 47ca932fe8..7a1461b461 100644 --- a/dom/base/DOMRequest.cpp +++ b/dom/base/DOMRequest.cpp @@ -9,8 +9,8 @@ #include "DOMError.h" #include "nsThreadUtils.h" #include "DOMCursor.h" -#include "nsIDOMEvent.h" #include "mozilla/ErrorResult.h" +#include "mozilla/dom/Event.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/ScriptSettings.h" @@ -185,8 +185,7 @@ DOMRequest::FireEvent(const nsAString& aType, bool aBubble, bool aCancelable) return; } - nsCOMPtr event; - NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); nsresult rv = event->InitEvent(aType, aBubble, aCancelable); if (NS_FAILED(rv)) { return; diff --git a/dom/base/EventSource.cpp b/dom/base/EventSource.cpp index f430487ff5..1f1e1341e6 100644 --- a/dom/base/EventSource.cpp +++ b/dom/base/EventSource.cpp @@ -847,12 +847,7 @@ EventSource::AnnounceConnection() return; } - nsCOMPtr event; - rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - if (NS_FAILED(rv)) { - NS_WARNING("Failed to create the open event!!!"); - return; - } + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); // it doesn't bubble, and it isn't cancelable rv = event->InitEvent(NS_LITERAL_STRING("open"), false, false); @@ -912,12 +907,7 @@ EventSource::ReestablishConnection() return; } - nsCOMPtr event; - rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - if (NS_FAILED(rv)) { - NS_WARNING("Failed to create the error event!!!"); - return; - } + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); // it doesn't bubble, and it isn't cancelable rv = event->InitEvent(NS_LITERAL_STRING("error"), false, false); @@ -1068,12 +1058,7 @@ EventSource::FailConnection() return; } - nsCOMPtr event; - rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - if (NS_FAILED(rv)) { - NS_WARNING("Failed to create the error event!!!"); - return; - } + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); // it doesn't bubble, and it isn't cancelable rv = event->InitEvent(NS_LITERAL_STRING("error"), false, false); @@ -1236,27 +1221,20 @@ EventSource::DispatchAllMessageEvents() // create an event that uses the MessageEvent interface, // which does not bubble, is not cancelable, and has no default action - nsCOMPtr event; - rv = NS_NewDOMMessageEvent(getter_AddRefs(event), this, nullptr, nullptr); - if (NS_FAILED(rv)) { - NS_WARNING("Failed to create the message event!!!"); - return; - } + nsRefPtr event = + NS_NewDOMMessageEvent(this, nullptr, nullptr); - nsCOMPtr messageEvent = do_QueryInterface(event); - rv = messageEvent->InitMessageEvent(message->mEventName, - false, false, - jsData, - mOrigin, - message->mLastEventID, nullptr); + rv = event->InitMessageEvent(message->mEventName, false, false, jsData, + mOrigin, message->mLastEventID, nullptr); if (NS_FAILED(rv)) { NS_WARNING("Failed to init the message event!!!"); return; } - messageEvent->SetTrusted(true); + event->SetTrusted(true); - rv = DispatchDOMEvent(nullptr, event, nullptr, nullptr); + rv = DispatchDOMEvent(nullptr, static_cast(event), nullptr, + nullptr); if (NS_FAILED(rv)) { NS_WARNING("Failed to dispatch the message event!!!"); return; diff --git a/dom/base/WebSocket.cpp b/dom/base/WebSocket.cpp index d71f26d73d..836c317ad7 100644 --- a/dom/base/WebSocket.cpp +++ b/dom/base/WebSocket.cpp @@ -14,6 +14,7 @@ #include "mozilla/DOMEventTargetHelper.h" #include "mozilla/net/WebSocketChannel.h" #include "mozilla/dom/File.h" +#include "mozilla/dom/MessageEvent.h" #include "mozilla/dom/nsCSPContext.h" #include "mozilla/dom/nsCSPUtils.h" #include "mozilla/dom/ScriptSettings.h" @@ -31,7 +32,6 @@ #include "nsIURL.h" #include "nsIUnicodeEncoder.h" #include "nsThreadUtils.h" -#include "nsIDOMMessageEvent.h" #include "nsIPromptFactory.h" #include "nsIWindowWatcher.h" #include "nsIPrompt.h" @@ -1799,9 +1799,7 @@ WebSocket::CreateAndDispatchSimpleEvent(const nsAString& aName) return NS_OK; } - nsCOMPtr event; - rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - NS_ENSURE_SUCCESS(rv, rv); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); // it doesn't bubble, and it isn't cancelable rv = event->InitEvent(aName, false, false); @@ -1879,21 +1877,17 @@ WebSocket::CreateAndDispatchMessageEvent(JSContext* aCx, // create an event that uses the MessageEvent interface, // which does not bubble, is not cancelable, and has no default action - nsCOMPtr event; - rv = NS_NewDOMMessageEvent(getter_AddRefs(event), this, nullptr, nullptr); - NS_ENSURE_SUCCESS(rv, rv); + nsRefPtr event = NS_NewDOMMessageEvent(this, nullptr, nullptr); - nsCOMPtr messageEvent = do_QueryInterface(event); - rv = messageEvent->InitMessageEvent(NS_LITERAL_STRING("message"), - false, false, - jsData, - mImpl->mUTF16Origin, - EmptyString(), nullptr); + rv = event->InitMessageEvent(NS_LITERAL_STRING("message"), false, false, + jsData, mImpl->mUTF16Origin, EmptyString(), + nullptr); NS_ENSURE_SUCCESS(rv, rv); event->SetTrusted(true); - return DispatchDOMEvent(nullptr, event, nullptr, nullptr); + return DispatchDOMEvent(nullptr, static_cast(event), nullptr, + nullptr); } nsresult diff --git a/dom/base/nsCCUncollectableMarker.cpp b/dom/base/nsCCUncollectableMarker.cpp index 616b9858ca..66761ea7ce 100644 --- a/dom/base/nsCCUncollectableMarker.cpp +++ b/dom/base/nsCCUncollectableMarker.cpp @@ -30,6 +30,7 @@ #include "nsFrameLoader.h" #include "mozilla/EventListenerManager.h" #include "mozilla/dom/Element.h" +#include "mozilla/dom/ProcessGlobal.h" #include "xpcpublic.h" #include "nsObserverService.h" #include "nsFocusManager.h" @@ -139,6 +140,14 @@ MarkChildMessageManagers(nsIMessageBroadcaster* aMM) static void MarkMessageManagers() { + if (nsFrameMessageManager::GetChildProcessManager()) { + // ProcessGlobal's MarkForCC marks also ChildProcessManager. + ProcessGlobal* pg = ProcessGlobal::Get(); + if (pg) { + pg->MarkForCC(); + } + } + // The global message manager only exists in the root process. if (!XRE_IsParentProcess()) { return; @@ -171,9 +180,6 @@ MarkMessageManagers() if (nsFrameMessageManager::sSameProcessParentManager) { nsFrameMessageManager::sSameProcessParentManager->MarkForCC(); } - if (nsFrameMessageManager::GetChildProcessManager()) { - nsFrameMessageManager::GetChildProcessManager()->MarkForCC(); - } } void diff --git a/dom/base/nsDOMDataChannel.cpp b/dom/base/nsDOMDataChannel.cpp index 1eba17484a..5bb85bbb00 100644 --- a/dom/base/nsDOMDataChannel.cpp +++ b/dom/base/nsDOMDataChannel.cpp @@ -17,9 +17,9 @@ extern PRLogModuleInfo* GetDataChannelLog(); #include "nsDOMDataChannelDeclarations.h" #include "nsDOMDataChannel.h" #include "nsIDOMDataChannel.h" -#include "nsIDOMMessageEvent.h" #include "mozilla/DOMEventTargetHelper.h" #include "mozilla/dom/File.h" +#include "mozilla/dom/MessageEvent.h" #include "mozilla/dom/ScriptSettings.h" #include "nsError.h" @@ -401,20 +401,15 @@ nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData, jsData.setString(jsString); } - nsCOMPtr event; - rv = NS_NewDOMMessageEvent(getter_AddRefs(event), this, nullptr, nullptr); - NS_ENSURE_SUCCESS(rv,rv); + nsRefPtr event = NS_NewDOMMessageEvent(this, nullptr, nullptr); - nsCOMPtr messageEvent = do_QueryInterface(event); - rv = messageEvent->InitMessageEvent(NS_LITERAL_STRING("message"), - false, false, - jsData, mOrigin, EmptyString(), - nullptr); + rv = event->InitMessageEvent(NS_LITERAL_STRING("message"), false, false, + jsData, mOrigin, EmptyString(), nullptr); NS_ENSURE_SUCCESS(rv,rv); event->SetTrusted(true); LOG(("%p(%p): %s - Dispatching\n",this,(void*)mDataChannel,__FUNCTION__)); - rv = DispatchDOMEvent(nullptr, event, nullptr, nullptr); + rv = DispatchDOMEvent(nullptr, static_cast(event), nullptr, nullptr); if (NS_FAILED(rv)) { NS_WARNING("Failed to dispatch the message event!!!"); } @@ -447,9 +442,7 @@ nsDOMDataChannel::OnSimpleEvent(nsISupports* aContext, const nsAString& aName) return NS_OK; } - nsCOMPtr event; - rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - NS_ENSURE_SUCCESS(rv,rv); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); rv = event->InitEvent(aName, false, false); NS_ENSURE_SUCCESS(rv,rv); diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 145eed4e60..ed4bf5b2a4 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -8160,17 +8160,17 @@ nsIDocument::CreateEvent(const nsAString& aEventType, ErrorResult& rv) const } // Create event even without presContext. - nsCOMPtr ev; - rv = EventDispatcher::CreateEvent(const_cast(this), - presContext, nullptr, aEventType, - getter_AddRefs(ev)); + nsRefPtr ev = + EventDispatcher::CreateEvent(const_cast(this), presContext, + nullptr, aEventType); if (!ev) { + rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return nullptr; } WidgetEvent* e = ev->GetInternalNSEvent(); e->mFlags.mBubbles = false; e->mFlags.mCancelable = false; - return dont_AddRef(ev.forget().take()->InternalDOMEvent()); + return ev.forget(); } void diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index ce55244b8e..b19c31c1d4 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -8824,8 +8824,7 @@ nsGlobalWindow::LeaveModalState() inner->mLastDialogQuitTime = TimeStamp::Now(); if (topWin->mModalStateDepth == 0) { - nsCOMPtr event; - NS_NewDOMEvent(getter_AddRefs(event), topWin, nullptr, nullptr); + nsRefPtr event = NS_NewDOMEvent(topWin, nullptr, nullptr); event->InitEvent(NS_LITERAL_STRING("endmodalstate"), true, false); event->SetTrusted(true); event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; @@ -11632,8 +11631,7 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic, return NS_OK; } - nsCOMPtr event; - NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); nsresult rv = event->InitEvent( !nsCRT::strcmp(aTopic, NS_NETWORK_ACTIVITY_BLIP_UPLOAD_TOPIC) ? NETWORK_UPLOAD_EVENT_NAME @@ -11669,8 +11667,7 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic, return NS_OK; } - nsCOMPtr event; - NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); nsresult rv = event->InitEvent(NS_LITERAL_STRING("languagechange"), false, false); NS_ENSURE_SUCCESS(rv, rv); diff --git a/dom/base/nsPerformance.cpp b/dom/base/nsPerformance.cpp index 11c2e9cf76..21e2327c41 100644 --- a/dom/base/nsPerformance.cpp +++ b/dom/base/nsPerformance.cpp @@ -477,16 +477,15 @@ nsPerformance::Timing() void nsPerformance::DispatchBufferFullEvent() { - nsCOMPtr event; - nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - if (NS_SUCCEEDED(rv)) { - // it bubbles, and it isn't cancelable - rv = event->InitEvent(NS_LITERAL_STRING("resourcetimingbufferfull"), true, false); - if (NS_SUCCEEDED(rv)) { - event->SetTrusted(true); - DispatchDOMEvent(nullptr, event, nullptr, nullptr); - } + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); + // it bubbles, and it isn't cancelable + nsresult rv = event->InitEvent(NS_LITERAL_STRING("resourcetimingbufferfull"), + true, false); + if (NS_FAILED(rv)) { + return; } + event->SetTrusted(true); + DispatchDOMEvent(nullptr, event, nullptr, nullptr); } nsPerformanceNavigation* diff --git a/dom/base/nsXMLHttpRequest.cpp b/dom/base/nsXMLHttpRequest.cpp index 132dd81f00..45d8d18cf9 100644 --- a/dom/base/nsXMLHttpRequest.cpp +++ b/dom/base/nsXMLHttpRequest.cpp @@ -1468,12 +1468,8 @@ nsXMLHttpRequest::GetLoadGroup() const nsresult nsXMLHttpRequest::CreateReadystatechangeEvent(nsIDOMEvent** aDOMEvent) { - nsresult rv = EventDispatcher::CreateEvent(this, nullptr, nullptr, - NS_LITERAL_STRING("Events"), - aDOMEvent); - if (NS_FAILED(rv)) { - return rv; - } + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); + event.forget(aDOMEvent); (*aDOMEvent)->InitEvent(NS_LITERAL_STRING(READYSTATE_STR), false, false); diff --git a/dom/bluetooth/bluetooth1/BluetoothAdapter.cpp b/dom/bluetooth/bluetooth1/BluetoothAdapter.cpp index cd3a95d595..691d8db74d 100644 --- a/dom/bluetooth/bluetooth1/BluetoothAdapter.cpp +++ b/dom/bluetooth/bluetooth1/BluetoothAdapter.cpp @@ -16,6 +16,7 @@ #include "mozilla/dom/BluetoothDiscoveryStateChangedEvent.h" #include "mozilla/dom/BluetoothStatusChangedEvent.h" #include "mozilla/dom/ContentChild.h" +#include "mozilla/dom/Event.h" #include "mozilla/dom/File.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/LazyIdleThread.h" @@ -361,11 +362,9 @@ BluetoothAdapter::Notify(const BluetoothSignal& aData) BluetoothStatusChangedEvent::Constructor(this, aData.name(), init); DispatchTrustedEvent(event); } else if (aData.name().EqualsLiteral(REQUEST_MEDIA_PLAYSTATUS_ID)) { - nsCOMPtr event; - nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - NS_ENSURE_SUCCESS_VOID(rv); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); - rv = event->InitEvent(aData.name(), false, false); + nsresult rv = event->InitEvent(aData.name(), false, false); NS_ENSURE_SUCCESS_VOID(rv); DispatchTrustedEvent(event); diff --git a/dom/bluetooth/bluetooth2/BluetoothAdapter.cpp b/dom/bluetooth/bluetooth2/BluetoothAdapter.cpp index 9b565bc180..1ea4b703be 100644 --- a/dom/bluetooth/bluetooth2/BluetoothAdapter.cpp +++ b/dom/bluetooth/bluetooth2/BluetoothAdapter.cpp @@ -16,6 +16,7 @@ #include "mozilla/dom/BluetoothAttributeEvent.h" #include "mozilla/dom/BluetoothStatusChangedEvent.h" #include "mozilla/dom/ContentChild.h" +#include "mozilla/dom/Event.h" #include "mozilla/dom/File.h" #include "mozilla/dom/bluetooth/BluetoothAdapter.h" @@ -1220,11 +1221,9 @@ BluetoothAdapter::DispatchDeviceEvent(const nsAString& aType, void BluetoothAdapter::DispatchEmptyEvent(const nsAString& aType) { - nsCOMPtr event; - nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - NS_ENSURE_SUCCESS_VOID(rv); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); - rv = event->InitEvent(aType, false, false); + nsresult rv = event->InitEvent(aType, false, false); NS_ENSURE_SUCCESS_VOID(rv); DispatchTrustedEvent(event); diff --git a/dom/bluetooth/bluetooth2/BluetoothGatt.cpp b/dom/bluetooth/bluetooth2/BluetoothGatt.cpp index a9b97c4ea4..212d765c0a 100644 --- a/dom/bluetooth/bluetooth2/BluetoothGatt.cpp +++ b/dom/bluetooth/bluetooth2/BluetoothGatt.cpp @@ -12,6 +12,7 @@ #include "mozilla/dom/bluetooth/BluetoothTypes.h" #include "mozilla/dom/BluetoothGattBinding.h" #include "mozilla/dom/BluetoothGattCharacteristicEvent.h" +#include "mozilla/dom/Event.h" #include "mozilla/dom/Promise.h" #include "nsServiceManagerUtils.h" @@ -240,13 +241,12 @@ BluetoothGatt::UpdateConnectionState(BluetoothConnectionState aState) mConnectionState = aState; // Dispatch connectionstatechanged event to application - nsCOMPtr event; - nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - NS_ENSURE_SUCCESS_VOID(rv); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); - rv = event->InitEvent(NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID), - false, - false); + nsresult rv = + event->InitEvent(NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID), + false, + false); NS_ENSURE_SUCCESS_VOID(rv); DispatchTrustedEvent(event); diff --git a/dom/browser-element/BrowserElementParent.cpp b/dom/browser-element/BrowserElementParent.cpp index 148b7b9210..5d25537da9 100644 --- a/dom/browser-element/BrowserElementParent.cpp +++ b/dom/browser-element/BrowserElementParent.cpp @@ -102,16 +102,10 @@ DispatchCustomDOMEvent(Element* aFrameElement, const nsAString& aEventName, presContext = shell->GetPresContext(); } - nsCOMPtr domEvent; - EventDispatcher::CreateEvent(aFrameElement, presContext, nullptr, - NS_LITERAL_STRING("customevent"), - getter_AddRefs(domEvent)); - NS_ENSURE_TRUE(domEvent, false); + nsRefPtr event = + NS_NewDOMCustomEvent(aFrameElement, presContext, nullptr); - nsCOMPtr customEvent = do_QueryInterface(domEvent); - NS_ENSURE_TRUE(customEvent, false); ErrorResult res; - CustomEvent* event = static_cast(customEvent.get()); event->InitCustomEvent(cx, aEventName, /* bubbles = */ true, @@ -121,12 +115,13 @@ DispatchCustomDOMEvent(Element* aFrameElement, const nsAString& aEventName, if (res.Failed()) { return false; } - customEvent->SetTrusted(true); + event->SetTrusted(true); // Dispatch the event. *aStatus = nsEventStatus_eConsumeNoDefault; nsresult rv = EventDispatcher::DispatchDOMEvent(aFrameElement, nullptr, - domEvent, presContext, aStatus); + static_cast(event), + presContext, aStatus); return NS_SUCCEEDED(rv); } diff --git a/dom/events/AnimationEvent.cpp b/dom/events/AnimationEvent.cpp index 582bd71a38..6267137267 100644 --- a/dom/events/AnimationEvent.cpp +++ b/dom/events/AnimationEvent.cpp @@ -88,14 +88,12 @@ AnimationEvent::GetPseudoElement(nsAString& aPseudoElement) using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMAnimationEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMAnimationEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalAnimationEvent* aEvent) { - AnimationEvent* it = new AnimationEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new AnimationEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/AnimationEvent.h b/dom/events/AnimationEvent.h index d6afdea30d..23713a1364 100644 --- a/dom/events/AnimationEvent.h +++ b/dom/events/AnimationEvent.h @@ -52,4 +52,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMAnimationEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::InternalAnimationEvent* aEvent); + #endif // mozilla_dom_AnimationEvent_h_ diff --git a/dom/events/AsyncEventDispatcher.cpp b/dom/events/AsyncEventDispatcher.cpp index 9c3d2bd10c..529a630c23 100644 --- a/dom/events/AsyncEventDispatcher.cpp +++ b/dom/events/AsyncEventDispatcher.cpp @@ -25,8 +25,9 @@ AsyncEventDispatcher::AsyncEventDispatcher(EventTarget* aTarget, : mTarget(aTarget) { MOZ_ASSERT(mTarget); - EventDispatcher::CreateEvent(aTarget, nullptr, &aEvent, EmptyString(), - getter_AddRefs(mEvent)); + nsRefPtr event = + EventDispatcher::CreateEvent(aTarget, nullptr, &aEvent, EmptyString()); + mEvent = do_QueryInterface(event); NS_ASSERTION(mEvent, "Should never fail to create an event"); mEvent->DuplicatePrivateData(); mEvent->SetTrusted(aEvent.mFlags.mIsTrusted); @@ -38,15 +39,15 @@ AsyncEventDispatcher::Run() if (mCanceled) { return NS_OK; } - nsCOMPtr event = mEvent; + nsRefPtr event = mEvent ? mEvent->InternalDOMEvent() : nullptr; if (!event) { - NS_NewDOMEvent(getter_AddRefs(event), mTarget, nullptr, nullptr); + event = NS_NewDOMEvent(mTarget, nullptr, nullptr); nsresult rv = event->InitEvent(mEventType, mBubbles, false); NS_ENSURE_SUCCESS(rv, rv); event->SetTrusted(true); } if (mOnlyChromeDispatch) { - MOZ_ASSERT(event->InternalDOMEvent()->IsTrusted()); + MOZ_ASSERT(event->IsTrusted()); event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; } bool dummy; diff --git a/dom/events/BeforeAfterKeyboardEvent.cpp b/dom/events/BeforeAfterKeyboardEvent.cpp index 13ec45218e..736e9edb07 100644 --- a/dom/events/BeforeAfterKeyboardEvent.cpp +++ b/dom/events/BeforeAfterKeyboardEvent.cpp @@ -78,16 +78,12 @@ BeforeAfterKeyboardEvent::GetEmbeddedCancelled() using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMBeforeAfterKeyboardEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMBeforeAfterKeyboardEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalBeforeAfterKeyboardEvent* aEvent) { - BeforeAfterKeyboardEvent* it = + nsRefPtr it = new BeforeAfterKeyboardEvent(aOwner, aPresContext, aEvent); - - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + return it.forget(); } diff --git a/dom/events/BeforeAfterKeyboardEvent.h b/dom/events/BeforeAfterKeyboardEvent.h index b14ff923aa..5ada2e861e 100644 --- a/dom/events/BeforeAfterKeyboardEvent.h +++ b/dom/events/BeforeAfterKeyboardEvent.h @@ -43,4 +43,9 @@ public: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMBeforeAfterKeyboardEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::InternalBeforeAfterKeyboardEvent* aEvent); + #endif // mozilla_dom_BeforeAfterKeyboardEvent_h_ diff --git a/dom/events/BeforeUnloadEvent.cpp b/dom/events/BeforeUnloadEvent.cpp index b9beb7d099..db55dc04f8 100644 --- a/dom/events/BeforeUnloadEvent.cpp +++ b/dom/events/BeforeUnloadEvent.cpp @@ -36,14 +36,12 @@ BeforeUnloadEvent::GetReturnValue(nsAString& aReturnValue) using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMBeforeUnloadEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMBeforeUnloadEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent) { - BeforeUnloadEvent* it = new BeforeUnloadEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new BeforeUnloadEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/BeforeUnloadEvent.h b/dom/events/BeforeUnloadEvent.h index 73de66e171..781332c6a2 100644 --- a/dom/events/BeforeUnloadEvent.h +++ b/dom/events/BeforeUnloadEvent.h @@ -47,4 +47,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMBeforeUnloadEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetEvent* aEvent); + #endif // mozilla_dom_BeforeUnloadEvent_h_ diff --git a/dom/events/ClipboardEvent.cpp b/dom/events/ClipboardEvent.cpp index 30e48372d0..c44fcf38ab 100644 --- a/dom/events/ClipboardEvent.cpp +++ b/dom/events/ClipboardEvent.cpp @@ -123,14 +123,12 @@ ClipboardEvent::GetClipboardData() using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMClipboardEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMClipboardEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalClipboardEvent* aEvent) { - ClipboardEvent* it = new ClipboardEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new ClipboardEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/ClipboardEvent.h b/dom/events/ClipboardEvent.h index a1e3be656f..563cbae18a 100644 --- a/dom/events/ClipboardEvent.h +++ b/dom/events/ClipboardEvent.h @@ -56,4 +56,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMClipboardEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::InternalClipboardEvent* aEvent); + #endif // mozilla_dom_ClipboardEvent_h_ diff --git a/dom/events/CommandEvent.cpp b/dom/events/CommandEvent.cpp index eacd415736..c842f0d39b 100644 --- a/dom/events/CommandEvent.cpp +++ b/dom/events/CommandEvent.cpp @@ -64,14 +64,12 @@ CommandEvent::InitCommandEvent(const nsAString& aTypeArg, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMCommandEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMCommandEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetCommandEvent* aEvent) { - CommandEvent* it = new CommandEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new CommandEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/CommandEvent.h b/dom/events/CommandEvent.h index f551aec1f6..cb21c1d491 100644 --- a/dom/events/CommandEvent.h +++ b/dom/events/CommandEvent.h @@ -51,4 +51,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMCommandEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetCommandEvent* aEvent); + #endif // mozilla_dom_CommandEvent_h_ diff --git a/dom/events/CompositionEvent.cpp b/dom/events/CompositionEvent.cpp index 6b4b054c29..0216c97818 100644 --- a/dom/events/CompositionEvent.cpp +++ b/dom/events/CompositionEvent.cpp @@ -80,12 +80,12 @@ CompositionEvent::InitCompositionEvent(const nsAString& aType, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMCompositionEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMCompositionEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetCompositionEvent* aEvent) { - CompositionEvent* event = new CompositionEvent(aOwner, aPresContext, aEvent); - return CallQueryInterface(event, aInstancePtrResult); + nsRefPtr event = + new CompositionEvent(aOwner, aPresContext, aEvent); + return event.forget(); } diff --git a/dom/events/CompositionEvent.h b/dom/events/CompositionEvent.h index 67a75ec1a1..c2fbf7cfdd 100644 --- a/dom/events/CompositionEvent.h +++ b/dom/events/CompositionEvent.h @@ -54,4 +54,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMCompositionEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetCompositionEvent* aEvent); + #endif // mozilla_dom_CompositionEvent_h_ diff --git a/dom/events/CustomEvent.cpp b/dom/events/CustomEvent.cpp index da04371fe0..125742efc4 100644 --- a/dom/events/CustomEvent.cpp +++ b/dom/events/CustomEvent.cpp @@ -111,14 +111,12 @@ CustomEvent::GetDetail(JSContext* aCx, VariantToJsval(aCx, mDetail, aRetval); } -nsresult -NS_NewDOMCustomEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, +already_AddRefed +NS_NewDOMCustomEvent(EventTarget* aOwner, nsPresContext* aPresContext, mozilla::WidgetEvent* aEvent) { - CustomEvent* it = new CustomEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new CustomEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/CustomEvent.h b/dom/events/CustomEvent.h index e5c17595b0..24cd0efa0e 100644 --- a/dom/events/CustomEvent.h +++ b/dom/events/CustomEvent.h @@ -58,4 +58,9 @@ public: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMCustomEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetEvent* aEvent); + #endif // CustomEvent_h__ diff --git a/dom/events/DOMEventTargetHelper.cpp b/dom/events/DOMEventTargetHelper.cpp index 12ec3b415d..bb053118d3 100644 --- a/dom/events/DOMEventTargetHelper.cpp +++ b/dom/events/DOMEventTargetHelper.cpp @@ -258,8 +258,7 @@ DOMEventTargetHelper::DispatchEvent(nsIDOMEvent* aEvent, bool* aRetVal) nsresult DOMEventTargetHelper::DispatchTrustedEvent(const nsAString& aEventName) { - nsCOMPtr event; - NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); nsresult rv = event->InitEvent(aEventName, false, false); NS_ENSURE_SUCCESS(rv, rv); diff --git a/dom/events/DataContainerEvent.cpp b/dom/events/DataContainerEvent.cpp index 4878f467f3..963a50d520 100644 --- a/dom/events/DataContainerEvent.cpp +++ b/dom/events/DataContainerEvent.cpp @@ -87,15 +87,13 @@ DataContainerEvent::SetData(JSContext* aCx, const nsAString& aKey, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMDataContainerEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMDataContainerEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent) { - DataContainerEvent* it = new DataContainerEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new DataContainerEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/DataContainerEvent.h b/dom/events/DataContainerEvent.h index 15acfeb44b..c118cf5aba 100644 --- a/dom/events/DataContainerEvent.h +++ b/dom/events/DataContainerEvent.h @@ -57,4 +57,9 @@ private: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMDataContainerEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetEvent* aEvent); + #endif // mozilla_dom_DataContainerEvent_h_ diff --git a/dom/events/DeviceMotionEvent.cpp b/dom/events/DeviceMotionEvent.cpp index 8e9b1dfc07..0c9d2c62a3 100644 --- a/dom/events/DeviceMotionEvent.cpp +++ b/dom/events/DeviceMotionEvent.cpp @@ -145,16 +145,12 @@ DeviceRotationRate::~DeviceRotationRate() using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMDeviceMotionEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMDeviceMotionEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent) { - NS_ENSURE_ARG_POINTER(aInstancePtrResult); - - DeviceMotionEvent* it = new DeviceMotionEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new DeviceMotionEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/DeviceMotionEvent.h b/dom/events/DeviceMotionEvent.h index c6b0624e39..a484488b95 100644 --- a/dom/events/DeviceMotionEvent.h +++ b/dom/events/DeviceMotionEvent.h @@ -149,4 +149,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMDeviceMotionEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetEvent* aEvent); + #endif // mozilla_dom_DeviceMotionEvent_h_ diff --git a/dom/events/DragEvent.cpp b/dom/events/DragEvent.cpp index 3e84dc578b..7ebb10b0c6 100644 --- a/dom/events/DragEvent.cpp +++ b/dom/events/DragEvent.cpp @@ -158,12 +158,12 @@ DragEvent::Constructor(const GlobalObject& aGlobal, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMDragEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMDragEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetDragEvent* aEvent) { - DragEvent* event = new DragEvent(aOwner, aPresContext, aEvent); - return CallQueryInterface(event, aInstancePtrResult); + nsRefPtr event = + new DragEvent(aOwner, aPresContext, aEvent); + return event.forget(); } diff --git a/dom/events/DragEvent.h b/dom/events/DragEvent.h index 21e56cc729..37450182b4 100644 --- a/dom/events/DragEvent.h +++ b/dom/events/DragEvent.h @@ -61,4 +61,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMDragEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetDragEvent* aEvent); + #endif // mozilla_dom_DragEvent_h_ diff --git a/dom/events/Event.cpp b/dom/events/Event.cpp index b285583670..84d9bedd26 100644 --- a/dom/events/Event.cpp +++ b/dom/events/Event.cpp @@ -481,6 +481,13 @@ Event::StopImmediatePropagation() return NS_OK; } +NS_IMETHODIMP +Event::StopCrossProcessForwarding() +{ + mEvent->mFlags.mNoCrossProcessBoundaryForwarding = true; + return NS_OK; +} + NS_IMETHODIMP Event::GetIsTrusted(bool* aIsTrusted) { @@ -1277,14 +1284,11 @@ Event::SetCancelBubble(bool aCancelBubble) using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent) { - Event* it = new Event(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new Event(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/Event.h b/dom/events/Event.h index c3f53ca292..4ace286562 100644 --- a/dom/events/Event.h +++ b/dom/events/Event.h @@ -314,6 +314,7 @@ private: NS_IMETHOD GetCancelable(bool* aCancelable) override { return _to GetCancelable(aCancelable); } \ NS_IMETHOD GetTimeStamp(DOMTimeStamp* aTimeStamp) override { return _to GetTimeStamp(aTimeStamp); } \ NS_IMETHOD StopPropagation(void) override { return _to StopPropagation(); } \ + NS_IMETHOD StopCrossProcessForwarding(void) override { return _to StopCrossProcessForwarding(); } \ NS_IMETHOD PreventDefault(void) override { return _to PreventDefault(); } \ NS_IMETHOD InitEvent(const nsAString& eventTypeArg, bool canBubbleArg, bool cancelableArg) override { return _to InitEvent(eventTypeArg, canBubbleArg, cancelableArg); } \ NS_IMETHOD GetDefaultPrevented(bool* aDefaultPrevented) override { return _to GetDefaultPrevented(aDefaultPrevented); } \ @@ -346,4 +347,9 @@ ToCanonicalSupports(mozilla::dom::Event* e) return static_cast(e); } +already_AddRefed +NS_NewDOMEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetEvent* aEvent); + #endif // mozilla_dom_Event_h_ diff --git a/dom/events/EventDispatcher.cpp b/dom/events/EventDispatcher.cpp index ebe7a545a3..a347acceab 100644 --- a/dom/events/EventDispatcher.cpp +++ b/dom/events/EventDispatcher.cpp @@ -15,13 +15,28 @@ #include "GeckoProfiler.h" #include "mozilla/ContentEvents.h" #include "mozilla/dom/CloseEvent.h" +#include "mozilla/dom/CustomEvent.h" #include "mozilla/dom/DeviceOrientationEvent.h" #include "mozilla/dom/EventTarget.h" +#include "mozilla/dom/FocusEvent.h" #include "mozilla/dom/HashChangeEvent.h" +#include "mozilla/dom/InputEvent.h" +#include "mozilla/dom/MessageEvent.h" +#include "mozilla/dom/MouseScrollEvent.h" +#include "mozilla/dom/MutationEvent.h" +#include "mozilla/dom/NotifyPaintEvent.h" #include "mozilla/dom/PageTransitionEvent.h" +#include "mozilla/dom/PointerEvent.h" #include "mozilla/dom/PopStateEvent.h" +#include "mozilla/dom/ScrollAreaEvent.h" +#include "mozilla/dom/SimpleGestureEvent.h" #include "mozilla/dom/StorageEvent.h" +#include "mozilla/dom/SVGZoomEvent.h" +#include "mozilla/dom/TimeEvent.h" #include "mozilla/dom/TouchEvent.h" +#include "mozilla/dom/TransitionEvent.h" +#include "mozilla/dom/WheelEvent.h" +#include "mozilla/dom/XULCommandEvent.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventListenerManager.h" #include "mozilla/InternalMutationEvent.h" @@ -705,85 +720,76 @@ EventDispatcher::DispatchDOMEvent(nsISupports* aTarget, return NS_ERROR_ILLEGAL_VALUE; } -/* static */ nsresult +/* static */ already_AddRefed EventDispatcher::CreateEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent, - const nsAString& aEventType, - nsIDOMEvent** aDOMEvent) + const nsAString& aEventType) { - *aDOMEvent = nullptr; - if (aEvent) { switch(aEvent->mClass) { case eMutationEventClass: - return NS_NewDOMMutationEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMMutationEvent(aOwner, aPresContext, aEvent->AsMutationEvent()); case eGUIEventClass: case eScrollPortEventClass: case eUIEventClass: - return NS_NewDOMUIEvent(aDOMEvent, aOwner, aPresContext, - aEvent->AsGUIEvent()); + return NS_NewDOMUIEvent(aOwner, aPresContext, aEvent->AsGUIEvent()); case eScrollAreaEventClass: - return NS_NewDOMScrollAreaEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMScrollAreaEvent(aOwner, aPresContext, aEvent->AsScrollAreaEvent()); case eKeyboardEventClass: - return NS_NewDOMKeyboardEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMKeyboardEvent(aOwner, aPresContext, aEvent->AsKeyboardEvent()); case eBeforeAfterKeyboardEventClass: - return NS_NewDOMBeforeAfterKeyboardEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMBeforeAfterKeyboardEvent(aOwner, aPresContext, aEvent->AsBeforeAfterKeyboardEvent()); case eCompositionEventClass: - return NS_NewDOMCompositionEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMCompositionEvent(aOwner, aPresContext, aEvent->AsCompositionEvent()); case eMouseEventClass: - return NS_NewDOMMouseEvent(aDOMEvent, aOwner, aPresContext, - aEvent->AsMouseEvent()); + return NS_NewDOMMouseEvent(aOwner, aPresContext, aEvent->AsMouseEvent()); case eFocusEventClass: - return NS_NewDOMFocusEvent(aDOMEvent, aOwner, aPresContext, - aEvent->AsFocusEvent()); + return NS_NewDOMFocusEvent(aOwner, aPresContext, aEvent->AsFocusEvent()); case eMouseScrollEventClass: - return NS_NewDOMMouseScrollEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMMouseScrollEvent(aOwner, aPresContext, aEvent->AsMouseScrollEvent()); case eWheelEventClass: - return NS_NewDOMWheelEvent(aDOMEvent, aOwner, aPresContext, - aEvent->AsWheelEvent()); + return NS_NewDOMWheelEvent(aOwner, aPresContext, aEvent->AsWheelEvent()); case eEditorInputEventClass: - return NS_NewDOMInputEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMInputEvent(aOwner, aPresContext, aEvent->AsEditorInputEvent()); case eDragEventClass: - return NS_NewDOMDragEvent(aDOMEvent, aOwner, aPresContext, - aEvent->AsDragEvent()); + return NS_NewDOMDragEvent(aOwner, aPresContext, aEvent->AsDragEvent()); case eClipboardEventClass: - return NS_NewDOMClipboardEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMClipboardEvent(aOwner, aPresContext, aEvent->AsClipboardEvent()); case eSVGZoomEventClass: - return NS_NewDOMSVGZoomEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMSVGZoomEvent(aOwner, aPresContext, aEvent->AsSVGZoomEvent()); case eSMILTimeEventClass: - return NS_NewDOMTimeEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMTimeEvent(aOwner, aPresContext, aEvent->AsSMILTimeEvent()); case eCommandEventClass: - return NS_NewDOMCommandEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMCommandEvent(aOwner, aPresContext, aEvent->AsCommandEvent()); case eSimpleGestureEventClass: - return NS_NewDOMSimpleGestureEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMSimpleGestureEvent(aOwner, aPresContext, aEvent->AsSimpleGestureEvent()); case ePointerEventClass: - return NS_NewDOMPointerEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMPointerEvent(aOwner, aPresContext, aEvent->AsPointerEvent()); case eTouchEventClass: - return NS_NewDOMTouchEvent(aDOMEvent, aOwner, aPresContext, - aEvent->AsTouchEvent()); + return NS_NewDOMTouchEvent(aOwner, aPresContext, aEvent->AsTouchEvent()); case eTransitionEventClass: - return NS_NewDOMTransitionEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMTransitionEvent(aOwner, aPresContext, aEvent->AsTransitionEvent()); case eAnimationEventClass: - return NS_NewDOMAnimationEvent(aDOMEvent, aOwner, aPresContext, + return NS_NewDOMAnimationEvent(aOwner, aPresContext, aEvent->AsAnimationEvent()); default: // For all other types of events, create a vanilla event object. - return NS_NewDOMEvent(aDOMEvent, aOwner, aPresContext, aEvent); + return NS_NewDOMEvent(aOwner, aPresContext, aEvent); } } @@ -792,106 +798,94 @@ EventDispatcher::CreateEvent(EventTarget* aOwner, if (aEventType.LowerCaseEqualsLiteral("mouseevent") || aEventType.LowerCaseEqualsLiteral("mouseevents") || aEventType.LowerCaseEqualsLiteral("popupevents")) - return NS_NewDOMMouseEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMMouseEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("mousescrollevents")) - return NS_NewDOMMouseScrollEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMMouseScrollEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("dragevent") || aEventType.LowerCaseEqualsLiteral("dragevents")) - return NS_NewDOMDragEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMDragEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("keyboardevent") || aEventType.LowerCaseEqualsLiteral("keyevents")) - return NS_NewDOMKeyboardEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMKeyboardEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("compositionevent") || aEventType.LowerCaseEqualsLiteral("textevent") || aEventType.LowerCaseEqualsLiteral("textevents")) { - return NS_NewDOMCompositionEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMCompositionEvent(aOwner, aPresContext, nullptr); } if (aEventType.LowerCaseEqualsLiteral("mutationevent") || aEventType.LowerCaseEqualsLiteral("mutationevents")) - return NS_NewDOMMutationEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMMutationEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("deviceorientationevent")) { DeviceOrientationEventInit init; - nsRefPtr event = - DeviceOrientationEvent::Constructor(aOwner, EmptyString(), init); - event.forget(aDOMEvent); - return NS_OK; + return DeviceOrientationEvent::Constructor(aOwner, EmptyString(), init); } if (aEventType.LowerCaseEqualsLiteral("devicemotionevent")) - return NS_NewDOMDeviceMotionEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMDeviceMotionEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("uievent") || aEventType.LowerCaseEqualsLiteral("uievents")) - return NS_NewDOMUIEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMUIEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("event") || aEventType.LowerCaseEqualsLiteral("events") || aEventType.LowerCaseEqualsLiteral("htmlevents") || aEventType.LowerCaseEqualsLiteral("svgevent") || aEventType.LowerCaseEqualsLiteral("svgevents")) - return NS_NewDOMEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("svgzoomevent") || aEventType.LowerCaseEqualsLiteral("svgzoomevents")) - return NS_NewDOMSVGZoomEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMSVGZoomEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("timeevent") || aEventType.LowerCaseEqualsLiteral("timeevents")) - return NS_NewDOMTimeEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMTimeEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("xulcommandevent") || aEventType.LowerCaseEqualsLiteral("xulcommandevents")) - return NS_NewDOMXULCommandEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMXULCommandEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("commandevent") || aEventType.LowerCaseEqualsLiteral("commandevents")) - return NS_NewDOMCommandEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMCommandEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("datacontainerevent") || aEventType.LowerCaseEqualsLiteral("datacontainerevents")) - return NS_NewDOMDataContainerEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMDataContainerEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("messageevent")) - return NS_NewDOMMessageEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMMessageEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("notifypaintevent")) - return NS_NewDOMNotifyPaintEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMNotifyPaintEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("simplegestureevent")) - return NS_NewDOMSimpleGestureEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMSimpleGestureEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("beforeunloadevent")) - return NS_NewDOMBeforeUnloadEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMBeforeUnloadEvent(aOwner, aPresContext, nullptr); // XXXkhuey this is broken if (aEventType.LowerCaseEqualsLiteral("pagetransition")) { PageTransitionEventInit init; - nsRefPtr event = - PageTransitionEvent::Constructor(aOwner, EmptyString(), init); - event.forget(aDOMEvent); - return NS_OK; + return PageTransitionEvent::Constructor(aOwner, EmptyString(), init); } if (aEventType.LowerCaseEqualsLiteral("scrollareaevent")) - return NS_NewDOMScrollAreaEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMScrollAreaEvent(aOwner, aPresContext, nullptr); // XXXkhuey Chrome supports popstateevent here, even though it provides no // initPopStateEvent method. This is nuts ... but copying it is unlikely to // break the web. if (aEventType.LowerCaseEqualsLiteral("popstateevent")) { AutoJSContext cx; RootedDictionary init(cx); - nsRefPtr event = - PopStateEvent::Constructor(aOwner, EmptyString(), init); - event.forget(aDOMEvent); - return NS_OK; + return PopStateEvent::Constructor(aOwner, EmptyString(), init); } if (aEventType.LowerCaseEqualsLiteral("touchevent") && TouchEvent::PrefEnabled()) - return NS_NewDOMTouchEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMTouchEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("hashchangeevent")) { HashChangeEventInit init; - nsRefPtr event = - HashChangeEvent::Constructor(aOwner, EmptyString(), init); - event.forget(aDOMEvent); - return NS_OK; + return HashChangeEvent::Constructor(aOwner, EmptyString(), init); } if (aEventType.LowerCaseEqualsLiteral("customevent")) - return NS_NewDOMCustomEvent(aDOMEvent, aOwner, aPresContext, nullptr); + return NS_NewDOMCustomEvent(aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("storageevent")) { - return NS_NewDOMStorageEvent(aDOMEvent, aOwner); + return NS_NewDOMStorageEvent(aOwner); } // NEW EVENT TYPES SHOULD NOT BE ADDED HERE; THEY SHOULD USE ONLY EVENT // CONSTRUCTORS - return NS_ERROR_DOM_NOT_SUPPORTED_ERR; + return nullptr; } } // namespace mozilla diff --git a/dom/events/EventDispatcher.h b/dom/events/EventDispatcher.h index 4fa9a13ecb..1e5329b5bd 100644 --- a/dom/events/EventDispatcher.h +++ b/dom/events/EventDispatcher.h @@ -23,6 +23,7 @@ template class nsCOMArray; namespace mozilla { namespace dom { +class Event; class EventTarget; } // namespace dom @@ -272,13 +273,12 @@ public: nsEventStatus* aEventStatus); /** - * Creates a DOM Event. + * Creates a DOM Event. Returns null if the event type is unsupported. */ - static nsresult CreateEvent(dom::EventTarget* aOwner, - nsPresContext* aPresContext, - WidgetEvent* aEvent, - const nsAString& aEventType, - nsIDOMEvent** aDOMEvent); + static already_AddRefed CreateEvent(dom::EventTarget* aOwner, + nsPresContext* aPresContext, + WidgetEvent* aEvent, + const nsAString& aEventType); /** * Called at shutting down. diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index 3a97a6978c..b7a77343e3 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -1106,8 +1106,10 @@ EventListenerManager::HandleEventInternal(nsPresContext* aPresContext, // This is tiny bit slow, but happens only once per event. nsCOMPtr et = do_QueryInterface(aEvent->originalTarget); - EventDispatcher::CreateEvent(et, aPresContext, - aEvent, EmptyString(), aDOMEvent); + nsRefPtr event = EventDispatcher::CreateEvent(et, aPresContext, + aEvent, + EmptyString()); + event.forget(aDOMEvent); } if (*aDOMEvent) { if (!aEvent->currentTarget) { diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 325907cb36..2c45884a90 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -16,6 +16,7 @@ #include "mozilla/TextEvents.h" #include "mozilla/TouchEvents.h" #include "mozilla/dom/ContentChild.h" +#include "mozilla/dom/DragEvent.h" #include "mozilla/dom/Event.h" #include "mozilla/dom/TabParent.h" #include "mozilla/dom/UIEvent.h" @@ -54,7 +55,6 @@ #include "nsIObserverService.h" #include "nsIDocShell.h" #include "nsIDOMWheelEvent.h" -#include "nsIDOMDragEvent.h" #include "nsIDOMUIEvent.h" #include "nsIMozBrowserFrame.h" @@ -1894,13 +1894,8 @@ EventStateManager::DoDefaultDragStart(nsPresContext* aPresContext, // XXXndeakin don't really want to create a new drag DOM event // here, but we need something to pass to the InvokeDragSession // methods. - nsCOMPtr domEvent; - NS_NewDOMDragEvent(getter_AddRefs(domEvent), dragTarget, - aPresContext, aDragEvent); - - nsCOMPtr domDragEvent = do_QueryInterface(domEvent); - // if creating a drag event failed, starting a drag session will - // just fail. + nsRefPtr event = + NS_NewDOMDragEvent(dragTarget, aPresContext, aDragEvent); // Use InvokeDragSessionWithSelection if a selection is being dragged, // such that the image can be generated from the selected text. However, @@ -1908,8 +1903,7 @@ EventStateManager::DoDefaultDragStart(nsPresContext* aPresContext, // other than a selection is being dragged. if (!dragImage && aSelection) { dragService->InvokeDragSessionWithSelection(aSelection, transArray, - action, domDragEvent, - aDataTransfer); + action, event, aDataTransfer); } else { // if dragging within a XUL tree and no custom drag image was @@ -1935,8 +1929,7 @@ EventStateManager::DoDefaultDragStart(nsPresContext* aPresContext, region, action, dragImage ? dragImage->AsDOMNode() : nullptr, - imageX, - imageY, domDragEvent, + imageX, imageY, event, aDataTransfer); } diff --git a/dom/events/FocusEvent.cpp b/dom/events/FocusEvent.cpp index 0d684f64b8..4f3732dcac 100644 --- a/dom/events/FocusEvent.cpp +++ b/dom/events/FocusEvent.cpp @@ -77,14 +77,11 @@ FocusEvent::Constructor(const GlobalObject& aGlobal, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMFocusEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMFocusEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalFocusEvent* aEvent) { - FocusEvent* it = new FocusEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new FocusEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/FocusEvent.h b/dom/events/FocusEvent.h index 58ca9f5343..af188baafc 100644 --- a/dom/events/FocusEvent.h +++ b/dom/events/FocusEvent.h @@ -53,4 +53,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMFocusEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::InternalFocusEvent* aEvent); + #endif // mozilla_dom_FocusEvent_h_ diff --git a/dom/events/InputEvent.cpp b/dom/events/InputEvent.cpp index 12fbd36cc2..f7070435a3 100644 --- a/dom/events/InputEvent.cpp +++ b/dom/events/InputEvent.cpp @@ -63,14 +63,11 @@ InputEvent::Constructor(const GlobalObject& aGlobal, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMInputEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMInputEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalEditorInputEvent* aEvent) { - InputEvent* it = new InputEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new InputEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/InputEvent.h b/dom/events/InputEvent.h index edafa7531e..3e0e9361df 100644 --- a/dom/events/InputEvent.h +++ b/dom/events/InputEvent.h @@ -46,4 +46,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMInputEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::InternalEditorInputEvent* aEvent); + #endif // mozilla_dom_InputEvent_h_ diff --git a/dom/events/KeyboardEvent.cpp b/dom/events/KeyboardEvent.cpp index 1e67a2384b..e74ca29283 100644 --- a/dom/events/KeyboardEvent.cpp +++ b/dom/events/KeyboardEvent.cpp @@ -309,14 +309,11 @@ KeyboardEvent::InitKeyEvent(const nsAString& aType, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMKeyboardEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMKeyboardEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetKeyboardEvent* aEvent) { - KeyboardEvent* it = new KeyboardEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new KeyboardEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/KeyboardEvent.h b/dom/events/KeyboardEvent.h index 87813ed03e..2772225cdb 100644 --- a/dom/events/KeyboardEvent.h +++ b/dom/events/KeyboardEvent.h @@ -93,4 +93,9 @@ private: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMKeyboardEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetKeyboardEvent* aEvent); + #endif // mozilla_dom_KeyboardEvent_h_ diff --git a/dom/events/MessageEvent.cpp b/dom/events/MessageEvent.cpp index 07ae64f3ac..d2a6572660 100644 --- a/dom/events/MessageEvent.cpp +++ b/dom/events/MessageEvent.cpp @@ -172,7 +172,7 @@ MessageEvent::Constructor(EventTarget* aEventTarget, ports.AppendElement(aParam.mPorts.Value().Value()[i].get()); } - event->mPorts = new MessagePortList(static_cast(event), ports); + event->mPorts = new MessagePortList(static_cast(event), ports); } return event.forget(); @@ -224,14 +224,11 @@ MessageEvent::SetSource(mozilla::dom::workers::ServiceWorkerClient* aClient) using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMMessageEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMMessageEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent) { - MessageEvent* it = new MessageEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new MessageEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/MessageEvent.h b/dom/events/MessageEvent.h index 485f24739f..e472a17b96 100644 --- a/dom/events/MessageEvent.h +++ b/dom/events/MessageEvent.h @@ -99,4 +99,9 @@ private: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMMessageEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetEvent* aEvent); + #endif // mozilla_dom_MessageEvent_h_ diff --git a/dom/events/MouseEvent.cpp b/dom/events/MouseEvent.cpp index b61c77d375..7b8455789d 100644 --- a/dom/events/MouseEvent.cpp +++ b/dom/events/MouseEvent.cpp @@ -507,14 +507,11 @@ MouseEvent::GetMozInputSource(uint16_t* aInputSource) using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMMouseEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMMouseEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetMouseEvent* aEvent) { - MouseEvent* it = new MouseEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new MouseEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/MouseEvent.h b/dom/events/MouseEvent.h index c05a5fddcd..1354593cf2 100644 --- a/dom/events/MouseEvent.h +++ b/dom/events/MouseEvent.h @@ -129,4 +129,9 @@ protected: NS_FORWARD_NSIDOMMOUSEEVENT(MouseEvent::) \ NS_FORWARD_TO_UIEVENT +already_AddRefed +NS_NewDOMMouseEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetMouseEvent* aEvent); + #endif // mozilla_dom_MouseEvent_h_ diff --git a/dom/events/MouseScrollEvent.cpp b/dom/events/MouseScrollEvent.cpp index b860cfc9a4..4569137572 100644 --- a/dom/events/MouseScrollEvent.cpp +++ b/dom/events/MouseScrollEvent.cpp @@ -88,14 +88,12 @@ MouseScrollEvent::Axis() using namespace mozilla; using namespace dom; -nsresult -NS_NewDOMMouseScrollEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMMouseScrollEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetMouseScrollEvent* aEvent) { - MouseScrollEvent* it = new MouseScrollEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new MouseScrollEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/MouseScrollEvent.h b/dom/events/MouseScrollEvent.h index b87be3510f..c97e5c32e8 100644 --- a/dom/events/MouseScrollEvent.h +++ b/dom/events/MouseScrollEvent.h @@ -59,4 +59,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMMouseScrollEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetMouseScrollEvent* aEvent); + #endif // mozilla_dom_MouseScrollEvent_h_ diff --git a/dom/events/MutationEvent.cpp b/dom/events/MutationEvent.cpp index ac4d91e4e7..189240a4be 100644 --- a/dom/events/MutationEvent.cpp +++ b/dom/events/MutationEvent.cpp @@ -119,14 +119,11 @@ MutationEvent::InitMutationEvent(const nsAString& aTypeArg, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMMutationEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalMutationEvent* aEvent) { - MutationEvent* it = new MutationEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new MutationEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/MutationEvent.h b/dom/events/MutationEvent.h index 93dc0ab221..93e9697089 100644 --- a/dom/events/MutationEvent.h +++ b/dom/events/MutationEvent.h @@ -65,4 +65,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMMutationEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::InternalMutationEvent* aEvent); + #endif // mozilla_dom_MutationEvent_h_ diff --git a/dom/events/NotifyPaintEvent.cpp b/dom/events/NotifyPaintEvent.cpp index f1fdf7eb92..cd6e705dc9 100644 --- a/dom/events/NotifyPaintEvent.cpp +++ b/dom/events/NotifyPaintEvent.cpp @@ -162,17 +162,15 @@ NotifyPaintEvent::Deserialize(const IPC::Message* aMsg, void** aIter) using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMNotifyPaintEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent, uint32_t aEventType, nsInvalidateRequestList* aInvalidateRequests) { - NotifyPaintEvent* it = new NotifyPaintEvent(aOwner, aPresContext, aEvent, - aEventType, aInvalidateRequests); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new NotifyPaintEvent(aOwner, aPresContext, aEvent, aEventType, + aInvalidateRequests); + return it.forget(); } diff --git a/dom/events/NotifyPaintEvent.h b/dom/events/NotifyPaintEvent.h index 7673c244b8..b0e09bb6f1 100644 --- a/dom/events/NotifyPaintEvent.h +++ b/dom/events/NotifyPaintEvent.h @@ -67,4 +67,12 @@ private: } // namespace dom } // namespace mozilla +// This empties aInvalidateRequests. +already_AddRefed +NS_NewDOMNotifyPaintEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetEvent* aEvent, + uint32_t aEventType = 0, + nsInvalidateRequestList* aInvalidateRequests = nullptr); + #endif // mozilla_dom_NotifyPaintEvent_h_ diff --git a/dom/events/PointerEvent.cpp b/dom/events/PointerEvent.cpp index 44d352598b..c78c4ec44f 100644 --- a/dom/events/PointerEvent.cpp +++ b/dom/events/PointerEvent.cpp @@ -164,14 +164,11 @@ PointerEvent::IsPrimary() using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMPointerEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMPointerEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetPointerEvent *aEvent) { - PointerEvent *it = new PointerEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new PointerEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/PointerEvent.h b/dom/events/PointerEvent.h index e33ad60ebf..62c5a0c365 100644 --- a/dom/events/PointerEvent.h +++ b/dom/events/PointerEvent.h @@ -55,4 +55,9 @@ void ConvertPointerTypeToString(uint16_t aPointerTypeSrc, nsAString& aPointerTyp } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMPointerEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetPointerEvent* aEvent); + #endif // mozilla_dom_PointerEvent_h_ diff --git a/dom/events/ScrollAreaEvent.cpp b/dom/events/ScrollAreaEvent.cpp index ba4e20d8ed..107f9c283e 100644 --- a/dom/events/ScrollAreaEvent.cpp +++ b/dom/events/ScrollAreaEvent.cpp @@ -100,12 +100,12 @@ ScrollAreaEvent::Deserialize(const IPC::Message* aMsg, void** aIter) using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMScrollAreaEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMScrollAreaEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalScrollAreaEvent* aEvent) { - ScrollAreaEvent* ev = new ScrollAreaEvent(aOwner, aPresContext, aEvent); - return CallQueryInterface(ev, aInstancePtrResult); + nsRefPtr ev = + new ScrollAreaEvent(aOwner, aPresContext, aEvent); + return ev.forget(); } diff --git a/dom/events/ScrollAreaEvent.h b/dom/events/ScrollAreaEvent.h index 5e1dc1b177..e9a6333c37 100644 --- a/dom/events/ScrollAreaEvent.h +++ b/dom/events/ScrollAreaEvent.h @@ -86,4 +86,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMScrollAreaEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::InternalScrollAreaEvent* aEvent); + #endif // mozilla_dom_ScrollAreaEvent_h_ diff --git a/dom/events/SimpleGestureEvent.cpp b/dom/events/SimpleGestureEvent.cpp index 4ff4522b38..9daf8a0892 100644 --- a/dom/events/SimpleGestureEvent.cpp +++ b/dom/events/SimpleGestureEvent.cpp @@ -146,14 +146,12 @@ SimpleGestureEvent::InitSimpleGestureEvent(const nsAString& aTypeArg, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMSimpleGestureEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMSimpleGestureEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetSimpleGestureEvent* aEvent) { - SimpleGestureEvent* it = new SimpleGestureEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new SimpleGestureEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/SimpleGestureEvent.h b/dom/events/SimpleGestureEvent.h index 48464e9323..0907c72304 100644 --- a/dom/events/SimpleGestureEvent.h +++ b/dom/events/SimpleGestureEvent.h @@ -78,4 +78,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMSimpleGestureEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetSimpleGestureEvent* aEvent); + #endif // mozilla_dom_SimpleGestureEvent_h_ diff --git a/dom/events/StorageEvent.cpp b/dom/events/StorageEvent.cpp index 5f91da6c50..933266fadd 100644 --- a/dom/events/StorageEvent.cpp +++ b/dom/events/StorageEvent.cpp @@ -103,16 +103,15 @@ StorageEvent::InitStorageEvent(const nsAString& aType, bool aCanBubble, } // namespace dom } // namespace mozilla -nsresult -NS_NewDOMStorageEvent(nsIDOMEvent** aDOMEvent, - mozilla::dom::EventTarget* aOwner) +using namespace mozilla; +using namespace mozilla::dom; + +already_AddRefed +NS_NewDOMStorageEvent(EventTarget* aOwner) { - nsRefPtr e = - new mozilla::dom::StorageEvent(aOwner); + nsRefPtr e = new StorageEvent(aOwner); e->SetTrusted(e->Init(aOwner)); - e.forget(aDOMEvent); - - return NS_OK; + return e.forget(); } diff --git a/dom/events/StorageEvent.h b/dom/events/StorageEvent.h index 1ed631d956..f50cb9137e 100644 --- a/dom/events/StorageEvent.h +++ b/dom/events/StorageEvent.h @@ -14,8 +14,8 @@ #include "mozilla/dom/StorageEventBinding.h" // Helper for EventDispatcher. -nsresult NS_NewDOMStorageEvent(nsIDOMEvent** aDOMEvent, - mozilla::dom::EventTarget* aOwner); +already_AddRefed +NS_NewDOMStorageEvent(mozilla::dom::EventTarget* aOwner); namespace mozilla { namespace dom { diff --git a/dom/events/TouchEvent.cpp b/dom/events/TouchEvent.cpp index 5c62ab4f03..8416dbddbf 100644 --- a/dom/events/TouchEvent.cpp +++ b/dom/events/TouchEvent.cpp @@ -238,14 +238,11 @@ TouchEvent::ShiftKey() using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMTouchEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMTouchEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetTouchEvent* aEvent) { - TouchEvent* it = new TouchEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new TouchEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/TouchEvent.h b/dom/events/TouchEvent.h index e01fe37759..d0ccc3f450 100644 --- a/dom/events/TouchEvent.h +++ b/dom/events/TouchEvent.h @@ -132,4 +132,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMTouchEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetTouchEvent* aEvent); + #endif // mozilla_dom_TouchEvent_h_ diff --git a/dom/events/TransitionEvent.cpp b/dom/events/TransitionEvent.cpp index c10e837e70..96231028f9 100644 --- a/dom/events/TransitionEvent.cpp +++ b/dom/events/TransitionEvent.cpp @@ -88,14 +88,12 @@ TransitionEvent::GetPseudoElement(nsAString& aPseudoElement) using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMTransitionEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMTransitionEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalTransitionEvent* aEvent) { - TransitionEvent *it = new TransitionEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new TransitionEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/TransitionEvent.h b/dom/events/TransitionEvent.h index cad4c44961..345181a01f 100644 --- a/dom/events/TransitionEvent.h +++ b/dom/events/TransitionEvent.h @@ -52,4 +52,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMTransitionEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::InternalTransitionEvent* aEvent); + #endif // mozilla_dom_TransitionEvent_h_ diff --git a/dom/events/UIEvent.cpp b/dom/events/UIEvent.cpp index b5ef0c4004..6e55d20068 100644 --- a/dom/events/UIEvent.cpp +++ b/dom/events/UIEvent.cpp @@ -447,14 +447,11 @@ UIEvent::GetModifierStateInternal(const nsAString& aKey) using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMUIEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetGUIEvent* aEvent) { - UIEvent* it = new UIEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new UIEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/UIEvent.h b/dom/events/UIEvent.h index ad92855fc3..35901c82e7 100644 --- a/dom/events/UIEvent.h +++ b/dom/events/UIEvent.h @@ -188,4 +188,9 @@ protected: return UIEvent::Deserialize(aMsg, aIter); \ } +already_AddRefed +NS_NewDOMUIEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetGUIEvent* aEvent); + #endif // mozilla_dom_UIEvent_h_ diff --git a/dom/events/WheelEvent.cpp b/dom/events/WheelEvent.cpp index 974bc205ec..23b7559631 100644 --- a/dom/events/WheelEvent.cpp +++ b/dom/events/WheelEvent.cpp @@ -206,14 +206,11 @@ WheelEvent::Constructor(const GlobalObject& aGlobal, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMWheelEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMWheelEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetWheelEvent* aEvent) { - WheelEvent* it = new WheelEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new WheelEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/WheelEvent.h b/dom/events/WheelEvent.h index 3ec86df2c9..596be4f8cd 100644 --- a/dom/events/WheelEvent.h +++ b/dom/events/WheelEvent.h @@ -60,4 +60,9 @@ private: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMWheelEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetWheelEvent* aEvent); + #endif // mozilla_dom_WheelEvent_h_ diff --git a/dom/events/XULCommandEvent.cpp b/dom/events/XULCommandEvent.cpp index 24c692eb86..d56cd1e19e 100644 --- a/dom/events/XULCommandEvent.cpp +++ b/dom/events/XULCommandEvent.cpp @@ -129,14 +129,12 @@ XULCommandEvent::InitCommandEvent(const nsAString& aType, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMXULCommandEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMXULCommandEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetInputEvent* aEvent) { - XULCommandEvent* it = new XULCommandEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = + new XULCommandEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/events/XULCommandEvent.h b/dom/events/XULCommandEvent.h index 9226cdb273..c9574a22cd 100644 --- a/dom/events/XULCommandEvent.h +++ b/dom/events/XULCommandEvent.h @@ -71,4 +71,9 @@ protected: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMXULCommandEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::WidgetInputEvent* aEvent); + #endif // mozilla_dom_XULCommandEvent_h_ diff --git a/dom/events/moz.build b/dom/events/moz.build index 65271055cc..d989b0cb5c 100644 --- a/dom/events/moz.build +++ b/dom/events/moz.build @@ -133,6 +133,7 @@ LOCAL_INCLUDES += [ '/dom/html', '/dom/settings', '/dom/storage', + '/dom/svg', '/dom/workers', '/dom/xml', '/dom/xul', diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index d09d436fdd..1b4539c62c 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -5369,17 +5369,13 @@ FireEventForAccessibility(nsIDOMHTMLInputElement* aTarget, nsPresContext* aPresContext, const nsAString& aEventType) { - nsCOMPtr event; nsCOMPtr element = do_QueryInterface(aTarget); - if (NS_SUCCEEDED(EventDispatcher::CreateEvent(element, aPresContext, nullptr, - NS_LITERAL_STRING("Events"), - getter_AddRefs(event)))) { - event->InitEvent(aEventType, true, true); - event->SetTrusted(true); + nsRefPtr event = NS_NewDOMEvent(element, aPresContext, nullptr); + event->InitEvent(aEventType, true, true); + event->SetTrusted(true); - EventDispatcher::DispatchDOMEvent(aTarget, nullptr, event, aPresContext, - nullptr); - } + EventDispatcher::DispatchDOMEvent(aTarget, nullptr, event, aPresContext, + nullptr); return NS_OK; } diff --git a/dom/interfaces/events/nsIDOMEvent.idl b/dom/interfaces/events/nsIDOMEvent.idl index b6dc3b6b01..ef25d397b0 100644 --- a/dom/interfaces/events/nsIDOMEvent.idl +++ b/dom/interfaces/events/nsIDOMEvent.idl @@ -40,7 +40,7 @@ class EventTarget; * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html */ -[builtinclass, uuid(02d54f52-a1f5-4ad2-b560-36f14012935e)] +[builtinclass, uuid(63857daf-c084-4ea6-a8b9-6812e3176991)] interface nsIDOMEvent : nsISupports { // PhaseType @@ -214,163 +214,5 @@ interface nsIDOMEvent : nsISupports [notxpcom] boolean Deserialize(in ConstIPCMessagePtr aMsg, out voidPtr aIter); [noscript,notxpcom] void SetOwner(in EventTargetPtr aOwner); [notxpcom] DOMEventPtr InternalDOMEvent(); + [noscript] void stopCrossProcessForwarding(); }; - -%{C++ - -nsresult -NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetEvent* aEvent); -nsresult -NS_NewDOMDataContainerEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetEvent* aEvent); -nsresult -NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetGUIEvent* aEvent); -nsresult -NS_NewDOMMouseEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetMouseEvent* aEvent); -nsresult -NS_NewDOMFocusEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::InternalFocusEvent* aEvent); -nsresult -NS_NewDOMMouseScrollEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetMouseScrollEvent* aEvent); -nsresult -NS_NewDOMWheelEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetWheelEvent* aEvent); -nsresult -NS_NewDOMDragEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetDragEvent* aEvent); -nsresult -NS_NewDOMClipboardEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::InternalClipboardEvent* aEvent); -nsresult -NS_NewDOMInputEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::InternalEditorInputEvent* aEvent); -nsresult -NS_NewDOMKeyboardEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetKeyboardEvent* aEvent); - -nsresult -NS_NewDOMBeforeAfterKeyboardEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::InternalBeforeAfterKeyboardEvent* aEvent); - -nsresult -NS_NewDOMCompositionEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetCompositionEvent* aEvent); -nsresult -NS_NewDOMMutationEvent(nsIDOMEvent** aResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::InternalMutationEvent* aEvent); -nsresult -NS_NewDOMDeviceMotionEvent(nsIDOMEvent** aResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetEvent* aEvent); -nsresult -NS_NewDOMBeforeUnloadEvent(nsIDOMEvent** aResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetEvent* aEvent); -nsresult -NS_NewDOMSVGEvent(nsIDOMEvent** aResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetEvent* aEvent); -nsresult -NS_NewDOMSVGZoomEvent(nsIDOMEvent** aResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::InternalSVGZoomEvent* aEvent); -nsresult -NS_NewDOMTimeEvent(nsIDOMEvent** aResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::InternalSMILTimeEvent* aEvent); -nsresult -NS_NewDOMXULCommandEvent(nsIDOMEvent** aResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetInputEvent* aEvent); -nsresult -NS_NewDOMCommandEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetCommandEvent* aEvent); -nsresult -NS_NewDOMMessageEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetEvent* aEvent); -// This empties aInvalidateRequests. -nsresult -NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetEvent* aEvent, - uint32_t aEventType = 0, - nsInvalidateRequestList* aInvalidateRequests = nullptr); -nsresult -NS_NewDOMSimpleGestureEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetSimpleGestureEvent* aEvent); -nsresult -NS_NewDOMScrollAreaEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::InternalScrollAreaEvent* aEvent); -nsresult -NS_NewDOMTransitionEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::InternalTransitionEvent* aEvent); -nsresult -NS_NewDOMAnimationEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::InternalAnimationEvent* aEvent); -nsresult -NS_NewDOMPointerEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetPointerEvent* aEvent); -nsresult -NS_NewDOMTouchEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetTouchEvent* aEvent); -nsresult -NS_NewDOMCustomEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, - nsPresContext* aPresContext, - mozilla::WidgetEvent* aEvent); -%} diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index 03c3ca937a..27f61658b5 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -158,7 +158,10 @@ parent: nsString aName, nsString aFeatures, nsString aBaseURI) - returns (bool windowOpened, FrameScriptInfo[] frameScripts, nsCString urlToLoad); + returns (nsresult rv, + bool windowOpened, + FrameScriptInfo[] frameScripts, + nsCString urlToLoad); sync SyncMessage(nsString aMessage, ClonedMessageData aData, CpowEntry[] aCpows, Principal aPrincipal) diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index f446338173..455391f290 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -249,7 +249,16 @@ TabChildBase::InitializeRootMetrics() // This is the root layer, so the cumulative resolution is the same // as the resolution. mLastRootMetrics.SetPresShellResolution(mLastRootMetrics.GetCumulativeResolution().ToScaleFactor().scale); - mLastRootMetrics.SetScrollOffset(CSSPoint(0, 0)); + + nsCOMPtr shell = GetPresShell(); + if (shell && shell->GetRootScrollFrameAsScrollable()) { + // The session history code might restore a scroll position when navigating + // back or forward, and we don't want to clobber that. + nsPoint pos = shell->GetRootScrollFrameAsScrollable()->GetScrollPosition(); + mLastRootMetrics.SetScrollOffset(CSSPoint::FromAppUnits(pos)); + } else { + mLastRootMetrics.SetScrollOffset(CSSPoint(0, 0)); + } TABC_LOG("After InitializeRootMetrics, mLastRootMetrics is %s\n", Stringify(mLastRootMetrics).c_str()); @@ -1592,16 +1601,23 @@ TabChild::ProvideWindowCommon(nsIDOMWindow* aOpener, // tab, then we want to enforce that the new window is also a remote tab. features.AppendLiteral(",remote"); + nsresult rv; + if (!SendCreateWindow(newChild, aChromeFlags, aCalledFromJS, aPositionSpecified, aSizeSpecified, url, name, NS_ConvertUTF8toUTF16(features), NS_ConvertUTF8toUTF16(baseURIString), + &rv, aWindowIsNew, &frameScripts, &urlToLoad)) { return NS_ERROR_NOT_AVAILABLE; } + + if (NS_FAILED(rv)) { + return rv; + } } if (!*aWindowIsNew) { PBrowserChild::Send__delete__(newChild); @@ -2210,6 +2226,13 @@ TabChild::RecvNotifyAPZStateChange(const ViewID& aViewId, const int& aArg) { mAPZEventState->ProcessAPZStateChange(GetDocument(), aViewId, aChange, aArg); + if (aChange == APZStateChange::TransformEnd) { + // This is used by tests to determine when the APZ is done doing whatever + // it's doing. XXX generify this as needed when writing additional tests. + DispatchMessageManagerMessage( + NS_LITERAL_STRING("APZ:TransformEnd"), + NS_LITERAL_STRING("{}")); + } return true; } @@ -3509,6 +3532,10 @@ TabChildGlobal::MarkForCC() if (mTabChild) { mTabChild->MarkScopesForCC(); } + EventListenerManager* elm = GetExistingListenerManager(); + if (elm) { + elm->MarkForCC(); + } return mMessageManager ? mMessageManager->MarkForCC() : false; } diff --git a/dom/ipc/TabMessageUtils.cpp b/dom/ipc/TabMessageUtils.cpp index efad15efc7..6949d1b367 100644 --- a/dom/ipc/TabMessageUtils.cpp +++ b/dom/ipc/TabMessageUtils.cpp @@ -5,9 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/EventDispatcher.h" +#include "mozilla/dom/Event.h" #include "mozilla/dom/TabMessageUtils.h" #include "nsCOMPtr.h" -#include "nsIDOMEvent.h" namespace mozilla { namespace dom { @@ -20,11 +20,8 @@ ReadRemoteEvent(const IPC::Message* aMsg, void** aIter, nsString type; NS_ENSURE_TRUE(ReadParam(aMsg, aIter, &type), false); - nsCOMPtr event; - EventDispatcher::CreateEvent(nullptr, nullptr, nullptr, type, - getter_AddRefs(event)); - aResult->mEvent = do_QueryInterface(event); - NS_ENSURE_TRUE(aResult->mEvent, false); + aResult->mEvent = EventDispatcher::CreateEvent(nullptr, nullptr, nullptr, + type); return aResult->mEvent->Deserialize(aMsg, aIter); } diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index 20801cac7f..fc132cf722 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -648,6 +648,7 @@ TabParent::RecvCreateWindow(PBrowserParent* aNewTab, const nsString& aName, const nsString& aFeatures, const nsString& aBaseURI, + nsresult* aResult, bool* aWindowIsNew, InfallibleTArray* aFrameScripts, nsCString* aURLToLoad) @@ -655,14 +656,14 @@ TabParent::RecvCreateWindow(PBrowserParent* aNewTab, // We always expect to open a new window here. If we don't, it's an error. *aWindowIsNew = true; - if (IsBrowserOrApp()) { + if (NS_WARN_IF(IsBrowserOrApp())) return false; - } - nsresult rv; nsCOMPtr pwwatch = - do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, false); + do_GetService(NS_WINDOWWATCHER_CONTRACTID, aResult); + + if (NS_WARN_IF(NS_FAILED(*aResult))) + return true; TabParent* newTab = TabParent::GetFrom(aNewTab); MOZ_ASSERT(newTab); @@ -693,8 +694,9 @@ TabParent::RecvCreateWindow(PBrowserParent* aNewTab, // opened one. if (!parent) { parent = FindMostRecentOpenWindow(); - if (!parent) { - return false; + if (NS_WARN_IF(!parent)) { + *aResult = NS_ERROR_FAILURE; + return true; } nsCOMPtr rootChromeWin = do_QueryInterface(parent); @@ -712,7 +714,10 @@ TabParent::RecvCreateWindow(PBrowserParent* aNewTab, // Opening new tabs is the easy case... if (openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB) { - NS_ENSURE_TRUE(browserDOMWin, false); + if (NS_WARN_IF(!browserDOMWin)) { + *aResult = NS_ERROR_FAILURE; + return true; + } bool isPrivate; nsCOMPtr loadContext = GetLoadContext(); @@ -744,45 +749,65 @@ TabParent::RecvCreateWindow(PBrowserParent* aNewTab, // TabChild has sent us a baseURI with which we can ensure that // the URI we pass to WindowWatcher is valid. nsCOMPtr baseURI; - rv = NS_NewURI(getter_AddRefs(baseURI), aBaseURI); - NS_ENSURE_SUCCESS(rv, false); + *aResult = NS_NewURI(getter_AddRefs(baseURI), aBaseURI); - nsCOMPtr finalURI; - rv = NS_NewURI(getter_AddRefs(finalURI), NS_ConvertUTF16toUTF8(aURI).get(), baseURI); - NS_ENSURE_SUCCESS(rv, false); + if (NS_WARN_IF(NS_FAILED(*aResult))) + return true; nsAutoCString finalURIString; - finalURI->GetSpec(finalURIString); + if (!aURI.IsEmpty()) { + nsCOMPtr finalURI; + *aResult = NS_NewURI(getter_AddRefs(finalURI), NS_ConvertUTF16toUTF8(aURI).get(), baseURI); + + if (NS_WARN_IF(NS_FAILED(*aResult))) + return true; + + finalURI->GetSpec(finalURIString); + } nsCOMPtr window; AutoUseNewTab aunt(newTab, aWindowIsNew, aURLToLoad); - rv = pwwatch->OpenWindow2(parent, finalURIString.get(), - NS_ConvertUTF16toUTF8(aName).get(), - NS_ConvertUTF16toUTF8(aFeatures).get(), aCalledFromJS, - false, false, this, nullptr, nullptr, getter_AddRefs(window)); - NS_ENSURE_SUCCESS(rv, false); + *aResult = pwwatch->OpenWindow2(parent, finalURIString.get(), + NS_ConvertUTF16toUTF8(aName).get(), + NS_ConvertUTF16toUTF8(aFeatures).get(), aCalledFromJS, + false, false, this, nullptr, nullptr, getter_AddRefs(window)); + + if (NS_WARN_IF(NS_FAILED(*aResult))) + return true; + + *aResult = NS_ERROR_FAILURE; nsCOMPtr pwindow = do_QueryInterface(window); - NS_ENSURE_TRUE(pwindow, false); + if (NS_WARN_IF(!pwindow)) { + return true; + } nsCOMPtr windowDocShell = pwindow->GetDocShell(); - NS_ENSURE_TRUE(windowDocShell, false); + if (NS_WARN_IF(!windowDocShell)) { + return true; + } nsCOMPtr treeOwner; windowDocShell->GetTreeOwner(getter_AddRefs(treeOwner)); nsCOMPtr xulWin = do_GetInterface(treeOwner); - NS_ENSURE_TRUE(xulWin, false); + if (NS_WARN_IF(!xulWin)) { + return true; + } nsCOMPtr xulBrowserWin; xulWin->GetXULBrowserWindow(getter_AddRefs(xulBrowserWin)); - NS_ENSURE_TRUE(xulBrowserWin, false); + if (NS_WARN_IF(!xulBrowserWin)) { + return true; + } nsCOMPtr newRemoteTab; - rv = xulBrowserWin->ForceInitialBrowserRemote(getter_AddRefs(newRemoteTab)); - NS_ENSURE_SUCCESS(rv, false); + *aResult = xulBrowserWin->ForceInitialBrowserRemote(getter_AddRefs(newRemoteTab)); + + if (NS_WARN_IF(NS_FAILED(*aResult))) + return true; MOZ_ASSERT(TabParent::GetFrom(newRemoteTab) == newTab); @@ -2996,8 +3021,7 @@ TabParent::LayerTreeUpdate(bool aActive) return true; } - nsCOMPtr event; - NS_NewDOMEvent(getter_AddRefs(event), mFrameElement, nullptr, nullptr); + nsRefPtr event = NS_NewDOMEvent(mFrameElement, nullptr, nullptr); if (aActive) { event->InitEvent(NS_LITERAL_STRING("MozLayerTreeReady"), true, false); } else { @@ -3036,8 +3060,7 @@ TabParent::RecvRemotePaintIsReady() return true; } - nsCOMPtr event; - NS_NewDOMEvent(getter_AddRefs(event), mFrameElement, nullptr, nullptr); + nsRefPtr event = NS_NewDOMEvent(mFrameElement, nullptr, nullptr); event->InitEvent(NS_LITERAL_STRING("MozAfterRemotePaint"), false, false); event->SetTrusted(true); event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h index 6772506aef..10fd8707cc 100644 --- a/dom/ipc/TabParent.h +++ b/dom/ipc/TabParent.h @@ -144,6 +144,7 @@ public: const nsString& aName, const nsString& aFeatures, const nsString& aBaseURI, + nsresult* aResult, bool* aWindowIsNew, InfallibleTArray* aFrameScripts, nsCString* aURLToLoad) override; diff --git a/dom/media/MediaRecorder.cpp b/dom/media/MediaRecorder.cpp index 9be55fe183..e0045dd273 100644 --- a/dom/media/MediaRecorder.cpp +++ b/dom/media/MediaRecorder.cpp @@ -1043,12 +1043,7 @@ MediaRecorder::DispatchSimpleEvent(const nsAString & aStr) return; } - nsCOMPtr event; - rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - if (NS_FAILED(rv)) { - NS_WARNING("Failed to create the error event!!!"); - return; - } + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); rv = event->InitEvent(aStr, false, false); if (NS_FAILED(rv)) { diff --git a/dom/media/TextTrackList.cpp b/dom/media/TextTrackList.cpp index 6e550945a6..59d5ecdfa7 100644 --- a/dom/media/TextTrackList.cpp +++ b/dom/media/TextTrackList.cpp @@ -163,14 +163,9 @@ TextTrackList::DispatchTrackEvent(nsIDOMEvent* aEvent) void TextTrackList::CreateAndDispatchChangeEvent() { - nsCOMPtr event; - nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - if (NS_FAILED(rv)) { - NS_WARNING("Failed to create the error event!"); - return; - } + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); - rv = event->InitEvent(NS_LITERAL_STRING("change"), false, false); + nsresult rv = event->InitEvent(NS_LITERAL_STRING("change"), false, false); if (NS_FAILED(rv)) { NS_WARNING("Failed to init the change event!"); return; diff --git a/dom/notification/DesktopNotification.cpp b/dom/notification/DesktopNotification.cpp index 0b5d7ee30e..19ebff589a 100644 --- a/dom/notification/DesktopNotification.cpp +++ b/dom/notification/DesktopNotification.cpp @@ -173,16 +173,14 @@ DesktopNotification::DispatchNotificationEvent(const nsString& aName) return; } - nsCOMPtr event; - nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - if (NS_SUCCEEDED(rv)) { - // it doesn't bubble, and it isn't cancelable - rv = event->InitEvent(aName, false, false); - if (NS_SUCCEEDED(rv)) { - event->SetTrusted(true); - DispatchDOMEvent(nullptr, event, nullptr, nullptr); - } + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); + // it doesn't bubble, and it isn't cancelable + nsresult rv = event->InitEvent(aName, false, false); + if (NS_FAILED(rv)) { + return; } + event->SetTrusted(true); + DispatchDOMEvent(nullptr, event, nullptr, nullptr); } nsresult diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index 10cff2c61d..a910179204 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -1080,8 +1080,7 @@ bool Notification::DispatchClickEvent() { AssertIsOnTargetThread(); - nsCOMPtr event; - NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); nsresult rv = event->InitEvent(NS_LITERAL_STRING("click"), false, true); NS_ENSURE_SUCCESS(rv, false); event->SetTrusted(true); diff --git a/dom/offline/nsDOMOfflineResourceList.cpp b/dom/offline/nsDOMOfflineResourceList.cpp index 2bcf93a797..ddfe7ecbbd 100644 --- a/dom/offline/nsDOMOfflineResourceList.cpp +++ b/dom/offline/nsDOMOfflineResourceList.cpp @@ -21,6 +21,7 @@ #include "nsIObserverService.h" #include "nsIScriptGlobalObject.h" #include "nsIWebNavigation.h" +#include "mozilla/dom/Event.h" #include "mozilla/dom/OfflineResourceListBinding.h" #include "mozilla/EventDispatcher.h" #include "mozilla/Preferences.h" @@ -547,11 +548,7 @@ nsDOMOfflineResourceList::SendEvent(const nsAString &aEventName) return NS_OK; } - nsCOMPtr event; - nsresult rv = EventDispatcher::CreateEvent(this, nullptr, nullptr, - NS_LITERAL_STRING("Events"), - getter_AddRefs(event)); - NS_ENSURE_SUCCESS(rv, rv); + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); event->InitEvent(aEventName, false, true); // We assume anyone that managed to call SendEvent is trusted diff --git a/dom/presentation/PresentationSession.cpp b/dom/presentation/PresentationSession.cpp index c6d5ff6d17..06fe102165 100644 --- a/dom/presentation/PresentationSession.cpp +++ b/dom/presentation/PresentationSession.cpp @@ -5,8 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/AsyncEventDispatcher.h" +#include "mozilla/dom/MessageEvent.h" #include "nsCycleCollectionParticipant.h" -#include "nsIDOMMessageEvent.h" #include "nsIPresentationService.h" #include "nsServiceManagerUtils.h" #include "nsStringStream.h" @@ -260,13 +260,9 @@ PresentationSession::DispatchMessageEvent(JS::Handle aData) return rv; } - nsCOMPtr event; - rv = NS_NewDOMMessageEvent(getter_AddRefs(event), this, nullptr, nullptr); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } + nsRefPtr messageEvent = + NS_NewDOMMessageEvent(this, nullptr, nullptr); - nsCOMPtr messageEvent = do_QueryInterface(event); rv = messageEvent->InitMessageEvent(NS_LITERAL_STRING("message"), false, false, aData, @@ -276,9 +272,9 @@ PresentationSession::DispatchMessageEvent(JS::Handle aData) return rv; } - event->SetTrusted(true); + messageEvent->SetTrusted(true); nsRefPtr asyncDispatcher = - new AsyncEventDispatcher(this, event); + new AsyncEventDispatcher(this, static_cast(messageEvent)); return asyncDispatcher->PostDOMEvent(); } diff --git a/dom/smil/TimeEvent.cpp b/dom/smil/TimeEvent.cpp index 22a37ec6b9..40a60aa882 100644 --- a/dom/smil/TimeEvent.cpp +++ b/dom/smil/TimeEvent.cpp @@ -80,14 +80,11 @@ TimeEvent::InitTimeEvent(const nsAString& aTypeArg, using namespace mozilla; using namespace mozilla::dom; -nsresult -NS_NewDOMTimeEvent(nsIDOMEvent** aInstancePtrResult, - EventTarget* aOwner, +already_AddRefed +NS_NewDOMTimeEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalSMILTimeEvent* aEvent) { - TimeEvent* it = new TimeEvent(aOwner, aPresContext, aEvent); - NS_ADDREF(it); - *aInstancePtrResult = static_cast(it); - return NS_OK; + nsRefPtr it = new TimeEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/smil/TimeEvent.h b/dom/smil/TimeEvent.h index 74c8ff6e32..be41de026b 100644 --- a/dom/smil/TimeEvent.h +++ b/dom/smil/TimeEvent.h @@ -63,4 +63,9 @@ private: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMTimeEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::InternalSMILTimeEvent* aEvent); + #endif // mozilla_dom_TimeEvent_h_ diff --git a/dom/speakermanager/SpeakerManager.cpp b/dom/speakermanager/SpeakerManager.cpp index d848e011ab..16dc7db7bd 100644 --- a/dom/speakermanager/SpeakerManager.cpp +++ b/dom/speakermanager/SpeakerManager.cpp @@ -5,16 +5,19 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "SpeakerManager.h" -#include "nsIDOMClassInfo.h" -#include "nsIDOMEvent.h" -#include "nsIDOMEventListener.h" -#include "SpeakerManagerService.h" -#include "nsIPermissionManager.h" -#include "nsIInterfaceRequestorUtils.h" -#include "nsIDocShell.h" -#include "AudioChannelService.h" + #include "mozilla/Services.h" +#include "mozilla/dom/Event.h" + +#include "AudioChannelService.h" +#include "nsIDocShell.h" +#include "nsIDOMClassInfo.h" +#include "nsIDOMEventListener.h" +#include "nsIInterfaceRequestorUtils.h" +#include "nsIPermissionManager.h" +#include "SpeakerManagerService.h" + namespace mozilla { namespace dom { @@ -86,12 +89,7 @@ SpeakerManager::DispatchSimpleEvent(const nsAString& aStr) return; } - nsCOMPtr event; - rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); - if (NS_FAILED(rv)) { - NS_WARNING("Failed to create the error event!!!"); - return; - } + nsRefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); rv = event->InitEvent(aStr, false, false); if (NS_FAILED(rv)) { diff --git a/dom/svg/SVGZoomEvent.cpp b/dom/svg/SVGZoomEvent.cpp index 8749927d23..c25acf01d4 100644 --- a/dom/svg/SVGZoomEvent.cpp +++ b/dom/svg/SVGZoomEvent.cpp @@ -90,13 +90,14 @@ SVGZoomEvent::~SVGZoomEvent() //////////////////////////////////////////////////////////////////////// // Exported creation functions: -nsresult -NS_NewDOMSVGZoomEvent(nsIDOMEvent** aInstancePtrResult, - mozilla::dom::EventTarget* aOwner, +using namespace mozilla; +using namespace mozilla::dom; + +already_AddRefed +NS_NewDOMSVGZoomEvent(EventTarget* aOwner, nsPresContext* aPresContext, mozilla::InternalSVGZoomEvent* aEvent) { - mozilla::dom::SVGZoomEvent* it = - new mozilla::dom::SVGZoomEvent(aOwner, aPresContext, aEvent); - return CallQueryInterface(it, aInstancePtrResult); + nsRefPtr it = new SVGZoomEvent(aOwner, aPresContext, aEvent); + return it.forget(); } diff --git a/dom/svg/SVGZoomEvent.h b/dom/svg/SVGZoomEvent.h index 78a3c1eda2..e044bbef8d 100644 --- a/dom/svg/SVGZoomEvent.h +++ b/dom/svg/SVGZoomEvent.h @@ -71,4 +71,9 @@ private: } // namespace dom } // namespace mozilla +already_AddRefed +NS_NewDOMSVGZoomEvent(mozilla::dom::EventTarget* aOwner, + nsPresContext* aPresContext, + mozilla::InternalSVGZoomEvent* aEvent); + #endif // mozilla_dom_SVGZoomEvent_h diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 976f7ff194..ee593878a1 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -2216,14 +2216,10 @@ public: WorkerGlobalScope* globalScope = aWorkerPrivate->GlobalScope(); - nsCOMPtr event; - nsresult rv = - NS_NewDOMEvent(getter_AddRefs(event), globalScope, nullptr, nullptr); - if (NS_WARN_IF(NS_FAILED(rv))) { - return false; - } + nsRefPtr event = NS_NewDOMEvent(globalScope, nullptr, nullptr); - rv = event->InitEvent(NS_LITERAL_STRING("pushsubscriptionchange"), false, false); + nsresult rv = event->InitEvent(NS_LITERAL_STRING("pushsubscriptionchange"), + false, false); if (NS_WARN_IF(NS_FAILED(rv))) { return false; } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 4d401e7124..1deeb42c34 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1258,15 +1258,9 @@ private: WorkerGlobalScope* globalScope = aWorkerPrivate->GlobalScope(); - nsCOMPtr event; - nsresult rv = - NS_NewDOMEvent(getter_AddRefs(event), globalScope, nullptr, nullptr); - if (NS_FAILED(rv)) { - Throw(aCx, rv); - return false; - } + nsRefPtr event = NS_NewDOMEvent(globalScope, nullptr, nullptr); - rv = event->InitEvent(NS_LITERAL_STRING("close"), false, false); + nsresult rv = event->InitEvent(NS_LITERAL_STRING("close"), false, false); if (NS_FAILED(rv)) { Throw(aCx, rv); return false; @@ -3848,12 +3842,9 @@ WorkerPrivate::OfflineStatusChangeEventInternal(JSContext* aCx, bool aIsOffline) eventType.AssignLiteral("online"); } - nsCOMPtr event; - nsresult rv = - NS_NewDOMEvent(getter_AddRefs(event), globalScope, nullptr, nullptr); - NS_ENSURE_SUCCESS_VOID(rv); + nsRefPtr event = NS_NewDOMEvent(globalScope, nullptr, nullptr); - rv = event->InitEvent(eventType, false, false); + nsresult rv = event->InitEvent(eventType, false, false); NS_ENSURE_SUCCESS_VOID(rv); event->SetTrusted(true); diff --git a/dom/workers/XMLHttpRequest.cpp b/dom/workers/XMLHttpRequest.cpp index d1f52ad2f2..61df0d4da1 100644 --- a/dom/workers/XMLHttpRequest.cpp +++ b/dom/workers/XMLHttpRequest.cpp @@ -1399,7 +1399,7 @@ EventRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) MOZ_ASSERT(target); - nsCOMPtr event; + nsRefPtr event; if (mProgressEvent) { ProgressEventInit init; init.mBubbles = false; @@ -1411,7 +1411,7 @@ EventRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) event = ProgressEvent::Constructor(target, mType, init); } else { - NS_NewDOMEvent(getter_AddRefs(event), target, nullptr, nullptr); + event = NS_NewDOMEvent(target, nullptr, nullptr); if (event) { event->InitEvent(mType, false, false); @@ -1802,13 +1802,10 @@ XMLHttpRequest::DispatchPrematureAbortEvent(EventTarget* aTarget, return; } - nsCOMPtr event; + nsRefPtr event; if (aEventType.EqualsLiteral("readystatechange")) { - NS_NewDOMEvent(getter_AddRefs(event), aTarget, nullptr, nullptr); - - if (event) { - event->InitEvent(aEventType, false, false); - } + event = NS_NewDOMEvent(aTarget, nullptr, nullptr); + event->InitEvent(aEventType, false, false); } else { ProgressEventInit init; diff --git a/dom/xml/nsXMLPrettyPrinter.cpp b/dom/xml/nsXMLPrettyPrinter.cpp index 906ffc4308..91fcf6f727 100644 --- a/dom/xml/nsXMLPrettyPrinter.cpp +++ b/dom/xml/nsXMLPrettyPrinter.cpp @@ -23,7 +23,7 @@ #include "mozilla/Preferences.h" #include "nsIDocument.h" #include "nsVariant.h" -#include "nsIDOMCustomEvent.h" +#include "mozilla/dom/CustomEvent.h" using namespace mozilla; using namespace mozilla::dom; @@ -156,22 +156,19 @@ nsXMLPrettyPrinter::PrettyPrint(nsIDocument* aDocument, NS_ENSURE_SUCCESS(rv, rv); // Fire an event at the bound element to pass it |resultFragment|. - nsCOMPtr domEvent; - rv = NS_NewDOMCustomEvent(getter_AddRefs(domEvent), rootCont, - nullptr, nullptr); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr customEvent = do_QueryInterface(domEvent); - MOZ_ASSERT(customEvent); + nsRefPtr event = + NS_NewDOMCustomEvent(rootCont, nullptr, nullptr); + MOZ_ASSERT(event); nsCOMPtr resultFragmentVariant = new nsVariant(); rv = resultFragmentVariant->SetAsISupports(resultFragment); MOZ_ASSERT(NS_SUCCEEDED(rv)); - rv = customEvent->InitCustomEvent(NS_LITERAL_STRING("prettyprint-dom-created"), - /* bubbles = */ false, /* cancelable = */ false, - /* detail = */ resultFragmentVariant); + rv = event->InitCustomEvent(NS_LITERAL_STRING("prettyprint-dom-created"), + /* bubbles = */ false, /* cancelable = */ false, + /* detail = */ resultFragmentVariant); NS_ENSURE_SUCCESS(rv, rv); - customEvent->SetTrusted(true); + event->SetTrusted(true); bool dummy; - rv = rootCont->DispatchEvent(domEvent, &dummy); + rv = rootCont->DispatchEvent(static_cast(event), &dummy); NS_ENSURE_SUCCESS(rv, rv); // Observe the document so we know when to switch to "normal" view diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 9100eea797..3e7262a482 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -3097,6 +3097,7 @@ void AsyncPanZoomController::SetState(PanZoomState aNewState) // Intentional scoping for mutex { ReentrantMonitorAutoEnter lock(mMonitor); + APZC_LOG("%p changing from state %d to %d\n", this, mState, aNewState); oldState = mState; mState = aNewState; } diff --git a/gfx/layers/apz/util/APZCCallbackHelper.cpp b/gfx/layers/apz/util/APZCCallbackHelper.cpp index 7ad7ec7cf1..aedef28c6f 100644 --- a/gfx/layers/apz/util/APZCCallbackHelper.cpp +++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp @@ -266,6 +266,36 @@ APZCCallbackHelper::GetOrCreateScrollIdentifiers(nsIContent* aContent, return false; } +void +APZCCallbackHelper::InitializeRootDisplayport(nsIPresShell* aPresShell) +{ + // Create a view-id and set a zero-margin displayport for the root element + // of the root document in the chrome process. This ensures that the scroll + // frame for this element gets an APZC, which in turn ensures that all content + // in the chrome processes is covered by an APZC. + // The displayport is zero-margin because this element is generally not + // actually scrollable (if it is, APZC will set proper margins when it's + // scrolled). + if (!aPresShell) { + return; + } + + MOZ_ASSERT(aPresShell->GetDocument()); + nsIContent* content = aPresShell->GetDocument()->GetDocumentElement(); + if (!content) { + return; + } + + uint32_t presShellId; + FrameMetrics::ViewID viewId; + if (APZCCallbackHelper::GetOrCreateScrollIdentifiers(content, &presShellId, &viewId)) { + // Note that the base rect that goes with these margins is set in + // nsRootBoxFrame::BuildDisplayList. + nsLayoutUtils::SetDisplayPortMargins(content, aPresShell, ScreenMargin(), 0, + nsLayoutUtils::RepaintMode::DoNotRepaint); + } +} + class FlingSnapEvent : public nsRunnable { typedef mozilla::layers::FrameMetrics::ViewID ViewID; diff --git a/gfx/layers/apz/util/APZCCallbackHelper.h b/gfx/layers/apz/util/APZCCallbackHelper.h index 26502de328..e2d9ff607d 100644 --- a/gfx/layers/apz/util/APZCCallbackHelper.h +++ b/gfx/layers/apz/util/APZCCallbackHelper.h @@ -68,6 +68,10 @@ public: uint32_t* aPresShellIdOut, FrameMetrics::ViewID* aViewIdOut); + /* Initialize a zero-margin displayport on the root document element of the + given presShell. */ + static void InitializeRootDisplayport(nsIPresShell* aPresShell); + /* Tell layout to perform scroll snapping for the scrollable frame with the * given scroll id. aDestination specifies the expected landing position of * a current fling or scrolling animation that should be used to select diff --git a/gfx/layers/apz/util/ChromeProcessController.cpp b/gfx/layers/apz/util/ChromeProcessController.cpp index 5bc5aa0568..3fb505bc3e 100644 --- a/gfx/layers/apz/util/ChromeProcessController.cpp +++ b/gfx/layers/apz/util/ChromeProcessController.cpp @@ -38,30 +38,7 @@ ChromeProcessController::ChromeProcessController(nsIWidget* aWidget, void ChromeProcessController::InitializeRoot() { - // Create a view-id and set a zero-margin displayport for the root element - // of the root document in the chrome process. This ensures that the scroll - // frame for this element gets an APZC, which in turn ensures that all content - // in the chrome processes is covered by an APZC. - // The displayport is zero-margin because this element is generally not - // actually scrollable (if it is, APZC will set proper margins when it's - // scrolled). - nsIPresShell* presShell = GetPresShell(); - if (!presShell) { - return; - } - - MOZ_ASSERT(presShell->GetDocument()); - nsIContent* content = presShell->GetDocument()->GetDocumentElement(); - if (!content) { - return; - } - - uint32_t presShellId; - FrameMetrics::ViewID viewId; - if (APZCCallbackHelper::GetOrCreateScrollIdentifiers(content, &presShellId, &viewId)) { - nsLayoutUtils::SetDisplayPortMargins(content, presShell, ScreenMargin(), 0, - nsLayoutUtils::RepaintMode::DoNotRepaint); - } + APZCCallbackHelper::InitializeRootDisplayport(GetPresShell()); } void diff --git a/js/src/gc/Marking.cpp b/js/src/gc/Marking.cpp index d39e7b52a0..868a5c0af0 100644 --- a/js/src/gc/Marking.cpp +++ b/js/src/gc/Marking.cpp @@ -1723,8 +1723,8 @@ GCMarker::enterWeakMarkingMode() if (weakMapAction() == ExpandWeakMaps) { tag_ = TracerKindTag::WeakMarking; - for (GCCompartmentGroupIter c(runtime()); !c.done(); c.next()) { - for (WeakMapBase* m = c->gcWeakMapList; m; m = m->next) { + for (GCZoneGroupIter zone(runtime()); !zone.done(); zone.next()) { + for (WeakMapBase* m = zone->gcWeakMapList; m; m = m->next) { if (m->marked) m->markEphemeronEntries(this); } diff --git a/js/src/gc/Zone.cpp b/js/src/gc/Zone.cpp index 991b5e7491..163ed06c8b 100644 --- a/js/src/gc/Zone.cpp +++ b/js/src/gc/Zone.cpp @@ -27,6 +27,7 @@ JS::Zone::Zone(JSRuntime* rt) debuggers(nullptr), arenas(rt), types(this), + gcWeakMapList(nullptr), compartments(), gcGrayRoots(), gcMallocBytes(0), @@ -203,6 +204,13 @@ Zone::sweepBreakpoints(FreeOp* fop) } } +void +Zone::sweepWeakMaps() +{ + /* Finalize unreachable (key,value) pairs in all weak maps. */ + WeakMapBase::sweepZone(this); +} + void Zone::discardJitCode(FreeOp* fop) { diff --git a/js/src/gc/Zone.h b/js/src/gc/Zone.h index 365a63a6d2..c8684a330f 100644 --- a/js/src/gc/Zone.h +++ b/js/src/gc/Zone.h @@ -242,6 +242,7 @@ struct Zone : public JS::shadow::Zone, LogTenurePromotionQueue awaitingTenureLogging; void sweepBreakpoints(js::FreeOp* fop); + void sweepWeakMaps(); void sweepCompartments(js::FreeOp* fop, bool keepAtleastOne, bool lastGC); js::jit::JitZone* createJitZone(JSContext* cx); @@ -267,6 +268,9 @@ struct Zone : public JS::shadow::Zone, js::TypeZone types; + /* Linked list of live weakmaps in this zone. */ + js::WeakMapBase* gcWeakMapList; + // The set of compartments in this zone. typedef js::Vector CompartmentVector; CompartmentVector compartments; diff --git a/js/src/jit-test/tests/gc/bug-1165966.js b/js/src/jit-test/tests/gc/bug-1165966.js new file mode 100644 index 0000000000..bcc8ccf806 --- /dev/null +++ b/js/src/jit-test/tests/gc/bug-1165966.js @@ -0,0 +1,6 @@ +// |jit-test| --no-ggc; allow-unhandlable-oom +load(libdir + 'oomTest.js'); +var g = newGlobal(); +oomTest(function() { + Debugger(g); +}); diff --git a/js/src/jit-test/tests/profiler/bug1164448.js b/js/src/jit-test/tests/profiler/bug1164448.js new file mode 100644 index 0000000000..3c66985fa2 --- /dev/null +++ b/js/src/jit-test/tests/profiler/bug1164448.js @@ -0,0 +1,25 @@ +// |jit-test| error: TypeError + +print = function(s) { return s.toString(); } +var gTestcases = new Array(); +function TestCase(n, d, e, a) + gTestcases[gTc++] = this; + dump = print; + for ( gTc=0; gTc < gTestcases.length; gTc++ ) {} +function jsTestDriverEnd() { + for (var i = 0; i < gTestcases.length; i++) + gTestcases[i].dump(); +} +TestCase(); +var g = newGlobal(); +g.parent = this; +g.eval("new Debugger(parent).onExceptionUnwind = function () {};"); +enableSPSProfiling(); +if (getBuildConfiguration()["arm-simulator"]) + enableSingleStepProfiling(1); +loadFile("jsTestDriverEnd();"); +loadFile("jsTestDriverEnd();"); +jsTestDriverEnd(); +function loadFile(lfVarx) { + try { evaluate(lfVarx); } catch (lfVare) {} +} diff --git a/js/src/jit/BacktrackingAllocator.cpp b/js/src/jit/BacktrackingAllocator.cpp index 189827a2f1..561baa3752 100644 --- a/js/src/jit/BacktrackingAllocator.cpp +++ b/js/src/jit/BacktrackingAllocator.cpp @@ -2042,21 +2042,26 @@ BacktrackingAllocator::populateSafepoints() switch (reg.type()) { case LDefinition::OBJECT: - safepoint->addGcPointer(a); + if (!safepoint->addGcPointer(a)) + return false; break; case LDefinition::SLOTS: - safepoint->addSlotsOrElementsPointer(a); + if (!safepoint->addSlotsOrElementsPointer(a)) + return false; break; #ifdef JS_NUNBOX32 case LDefinition::TYPE: - safepoint->addNunboxType(i, a); + if (!safepoint->addNunboxType(i, a)) + return false; break; case LDefinition::PAYLOAD: - safepoint->addNunboxPayload(i, a); + if (!safepoint->addNunboxPayload(i, a)) + return false; break; #else case LDefinition::BOX: - safepoint->addBoxedValue(a); + if (!safepoint->addBoxedValue(a)) + return false; break; #endif default: diff --git a/js/src/jit/JitFrames.cpp b/js/src/jit/JitFrames.cpp index b1a0dd811a..dc18a73667 100644 --- a/js/src/jit/JitFrames.cpp +++ b/js/src/jit/JitFrames.cpp @@ -3026,6 +3026,35 @@ JitProfilingFrameIterator::JitProfilingFrameIterator(void* exitFrame) return; } + if (prevType == JitFrame_Unwound_Rectifier) { + // Unwound rectifier exit frames still keep their 'JS' format (with + // the target function and actual-args included in the frame and not + // counted in the frame size). + RectifierFrameLayout* rectFrame = + GetPreviousRawFrame((JitFrameLayout*) frame); + + MOZ_ASSERT(rectFrame->prevType() == JitFrame_BaselineStub || + rectFrame->prevType() == JitFrame_IonJS); + + if (rectFrame->prevType() == JitFrame_BaselineStub) { + // Unwind past stub frame. + BaselineStubFrameLayout* stubFrame = + GetPreviousRawFrame(rectFrame); + MOZ_ASSERT(stubFrame->prevType() == JitFrame_BaselineJS); + returnAddressToFp_ = stubFrame->returnAddress(); + fp_ = ((uint8_t*) stubFrame->reverseSavedFramePtr()) + + jit::BaselineFrame::FramePointerOffset; + type_ = JitFrame_BaselineJS; + return; + } + + // else, prior frame was ion frame. + returnAddressToFp_ = rectFrame->returnAddress(); + fp_ = GetPreviousRawFrame(rectFrame); + type_ = JitFrame_IonJS; + return; + } + MOZ_CRASH("Invalid frame type prior to exit frame."); } diff --git a/js/src/jit/RematerializedFrame.cpp b/js/src/jit/RematerializedFrame.cpp index 2e16cb2afc..27534b9771 100644 --- a/js/src/jit/RematerializedFrame.cpp +++ b/js/src/jit/RematerializedFrame.cpp @@ -44,6 +44,11 @@ RematerializedFrame::RematerializedFrame(JSContext* cx, uint8_t* top, unsigned n numActualArgs_(numActualArgs), script_(iter.script()) { + if (iter.isFunctionFrame()) + callee_ = iter.callee(fallback); + else + callee_ = nullptr; + CopyValueToRematerializedFrame op(slots_); iter.readFrameArgsAndLocals(cx, op, op, &scopeChain_, &hasCallObj_, &returnValue_, &argsObj_, &thisValue_, ReadFrame_Actuals, @@ -152,6 +157,8 @@ RematerializedFrame::mark(JSTracer* trc) { TraceRoot(trc, &script_, "remat ion frame script"); TraceRoot(trc, &scopeChain_, "remat ion frame scope chain"); + if (callee_) + TraceRoot(trc, &callee_, "remat ion frame callee"); TraceRoot(trc, &returnValue_, "remat ion frame return value"); TraceRoot(trc, &thisValue_, "remat ion frame this"); TraceRootRange(trc, numActualArgs_ + isConstructing_ + script_->nfixed(), diff --git a/js/src/jit/RematerializedFrame.h b/js/src/jit/RematerializedFrame.h index 17ca017aee..27bc8c81ba 100644 --- a/js/src/jit/RematerializedFrame.h +++ b/js/src/jit/RematerializedFrame.h @@ -51,6 +51,7 @@ class RematerializedFrame JSScript* script_; JSObject* scopeChain_; + JSFunction* callee_; ArgumentsObject* argsObj_; Value returnValue_; @@ -159,10 +160,11 @@ class RematerializedFrame return isFunctionFrame() ? fun() : nullptr; } JSFunction* callee() const { - return fun(); + MOZ_ASSERT(isFunctionFrame()); + return callee_; } Value calleev() const { - return ObjectValue(*fun()); + return ObjectValue(*callee()); } Value& thisValue() { return thisValue_; diff --git a/js/src/jit/x86-shared/Assembler-x86-shared.h b/js/src/jit/x86-shared/Assembler-x86-shared.h index 753e740509..1608653b8b 100644 --- a/js/src/jit/x86-shared/Assembler-x86-shared.h +++ b/js/src/jit/x86-shared/Assembler-x86-shared.h @@ -2963,7 +2963,7 @@ class AssemblerX86Shared : public AssemblerShared } } unsigned blendpsMask(bool x, bool y, bool z, bool w) { - return x | (y << 1) | (z << 2) | (w << 3); + return (x << 0) | (y << 1) | (z << 2) | (w << 3); } void vblendps(unsigned mask, FloatRegister src1, FloatRegister src0, FloatRegister dest) { MOZ_ASSERT(HasSSE41()); diff --git a/js/src/jsapi-tests/testXDR.cpp b/js/src/jsapi-tests/testXDR.cpp index 7f29f5e31c..e1cc401337 100644 --- a/js/src/jsapi-tests/testXDR.cpp +++ b/js/src/jsapi-tests/testXDR.cpp @@ -12,6 +12,8 @@ #include "jsscriptinlines.h" +using mozilla::UniquePtr; + static JSScript* FreezeThaw(JSContext* cx, JS::HandleScript script) { @@ -130,7 +132,8 @@ BEGIN_TEST(testXDR_sourceMap) CHECK(script); size_t len = strlen(*sm); - char16_t* expected = js::InflateString(cx, *sm, &len); + UniquePtr expected_wrapper(js::InflateString(cx, *sm, &len)); + char16_t *expected = expected_wrapper.get(); CHECK(expected); // The script source takes responsibility of free'ing |expected|. diff --git a/js/src/jscompartment.cpp b/js/src/jscompartment.cpp index 1aef54c5e6..f97a3e6add 100644 --- a/js/src/jscompartment.cpp +++ b/js/src/jscompartment.cpp @@ -66,7 +66,6 @@ JSCompartment::JSCompartment(Zone* zone, const JS::CompartmentOptions& options = objectMetadataTable(nullptr), lazyArrayBuffers(nullptr), gcIncomingGrayPointers(nullptr), - gcWeakMapList(nullptr), gcPreserveJitCode(options.preserveJitCode()), debugModeBits(0), rngState(0), @@ -632,13 +631,6 @@ JSCompartment::sweepDebugScopes() debugScopes->sweep(rt); } -void -JSCompartment::sweepWeakMaps() -{ - /* Finalize unreachable (key,value) pairs in all weak maps. */ - WeakMapBase::sweepCompartment(this); -} - void JSCompartment::sweepNativeIterators() { @@ -757,7 +749,6 @@ JSCompartment::clearTables() MOZ_ASSERT(crossCompartmentWrappers.empty()); MOZ_ASSERT(!jitCompartment_); MOZ_ASSERT(!debugScopes); - MOZ_ASSERT(!gcWeakMapList); MOZ_ASSERT(enumerators->next() == enumerators); MOZ_ASSERT(regExps.empty()); diff --git a/js/src/jscompartment.h b/js/src/jscompartment.h index 9f6cfe1318..8ce5762613 100644 --- a/js/src/jscompartment.h +++ b/js/src/jscompartment.h @@ -454,9 +454,6 @@ struct JSCompartment */ JSObject* gcIncomingGrayPointers; - /* Linked list of live weakmaps in this compartment. */ - js::WeakMapBase* gcWeakMapList; - private: /* Whether to preserve JIT code on non-shrinking GCs. */ bool gcPreserveJitCode; @@ -544,7 +541,6 @@ struct JSCompartment void sweepJitCompartment(js::FreeOp* fop); void sweepRegExps(); void sweepDebugScopes(); - void sweepWeakMaps(); void sweepNativeIterators(); void sweepTemplateObjects(); diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index b29f3df08d..1fa73f8fc1 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -1829,12 +1829,12 @@ GCMarker::delayMarkingChildren(const void* thing) } inline void -ArenaLists::prepareForIncrementalGC(JSRuntime *rt) +ArenaLists::prepareForIncrementalGC(JSRuntime* rt) { for (auto i : AllAllocKinds()) { - FreeList *freeList = &freeLists[i]; + FreeList* freeList = &freeLists[i]; if (!freeList->isEmpty()) { - ArenaHeader *aheader = freeList->arenaHeader(); + ArenaHeader* aheader = freeList->arenaHeader(); aheader->allocatedDuringIncremental = true; rt->gc.marker.delayMarkingArena(aheader); } @@ -1912,8 +1912,8 @@ size_t ArenaHeader::countUsedCells() return Arena::thingsPerArena(getThingSize()) - countFreeCells(); } -ArenaHeader * -ArenaList::removeRemainingArenas(ArenaHeader **arenap) +ArenaHeader* +ArenaList::removeRemainingArenas(ArenaHeader** arenap) { // This is only ever called to remove arenas that are after the cursor, so // we don't need to update it. @@ -1937,8 +1937,8 @@ ShouldRelocateAllArenas(JS::gcreason::Reason reason) * Choose which arenas to relocate all cells from. Return an arena cursor that * can be passed to removeRemainingArenas(). */ -ArenaHeader ** -ArenaList::pickArenasToRelocate(size_t &arenaTotalOut, size_t &relocTotalOut) +ArenaHeader** +ArenaList::pickArenasToRelocate(size_t& arenaTotalOut, size_t& relocTotalOut) { // Relocate the greatest number of arenas such that the number of used cells // in relocated arenas is less than or equal to the number of free cells in @@ -1955,13 +1955,13 @@ ArenaList::pickArenasToRelocate(size_t &arenaTotalOut, size_t &relocTotalOut) if (isCursorAtEnd()) return nullptr; - ArenaHeader **arenap = cursorp_; // Next arena to consider + ArenaHeader** arenap = cursorp_; // Next arena to consider size_t previousFreeCells = 0; // Count of free cells before size_t followingUsedCells = 0; // Count of used cells after arenap. size_t arenaCount = 0; // Total number of arenas. size_t arenaIndex = 0; // Index of the next arena to consider. - for (ArenaHeader *arena = *cursorp_; arena; arena = arena->next) { + for (ArenaHeader* arena = *cursorp_; arena; arena = arena->next) { followingUsedCells += arena->countUsedCells(); arenaCount++; } @@ -1970,7 +1970,7 @@ ArenaList::pickArenasToRelocate(size_t &arenaTotalOut, size_t &relocTotalOut) size_t cellsPerArena = Arena::thingsPerArena((*arenap)->getThingSize()); while (*arenap) { - ArenaHeader *arena = *arenap; + ArenaHeader* arena = *arenap; if (followingUsedCells <= previousFreeCells) break; @@ -2015,18 +2015,18 @@ RelocateCell(Zone* zone, TenuredCell* src, AllocKind thingKind, size_t thingSize dstAlloc = GCRuntime::refillFreeListInGC(zone, thingKind); if (!dstAlloc) return false; - TenuredCell *dst = TenuredCell::fromPointer(dstAlloc); + TenuredCell* dst = TenuredCell::fromPointer(dstAlloc); // Copy source cell contents to destination. memcpy(dst, src, thingSize); if (IsObjectAllocKind(thingKind)) { - JSObject *srcObj = static_cast(static_cast(src)); - JSObject *dstObj = static_cast(static_cast(dst)); + JSObject* srcObj = static_cast(static_cast(src)); + JSObject* dstObj = static_cast(static_cast(dst)); if (srcObj->isNative()) { - NativeObject *srcNative = &srcObj->as(); - NativeObject *dstNative = &dstObj->as(); + NativeObject* srcNative = &srcObj->as(); + NativeObject* dstNative = &dstObj->as(); // Fixup the pointer to inline object elements if necessary. if (srcNative->hasFixedElements()) @@ -2061,7 +2061,7 @@ RelocateCell(Zone* zone, TenuredCell* src, AllocKind thingKind, size_t thingSize } static void -RelocateArena(ArenaHeader *aheader, SliceBudget &sliceBudget) +RelocateArena(ArenaHeader* aheader, SliceBudget& sliceBudget) { MOZ_ASSERT(aheader->allocated()); MOZ_ASSERT(!aheader->hasDelayedMarking); @@ -2085,9 +2085,9 @@ RelocateArena(ArenaHeader *aheader, SliceBudget &sliceBudget) #ifdef DEBUG for (ArenaCellIterUnderFinalize i(aheader); !i.done(); i.next()) { - TenuredCell *src = i.getCell(); + TenuredCell* src = i.getCell(); MOZ_ASSERT(RelocationOverlay::isCellForwarded(src)); - TenuredCell *dest = Forwarded(src); + TenuredCell* dest = Forwarded(src); MOZ_ASSERT(src->isMarked(BLACK) == dest->isMarked(BLACK)); MOZ_ASSERT(src->isMarked(GRAY) == dest->isMarked(GRAY)); } @@ -2098,8 +2098,8 @@ RelocateArena(ArenaHeader *aheader, SliceBudget &sliceBudget) * Relocate all arenas identified by pickArenasToRelocate: for each arena, * relocate each cell within it, then add it to a list of relocated arenas. */ -ArenaHeader * -ArenaList::relocateArenas(ArenaHeader *toRelocate, ArenaHeader *relocated, SliceBudget &sliceBudget, +ArenaHeader* +ArenaList::relocateArenas(ArenaHeader* toRelocate, ArenaHeader* relocated, SliceBudget& sliceBudget, gcstats::Statistics& stats) { check(); @@ -2199,7 +2199,7 @@ ArenaLists::relocateArenas(Zone* zone, ArenaHeader*& relocatedListOut, JS::gcrea } bool -GCRuntime::relocateArenas(Zone *zone, JS::gcreason::Reason reason, SliceBudget &sliceBudget) +GCRuntime::relocateArenas(Zone* zone, JS::gcreason::Reason reason, SliceBudget& sliceBudget) { gcstats::AutoPhase ap(stats, gcstats::PHASE_COMPACT_MOVE); @@ -2217,9 +2217,9 @@ GCRuntime::relocateArenas(Zone *zone, JS::gcreason::Reason reason, SliceBudget & for (auto i : AllAllocKinds()) { size_t thingsPerArena = Arena::thingsPerArena(Arena::thingSize(i)); if (CanRelocateAllocKind(i)) { - ArenaList &al = zone->arenas.arenaLists[i]; + ArenaList& al = zone->arenas.arenaLists[i]; size_t freeCells = 0; - for (ArenaHeader *arena = al.arenaAfterCursor(); arena; arena = arena->next) + for (ArenaHeader* arena = al.arenaAfterCursor(); arena; arena = arena->next) freeCells += arena->countFreeCells(); MOZ_ASSERT(freeCells < thingsPerArena); } @@ -2271,6 +2271,7 @@ GCRuntime::sweepZoneAfterCompacting(Zone* zone) FreeOp* fop = rt->defaultFreeOp(); sweepTypesAfterCompacting(zone); zone->sweepBreakpoints(fop); + zone->sweepWeakMaps(); for (CompartmentsInZoneIter c(zone); !c.done(); c.next()) { c->sweepInnerViews(); @@ -2284,7 +2285,6 @@ GCRuntime::sweepZoneAfterCompacting(Zone* zone) c->sweepSelfHostingScriptSource(); c->sweepDebugScopes(); c->sweepJitCompartment(fop); - c->sweepWeakMaps(); c->sweepNativeIterators(); c->sweepTemplateObjects(); } @@ -2528,7 +2528,7 @@ UpdateCellPointersTask::run() } // namespace js void -GCRuntime::updateAllCellPointersParallel(MovingTracer *trc, Zone *zone) +GCRuntime::updateAllCellPointersParallel(MovingTracer* trc, Zone* zone) { AutoDisableProxyCheck noProxyCheck(rt); // These checks assert when run in parallel. @@ -2565,7 +2565,7 @@ GCRuntime::updateAllCellPointersParallel(MovingTracer *trc, Zone *zone) } void -GCRuntime::updateAllCellPointersSerial(MovingTracer *trc, Zone *zone) +GCRuntime::updateAllCellPointersSerial(MovingTracer* trc, Zone* zone) { UpdateCellPointersTask task; { @@ -2583,7 +2583,7 @@ GCRuntime::updateAllCellPointersSerial(MovingTracer *trc, Zone *zone) * part of the traversal. */ void -GCRuntime::updatePointersToRelocatedCells(Zone *zone) +GCRuntime::updatePointersToRelocatedCells(Zone* zone) { MOZ_ASSERT(zone->isGCCompacting()); MOZ_ASSERT(rt->currentThreadHasExclusiveAccess()); @@ -2604,9 +2604,9 @@ GCRuntime::updatePointersToRelocatedCells(Zone *zone) Debugger::markAll(&trc); Debugger::markIncomingCrossCompartmentEdges(&trc); + WeakMapBase::markAll(zone, &trc); for (CompartmentsInZoneIter c(zone); !c.done(); c.next()) { c->trace(&trc); - WeakMapBase::markAll(c, &trc); if (c->watchpointMap) c->watchpointMap->markAll(&trc); } @@ -3188,7 +3188,7 @@ GCRuntime::decommitAllWithoutUnlocking(const AutoLockGC& lock) } void -GCRuntime::decommitArenas(AutoLockGC &lock) +GCRuntime::decommitArenas(AutoLockGC& lock) { // Verify that all entries in the empty chunks pool are decommitted. for (ChunkPool::Iter chunk(emptyChunks(lock)); !chunk.done(); chunk.next()) @@ -3210,7 +3210,7 @@ GCRuntime::decommitArenas(AutoLockGC &lock) // Start at the tail and stop before the first chunk: we allocate from the // head and don't want to thrash with the mutator. for (size_t i = toDecommit.length(); i > 1; --i) { - Chunk *chunk = toDecommit[i - 1]; + Chunk* chunk = toDecommit[i - 1]; MOZ_ASSERT(chunk); // The arena list is not doubly-linked, so we have to work in the free @@ -3545,7 +3545,7 @@ GCRuntime::shouldReleaseObservedTypes() * arbitrary compartment in the zone. */ void -Zone::sweepCompartments(FreeOp *fop, bool keepAtleastOne, bool destroyingRuntime) +Zone::sweepCompartments(FreeOp* fop, bool keepAtleastOne, bool destroyingRuntime) { JSRuntime* rt = runtimeFromMainThread(); JSDestroyCompartmentCallback callback = rt->destroyCompartmentCallback; @@ -3579,7 +3579,7 @@ Zone::sweepCompartments(FreeOp *fop, bool keepAtleastOne, bool destroyingRuntime } void -GCRuntime::sweepZones(FreeOp *fop, bool destroyingRuntime) +GCRuntime::sweepZones(FreeOp* fop, bool destroyingRuntime) { MOZ_ASSERT_IF(destroyingRuntime, rt->gc.numActiveZoneIters == 0); if (rt->gc.numActiveZoneIters) @@ -3892,9 +3892,9 @@ GCRuntime::beginMarkPhase(JS::gcreason::Reason reason) zone->arenas.unmarkAll(); } - for (GCCompartmentsIter c(rt); !c.done(); c.next()) { - /* Unmark all weak maps in the compartments being collected. */ - WeakMapBase::unmarkCompartment(c); + for (GCZonesIter zone(rt); !zone.done(); zone.next()) { + /* Unmark all weak maps in the zones being collected. */ + WeakMapBase::unmarkZone(zone); } if (isFull) @@ -3976,7 +3976,7 @@ GCRuntime::beginMarkPhase(JS::gcreason::Reason reason) return true; } -template +template void GCRuntime::markWeakReferences(gcstats::Phase phase) { @@ -3992,11 +3992,13 @@ GCRuntime::markWeakReferences(gcstats::Phase phase) for (;;) { bool markedAny = false; - for (CompartmentIterT c(rt); !c.done(); c.next()) { + if (!marker.isWeakMarkingTracer()) { + for (ZoneIterT zone(rt); !zone.done(); zone.next()) + markedAny |= WeakMapBase::markZoneIteratively(zone, &marker); + } + for (CompartmentsIterT c(rt); !c.done(); c.next()) { if (c->watchpointMap) markedAny |= c->watchpointMap->markIteratively(&marker); - if (marker.weakMapAction() != ExpandWeakMaps) - markedAny |= WeakMapBase::markCompartmentIteratively(c, &marker); } markedAny |= Debugger::markAllIteratively(&marker); markedAny |= jit::JitRuntime::MarkJitcodeGlobalTableIteratively(&marker); @@ -4015,7 +4017,7 @@ GCRuntime::markWeakReferences(gcstats::Phase phase) void GCRuntime::markWeakReferencesInCurrentGroup(gcstats::Phase phase) { - markWeakReferences(phase); + markWeakReferences(phase); } template @@ -4044,7 +4046,7 @@ GCRuntime::markGrayReferencesInCurrentGroup(gcstats::Phase phase) void GCRuntime::markAllWeakReferences(gcstats::Phase phase) { - markWeakReferences(phase); + markWeakReferences(phase); } void @@ -4147,8 +4149,8 @@ js::gc::MarkingValidator::nonIncrementalMark() if (!markedWeakMaps.init()) return; - for (GCCompartmentsIter c(runtime); !c.done(); c.next()) { - if (!WeakMapBase::saveCompartmentMarkedWeakMaps(c, markedWeakMaps)) + for (GCZonesIter zone(runtime); !zone.done(); zone.next()) { + if (!WeakMapBase::saveZoneMarkedWeakMaps(zone, markedWeakMaps)) return; } @@ -4179,8 +4181,8 @@ js::gc::MarkingValidator::nonIncrementalMark() { gcstats::AutoPhase ap(gc->stats, gcstats::PHASE_UNMARK); - for (GCCompartmentsIter c(runtime); !c.done(); c.next()) - WeakMapBase::unmarkCompartment(c); + for (GCZonesIter zone(runtime); !zone.done(); zone.next()) + WeakMapBase::unmarkZone(zone); MOZ_ASSERT(gcmarker->isDrained()); gcmarker->reset(); @@ -4229,8 +4231,8 @@ js::gc::MarkingValidator::nonIncrementalMark() Swap(*entry, *bitmap); } - for (GCCompartmentsIter c(runtime); !c.done(); c.next()) - WeakMapBase::unmarkCompartment(c); + for (GCZonesIter zone(runtime); !zone.done(); zone.next()) + WeakMapBase::unmarkZone(zone); WeakMapBase::restoreMarkedWeakMaps(markedWeakMaps); gc->marker.weakKeys.clear(); @@ -4432,8 +4434,8 @@ GCRuntime::findZoneEdgesForWeakMaps() * group. */ - for (GCCompartmentsIter comp(rt); !comp.done(); comp.next()) { - if (!WeakMapBase::findZoneEdgesForCompartment(comp)) + for (GCZonesIter zone(rt); !zone.done(); zone.next()) { + if (!WeakMapBase::findInterZoneEdges(zone)) return false; } @@ -4961,10 +4963,12 @@ GCRuntime::beginSweepingZoneGroup() c->sweepObjectPendingMetadata(); c->sweepDebugScopes(); c->sweepJitCompartment(&fop); - c->sweepWeakMaps(); c->sweepTemplateObjects(); } + for (GCZoneGroupIter zone(rt); !zone.done(); zone.next()) + zone->sweepWeakMaps(); + // Bug 1071218: the following two methods have not yet been // refactored to work on a single zone-group at once. @@ -5252,7 +5256,7 @@ GCRuntime::sweepPhase(SliceBudget& sliceBudget) sweepZone->types.endSweep(rt); } - // Foreground finalized objects have already been finalized, + // Foreground finalized objects have already been finalized, // and now their arenas can be reclaimed by freeing empty ones // and making non-empty ones available for allocation. al.mergeForegroundSweptObjectArenas(); @@ -5454,7 +5458,7 @@ GCRuntime::beginCompactPhase() } GCRuntime::IncrementalProgress -GCRuntime::compactPhase(JS::gcreason::Reason reason, SliceBudget &sliceBudget) +GCRuntime::compactPhase(JS::gcreason::Reason reason, SliceBudget& sliceBudget) { MOZ_ASSERT(rt->gc.nursery.isEmpty()); assertBackgroundSweepingFinished(); @@ -5463,7 +5467,7 @@ GCRuntime::compactPhase(JS::gcreason::Reason reason, SliceBudget &sliceBudget) gcstats::AutoPhase ap(stats, gcstats::PHASE_COMPACT); while (!zonesToMaybeCompact.isEmpty()) { - Zone *zone = zonesToMaybeCompact.front(); + Zone* zone = zonesToMaybeCompact.front(); MOZ_ASSERT(zone->isGCFinished()); if (relocateArenas(zone, reason, sliceBudget)) { zone->setGCState(Zone::Compact); @@ -6566,7 +6570,7 @@ js::NewCompartment(JSContext* cx, Zone* zone, JSPrincipals* principals, } void -gc::MergeCompartments(JSCompartment *source, JSCompartment *target) +gc::MergeCompartments(JSCompartment* source, JSCompartment* target) { // The source compartment must be specifically flagged as mergable. This // also implies that the compartment is not visible to the debugger. @@ -6574,7 +6578,7 @@ gc::MergeCompartments(JSCompartment *source, JSCompartment *target) MOZ_ASSERT(source->addonId == target->addonId); - JSRuntime *rt = source->runtimeFromMainThread(); + JSRuntime* rt = source->runtimeFromMainThread(); AutoPrepareForTracing prepare(rt, SkipAtoms); @@ -6598,29 +6602,35 @@ gc::MergeCompartments(JSCompartment *source, JSCompartment *target) // type information generations are in sync. for (ZoneCellIter iter(source->zone(), AllocKind::SCRIPT); !iter.done(); iter.next()) { - JSScript *script = iter.get(); + JSScript* script = iter.get(); MOZ_ASSERT(script->compartment() == source); script->compartment_ = target; script->setTypesGeneration(target->zone()->types.generation); } for (ZoneCellIter iter(source->zone(), AllocKind::BASE_SHAPE); !iter.done(); iter.next()) { - BaseShape *base = iter.get(); + BaseShape* base = iter.get(); MOZ_ASSERT(base->compartment() == source); base->compartment_ = target; } for (ZoneCellIter iter(source->zone(), AllocKind::OBJECT_GROUP); !iter.done(); iter.next()) { - ObjectGroup *group = iter.get(); + ObjectGroup* group = iter.get(); group->setGeneration(target->zone()->types.generation); group->compartment_ = target; + + // Remove any unboxed layouts from the list in the off thread + // compartment. These do not need to be reinserted in the target + // compartment's list, as the list is not required to be complete. + if (UnboxedLayout* layout = group->maybeUnboxedLayoutDontCheckGeneration()) + layout->detachFromCompartment(); } // Fixup zone pointers in source's zone to refer to target's zone. for (auto thingKind : AllAllocKinds()) { for (ArenaIter aiter(source->zone(), thingKind); !aiter.done(); aiter.next()) { - ArenaHeader *aheader = aiter.get(); + ArenaHeader* aheader = aiter.get(); aheader->zone = target->zone(); } } @@ -6759,7 +6769,7 @@ js::ReleaseAllJITCode(FreeOp* fop) #ifdef DEBUG /* Assert no baseline scripts are marked as active. */ for (ZoneCellIter i(zone, AllocKind::SCRIPT); !i.done(); i.next()) { - JSScript *script = i.get(); + JSScript* script = i.get(); MOZ_ASSERT_IF(script->hasBaselineScript(), !script->baselineScript()->active()); } #endif @@ -6770,7 +6780,7 @@ js::ReleaseAllJITCode(FreeOp* fop) jit::InvalidateAll(fop, zone); for (ZoneCellIter i(zone, AllocKind::SCRIPT); !i.done(); i.next()) { - JSScript *script = i.get(); + JSScript* script = i.get(); jit::FinishInvalidation(fop, script); /* @@ -6785,10 +6795,10 @@ js::ReleaseAllJITCode(FreeOp* fop) } void -js::PurgeJITCaches(Zone *zone) +js::PurgeJITCaches(Zone* zone) { for (ZoneCellIterUnderGC i(zone, AllocKind::SCRIPT); !i.done(); i.next()) { - JSScript *script = i.get(); + JSScript* script = i.get(); /* Discard Ion caches. */ jit::PurgeCaches(script); @@ -6809,7 +6819,7 @@ ArenaLists::normalizeBackgroundFinalizeState(AllocKind thingKind) } void -ArenaLists::adoptArenas(JSRuntime *rt, ArenaLists *fromArenaLists) +ArenaLists::adoptArenas(JSRuntime* rt, ArenaLists* fromArenaLists) { // GC should be inactive, but still take the lock as a kind of read fence. AutoLockGC lock(rt); @@ -6823,12 +6833,12 @@ ArenaLists::adoptArenas(JSRuntime *rt, ArenaLists *fromArenaLists) normalizeBackgroundFinalizeState(thingKind); fromArenaLists->normalizeBackgroundFinalizeState(thingKind); - ArenaList *fromList = &fromArenaLists->arenaLists[thingKind]; - ArenaList *toList = &arenaLists[thingKind]; + ArenaList* fromList = &fromArenaLists->arenaLists[thingKind]; + ArenaList* toList = &arenaLists[thingKind]; fromList->check(); toList->check(); - ArenaHeader *next; - for (ArenaHeader *fromHeader = fromList->head(); fromHeader; fromHeader = next) { + ArenaHeader* next; + for (ArenaHeader* fromHeader = fromList->head(); fromHeader; fromHeader = next) { // Copy fromHeader->next before releasing/reinserting. next = fromHeader->next; @@ -6841,11 +6851,11 @@ ArenaLists::adoptArenas(JSRuntime *rt, ArenaLists *fromArenaLists) } bool -ArenaLists::containsArena(JSRuntime *rt, ArenaHeader *needle) +ArenaLists::containsArena(JSRuntime* rt, ArenaHeader* needle) { AutoLockGC lock(rt); - ArenaList &list = arenaLists[needle->getAllocKind()]; - for (ArenaHeader *aheader = list.head(); aheader; aheader = aheader->next) { + ArenaList& list = arenaLists[needle->getAllocKind()]; + for (ArenaHeader* aheader = list.head(); aheader; aheader = aheader->next) { if (aheader == needle) return true; } @@ -7280,7 +7290,7 @@ namespace gc { namespace MemInfo { static bool -GCBytesGetter(JSContext *cx, unsigned argc, Value *vp) +GCBytesGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->runtime()->gc.usage.gcBytes())); @@ -7288,7 +7298,7 @@ GCBytesGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -GCMaxBytesGetter(JSContext *cx, unsigned argc, Value *vp) +GCMaxBytesGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->runtime()->gc.tunables.gcMaxBytes())); @@ -7296,7 +7306,7 @@ GCMaxBytesGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -MallocBytesGetter(JSContext *cx, unsigned argc, Value *vp) +MallocBytesGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->runtime()->gc.getMallocBytes())); @@ -7304,7 +7314,7 @@ MallocBytesGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -MaxMallocGetter(JSContext *cx, unsigned argc, Value *vp) +MaxMallocGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->runtime()->gc.maxMallocBytesAllocated())); @@ -7312,7 +7322,7 @@ MaxMallocGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -GCHighFreqGetter(JSContext *cx, unsigned argc, Value *vp) +GCHighFreqGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setBoolean(cx->runtime()->gc.schedulingState.inHighFrequencyGCMode()); @@ -7320,7 +7330,7 @@ GCHighFreqGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -GCNumberGetter(JSContext *cx, unsigned argc, Value *vp) +GCNumberGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->runtime()->gc.gcNumber())); @@ -7328,7 +7338,7 @@ GCNumberGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -MajorGCCountGetter(JSContext *cx, unsigned argc, Value *vp) +MajorGCCountGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->runtime()->gc.majorGCCount())); @@ -7336,7 +7346,7 @@ MajorGCCountGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -MinorGCCountGetter(JSContext *cx, unsigned argc, Value *vp) +MinorGCCountGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->runtime()->gc.minorGCCount())); @@ -7344,7 +7354,7 @@ MinorGCCountGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -ZoneGCBytesGetter(JSContext *cx, unsigned argc, Value *vp) +ZoneGCBytesGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->zone()->usage.gcBytes())); @@ -7352,7 +7362,7 @@ ZoneGCBytesGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -ZoneGCTriggerBytesGetter(JSContext *cx, unsigned argc, Value *vp) +ZoneGCTriggerBytesGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->zone()->threshold.gcTriggerBytes())); @@ -7360,7 +7370,7 @@ ZoneGCTriggerBytesGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -ZoneGCAllocTriggerGetter(JSContext *cx, unsigned argc, Value *vp) +ZoneGCAllocTriggerGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->zone()->threshold.allocTrigger(cx->runtime()->gc.schedulingState.inHighFrequencyGCMode()))); @@ -7368,7 +7378,7 @@ ZoneGCAllocTriggerGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -ZoneMallocBytesGetter(JSContext *cx, unsigned argc, Value *vp) +ZoneMallocBytesGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->zone()->gcMallocBytes)); @@ -7376,7 +7386,7 @@ ZoneMallocBytesGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -ZoneMaxMallocGetter(JSContext *cx, unsigned argc, Value *vp) +ZoneMaxMallocGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->zone()->gcMaxMallocBytes)); @@ -7384,7 +7394,7 @@ ZoneMaxMallocGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -ZoneGCDelayBytesGetter(JSContext *cx, unsigned argc, Value *vp) +ZoneGCDelayBytesGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->zone()->gcDelayBytes)); @@ -7392,7 +7402,7 @@ ZoneGCDelayBytesGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -ZoneGCHeapGrowthFactorGetter(JSContext *cx, unsigned argc, Value *vp) +ZoneGCHeapGrowthFactorGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(cx->zone()->threshold.gcHeapGrowthFactor()); @@ -7400,7 +7410,7 @@ ZoneGCHeapGrowthFactorGetter(JSContext *cx, unsigned argc, Value *vp) } static bool -ZoneGCNumberGetter(JSContext *cx, unsigned argc, Value *vp) +ZoneGCNumberGetter(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); args.rval().setNumber(double(cx->zone()->gcNumber())); diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index ab272fb94b..1f78bee5c9 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -2753,6 +2753,7 @@ js::WatchGuts(JSContext* cx, JS::HandleObject origObj, JS::HandleId id, JS::Hand wpmap = cx->runtime()->new_(); if (!wpmap || !wpmap->init()) { ReportOutOfMemory(cx); + js_delete(wpmap); return false; } cx->compartment()->watchpointMap = wpmap; diff --git a/js/src/json.cpp b/js/src/json.cpp index 130bc9f4cc..0f54e80241 100644 --- a/js/src/json.cpp +++ b/js/src/json.cpp @@ -327,7 +327,11 @@ JO(JSContext* cx, HandleObject obj, StringifyContext* scx) Maybe ids; const AutoIdVector* props; if (scx->replacer && !scx->replacer->isCallable()) { - MOZ_ASSERT(IsArray(scx->replacer, cx)); + // NOTE: We can't assert |IsArray(scx->replacer)| because the replacer + // might have been a revocable proxy to an array. Such a proxy + // satisfies |IsArray|, but any side effect of JSON.stringify + // could revoke the proxy so that |!IsArray(scx->replacer)|. See + // bug 1196497. props = &scx->propertyList; } else { MOZ_ASSERT_IF(scx->replacer, scx->propertyList.length() == 0); diff --git a/js/src/jsweakmap.cpp b/js/src/jsweakmap.cpp index 5df6f3b5e4..89d77a2901 100644 --- a/js/src/jsweakmap.cpp +++ b/js/src/jsweakmap.cpp @@ -28,13 +28,13 @@ using namespace js::gc; using mozilla::UniquePtr; -WeakMapBase::WeakMapBase(JSObject* memOf, JSCompartment* c) +WeakMapBase::WeakMapBase(JSObject* memOf, Zone* zone) : memberOf(memOf), - compartment(c), + zone(zone), next(WeakMapNotInList), marked(false) { - MOZ_ASSERT_IF(memberOf, memberOf->compartment() == c); + MOZ_ASSERT_IF(memberOf, memberOf->compartment()->zone() == zone); } WeakMapBase::~WeakMapBase() @@ -75,17 +75,17 @@ WeakMapBase::trace(JSTracer *tracer) } void -WeakMapBase::unmarkCompartment(JSCompartment* c) +WeakMapBase::unmarkZone(JS::Zone* zone) { - for (WeakMapBase* m = c->gcWeakMapList; m; m = m->next) + for (WeakMapBase* m = zone->gcWeakMapList; m; m = m->next) m->marked = false; } void -WeakMapBase::markAll(JSCompartment* c, JSTracer* tracer) +WeakMapBase::markAll(JS::Zone* zone, JSTracer* tracer) { MOZ_ASSERT(tracer->weakMapAction() != DoNotTraceWeakMaps); - for (WeakMapBase* m = c->gcWeakMapList; m; m = m->next) { + for (WeakMapBase* m = zone->gcWeakMapList; m; m = m->next) { m->trace(tracer); if (m->memberOf) TraceEdge(tracer, &m->memberOf, "memberOf"); @@ -93,10 +93,10 @@ WeakMapBase::markAll(JSCompartment* c, JSTracer* tracer) } bool -WeakMapBase::markCompartmentIteratively(JSCompartment* c, JSTracer* tracer) +WeakMapBase::markZoneIteratively(JS::Zone* zone, JSTracer* tracer) { bool markedAny = false; - for (WeakMapBase* m = c->gcWeakMapList; m; m = m->next) { + for (WeakMapBase* m = zone->gcWeakMapList; m; m = m->next) { if (m->marked && m->markIteratively(tracer)) markedAny = true; } @@ -104,9 +104,9 @@ WeakMapBase::markCompartmentIteratively(JSCompartment* c, JSTracer* tracer) } bool -WeakMapBase::findZoneEdgesForCompartment(JSCompartment* c) +WeakMapBase::findInterZoneEdges(JS::Zone* zone) { - for (WeakMapBase* m = c->gcWeakMapList; m; m = m->next) { + for (WeakMapBase* m = zone->gcWeakMapList; m; m = m->next) { if (!m->findZoneEdges()) return false; } @@ -114,10 +114,10 @@ WeakMapBase::findZoneEdgesForCompartment(JSCompartment* c) } void -WeakMapBase::sweepCompartment(JSCompartment* c) +WeakMapBase::sweepZone(JS::Zone* zone) { - WeakMapBase** tailPtr = &c->gcWeakMapList; - for (WeakMapBase* m = c->gcWeakMapList; m; ) { + WeakMapBase** tailPtr = &zone->gcWeakMapList; + for (WeakMapBase* m = zone->gcWeakMapList; m; ) { WeakMapBase* next = m->next; if (m->marked) { m->sweep(); @@ -133,7 +133,7 @@ WeakMapBase::sweepCompartment(JSCompartment* c) *tailPtr = nullptr; #ifdef DEBUG - for (WeakMapBase* m = c->gcWeakMapList; m; m = m->next) + for (WeakMapBase* m = zone->gcWeakMapList; m; m = m->next) MOZ_ASSERT(m->isInList() && m->marked); #endif } @@ -142,8 +142,8 @@ void WeakMapBase::traceAllMappings(WeakMapTracer* tracer) { JSRuntime* rt = tracer->runtime; - for (CompartmentsIter c(rt, SkipAtoms); !c.done(); c.next()) { - for (WeakMapBase* m = c->gcWeakMapList; m; m = m->next) { + for (ZonesIter zone(rt, SkipAtoms); !zone.done(); zone.next()) { + for (WeakMapBase* m = zone->gcWeakMapList; m; m = m->next) { // The WeakMapTracer callback is not allowed to GC. JS::AutoSuppressGCAnalysis nogc; m->traceMappings(tracer); @@ -152,9 +152,9 @@ WeakMapBase::traceAllMappings(WeakMapTracer* tracer) } bool -WeakMapBase::saveCompartmentMarkedWeakMaps(JSCompartment* c, WeakMapSet& markedWeakMaps) +WeakMapBase::saveZoneMarkedWeakMaps(JS::Zone* zone, WeakMapSet& markedWeakMaps) { - for (WeakMapBase* m = c->gcWeakMapList; m; m = m->next) { + for (WeakMapBase* m = zone->gcWeakMapList; m; m = m->next) { if (m->marked && !markedWeakMaps.put(m)) return false; } @@ -166,7 +166,7 @@ WeakMapBase::restoreMarkedWeakMaps(WeakMapSet& markedWeakMaps) { for (WeakMapSet::Range r = markedWeakMaps.all(); !r.empty(); r.popFront()) { WeakMapBase* map = r.front(); - MOZ_ASSERT(map->compartment->zone()->isGCMarking()); + MOZ_ASSERT(map->zone->isGCMarking()); MOZ_ASSERT(!map->marked); map->marked = true; } @@ -175,8 +175,8 @@ WeakMapBase::restoreMarkedWeakMaps(WeakMapSet& markedWeakMaps) void WeakMapBase::removeWeakMapFromList(WeakMapBase* weakmap) { - JSCompartment* c = weakmap->compartment; - for (WeakMapBase** p = &c->gcWeakMapList; *p; p = &(*p)->next) { + JS::Zone* zone = weakmap->zone; + for (WeakMapBase** p = &zone->gcWeakMapList; *p; p = &(*p)->next) { if (*p == weakmap) { *p = (*p)->next; weakmap->next = WeakMapNotInList; @@ -194,7 +194,6 @@ ObjectValueMap::findZoneEdges() * zone. */ JS::AutoSuppressGCAnalysis nogc; - Zone* mapZone = compartment->zone(); for (Range r = all(); !r.empty(); r.popFront()) { JSObject* key = r.front().key(); if (key->asTenured().isMarked(BLACK) && !key->asTenured().isMarked(GRAY)) @@ -206,7 +205,7 @@ ObjectValueMap::findZoneEdges() if (!delegate) continue; Zone* delegateZone = delegate->zone(); - if (delegateZone == mapZone) + if (delegateZone == zone) continue; if (!delegateZone->gcZoneGroupEdges.put(key->zone())) return false; diff --git a/js/src/jsweakmap.h b/js/src/jsweakmap.h index fdaf3ff062..06496746f3 100644 --- a/js/src/jsweakmap.h +++ b/js/src/jsweakmap.h @@ -44,44 +44,44 @@ class WeakMapBase { friend void js::GCMarker::enterWeakMarkingMode(); public: - WeakMapBase(JSObject* memOf, JSCompartment* c); + WeakMapBase(JSObject* memOf, JS::Zone* zone); virtual ~WeakMapBase(); void trace(JSTracer* tracer); // Garbage collector entry points. - // Unmark all weak maps in a compartment. - static void unmarkCompartment(JSCompartment* c); + // Unmark all weak maps in a zone. + static void unmarkZone(JS::Zone* zone); - // Mark all the weakmaps in a compartment. - static void markAll(JSCompartment* c, JSTracer* tracer); + // Mark all the weakmaps in a zone. + static void markAll(JS::Zone* zone, JSTracer* tracer); - // Check all weak maps in a compartment that have been marked as live in this garbage + // Check all weak maps in a zone that have been marked as live in this garbage // collection, and mark the values of all entries that have become strong references // to them. Return true if we marked any new values, indicating that we need to make // another pass. In other words, mark my marked maps' marked members' mid-collection. - static bool markCompartmentIteratively(JSCompartment* c, JSTracer* tracer); + static bool markZoneIteratively(JS::Zone* zone, JSTracer* tracer); // Add zone edges for weakmaps with key delegates in a different zone. - static bool findZoneEdgesForCompartment(JSCompartment* c); + static bool findInterZoneEdges(JS::Zone* zone); - // Sweep the weak maps in a compartment, removing dead weak maps and removing + // Sweep the weak maps in a zone, removing dead weak maps and removing // entries of live weak maps whose keys are dead. - static void sweepCompartment(JSCompartment* c); + static void sweepZone(JS::Zone* zone); // Trace all delayed weak map bindings. Used by the cycle collector. static void traceAllMappings(WeakMapTracer* tracer); bool isInList() { return next != WeakMapNotInList; } - // Save information about which weak maps are marked for a compartment. - static bool saveCompartmentMarkedWeakMaps(JSCompartment* c, WeakMapSet& markedWeakMaps); + // Save information about which weak maps are marked for a zone. + static bool saveZoneMarkedWeakMaps(JS::Zone* zone, WeakMapSet& markedWeakMaps); - // Restore information about which weak maps are marked for many compartments. + // Restore information about which weak maps are marked for many zones. static void restoreMarkedWeakMaps(WeakMapSet& markedWeakMaps); - // Remove a weakmap from its compartment's weakmaps list. + // Remove a weakmap from its zone's weakmaps list. static void removeWeakMapFromList(WeakMapBase* weakmap); // Any weakmap key types that want to participate in the non-iterative @@ -104,12 +104,12 @@ class WeakMapBase { // Object that this weak map is part of, if any. HeapPtrObject memberOf; - // Compartment that this weak map is part of. - JSCompartment* compartment; + // Zone containing this weak map. + JS::Zone* zone; - // Link in a list of all WeakMaps in a compartment, headed by - // JSCompartment::gcWeakMapList. The last element of the list has nullptr as - // its next. Maps not in the list have WeakMapNotInList as their next. + // Link in a list of all WeakMaps in a Zone, headed by + // JS::Zone::gcWeakMapList. The last element of the list has nullptr as its + // next. Maps not in the list have WeakMapNotInList as their next. WeakMapBase* next; // Whether this object has been traced during garbage collection. @@ -140,14 +140,14 @@ class WeakMap : public HashMap, publ typedef typename Base::AddPtr AddPtr; explicit WeakMap(JSContext* cx, JSObject* memOf = nullptr) - : Base(cx->runtime()), WeakMapBase(memOf, cx->compartment()) { } + : Base(cx->runtime()), WeakMapBase(memOf, cx->compartment()->zone()) { } bool init(uint32_t len = 16) { if (!Base::init(len)) return false; - next = compartment->gcWeakMapList; - compartment->gcWeakMapList = this; - marked = JS::IsIncrementalGCInProgress(compartment->runtimeFromMainThread()); + next = zone->gcWeakMapList; + zone->gcWeakMapList = this; + marked = JS::IsIncrementalGCInProgress(zone->runtimeFromMainThread()); return true; } diff --git a/js/src/tests/ecma_6/Proxy/json-stringify-replacer-array-revocable-proxy.js b/js/src/tests/ecma_6/Proxy/json-stringify-replacer-array-revocable-proxy.js new file mode 100644 index 0000000000..5d667e353a --- /dev/null +++ b/js/src/tests/ecma_6/Proxy/json-stringify-replacer-array-revocable-proxy.js @@ -0,0 +1,39 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +var gTestfile = "json-stringify-replacer-array-revocable-proxy.js"; +//----------------------------------------------------------------------------- +var BUGNUMBER = 1196497; +var summary = + "Don't assert when JSON.stringify is passed a revocable proxy to an array, " + + "then that proxy is revoked midflight during stringification"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +var arr = []; +var { proxy, revoke } = Proxy.revocable(arr, { + get(thisv, prop, receiver) { + // First (and only) get will be for "length", to determine the length of the + // list of properties to serialize. Returning 0 uses the empty list, + // resulting in |a: 0| being ignored below. + assertEq(thisv, arr); + assertEq(prop, "length"); + assertEq(receiver, proxy); + + revoke(); + return 0; + } +}); + +assertEq(JSON.stringify({a: 0}, proxy), "{}"); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("Tests complete"); diff --git a/js/src/vm/Debugger.h b/js/src/vm/Debugger.h index bc3fbe3c3b..7d9c3345b7 100644 --- a/js/src/vm/Debugger.h +++ b/js/src/vm/Debugger.h @@ -81,12 +81,16 @@ class DebuggerWeakMap : private WeakMap, Relocatabl RuntimeAllocPolicy> CountMap; CountMap zoneCounts; + JSCompartment* compartment; public: typedef WeakMap > Base; explicit DebuggerWeakMap(JSContext* cx) - : Base(cx), zoneCounts(cx->runtime()) { } + : Base(cx), + zoneCounts(cx->runtime()), + compartment(cx->compartment()) + { } ~DebuggerWeakMap() { // If our owning Debugger fails construction after already initializing @@ -120,7 +124,7 @@ class DebuggerWeakMap : private WeakMap, Relocatabl template bool relookupOrAdd(AddPtr& p, const KeyInput& k, const ValueInput& v) { - MOZ_ASSERT(v->compartment() == Base::compartment); + MOZ_ASSERT(v->compartment() == this->compartment); MOZ_ASSERT(!k->compartment()->options_.mergeable()); MOZ_ASSERT_IF(!InvisibleKeysOk, !k->compartment()->options_.invisibleToDebugger()); MOZ_ASSERT(!Base::has(k)); diff --git a/js/src/vm/Stack.h b/js/src/vm/Stack.h index f3483a30e1..f68b5128fa 100644 --- a/js/src/vm/Stack.h +++ b/js/src/vm/Stack.h @@ -562,7 +562,7 @@ class InterpreterFrame unsigned numActualArgs() const { MOZ_ASSERT(hasArgs()); return u.nactual; } /* Watch out, this exposes a pointer to the unaliased formal arg array. */ - Value* argv() const { return argv_; } + Value* argv() const { MOZ_ASSERT(hasArgs()); return argv_; } /* * Arguments object diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 21bab9bc81..f987e0b2ff 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -57,7 +57,7 @@ #include "nsRefreshDriver.h" #include "Layers.h" #include "ClientLayerManager.h" -#include "nsIDOMEvent.h" +#include "mozilla/dom/NotifyPaintEvent.h" #include "gfxPrefs.h" #include "nsIDOMChromeWindow.h" #include "nsFrameLoader.h" @@ -2215,23 +2215,21 @@ nsPresContext::FireDOMPaintEvent(nsInvalidateRequestList* aList) } // Events sent to the window get propagated to the chrome event handler // automatically. - nsCOMPtr event; + // // This will empty our list in case dispatching the event causes more damage // (hopefully it won't, or we're likely to get an infinite loop! At least // it won't be blocking app execution though). - NS_NewDOMNotifyPaintEvent(getter_AddRefs(event), eventTarget, this, nullptr, - NS_AFTERPAINT, aList); - if (!event) { - return; - } + nsRefPtr event = + NS_NewDOMNotifyPaintEvent(eventTarget, this, nullptr, NS_AFTERPAINT, + aList); // Even if we're not telling the window about the event (so eventTarget is // the chrome event handler, not the window), the window is still // logically the event target. event->SetTarget(eventTarget); event->SetTrusted(true); - EventDispatcher::DispatchDOMEvent(dispatchTarget, nullptr, event, this, - nullptr); + EventDispatcher::DispatchDOMEvent(dispatchTarget, nullptr, + static_cast(event), this, nullptr); } static bool diff --git a/layout/xul/nsMenuFrame.cpp b/layout/xul/nsMenuFrame.cpp index 59263fd351..05c1a4dcdd 100644 --- a/layout/xul/nsMenuFrame.cpp +++ b/layout/xul/nsMenuFrame.cpp @@ -44,6 +44,7 @@ #include "mozilla/Services.h" #include "mozilla/TextEvents.h" #include "mozilla/dom/Element.h" +#include "mozilla/dom/Event.h" #include using namespace mozilla; @@ -94,17 +95,13 @@ public: domEventToFire.AssignLiteral("DOMMenuItemInactive"); } - nsCOMPtr event; - if (NS_SUCCEEDED(EventDispatcher::CreateEvent(mMenu, mPresContext, nullptr, - NS_LITERAL_STRING("Events"), - getter_AddRefs(event)))) { - event->InitEvent(domEventToFire, true, true); + nsRefPtr event = NS_NewDOMEvent(mMenu, mPresContext, nullptr); + event->InitEvent(domEventToFire, true, true); - event->SetTrusted(true); + event->SetTrusted(true); - EventDispatcher::DispatchDOMEvent(mMenu, nullptr, event, - mPresContext, nullptr); - } + EventDispatcher::DispatchDOMEvent(mMenu, nullptr, event, + mPresContext, nullptr); return NS_OK; } diff --git a/layout/xul/nsRootBoxFrame.cpp b/layout/xul/nsRootBoxFrame.cpp index 11fb77b202..32ef238a79 100644 --- a/layout/xul/nsRootBoxFrame.cpp +++ b/layout/xul/nsRootBoxFrame.cpp @@ -179,6 +179,14 @@ nsRootBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, const nsDisplayListSet& aLists) { + if (mContent && mContent->GetProperty(nsGkAtoms::DisplayPortMargins)) { + // The XUL document's root element may have displayport margins set in + // ChromeProcessController::InitializeRoot, and we should to supply the + // base rect. + nsRect displayPortBase = aDirtyRect.Intersect(nsRect(nsPoint(0, 0), GetSize())); + nsLayoutUtils::SetDisplayPortBase(mContent, displayPortBase); + } + // root boxes don't need a debug border/outline or a selection overlay... // They *may* have a background propagated to them, so force creation // of a background display list element. diff --git a/layout/xul/nsXULPopupManager.cpp b/layout/xul/nsXULPopupManager.cpp index a4dc1955f7..4ebc76b8a1 100644 --- a/layout/xul/nsXULPopupManager.cpp +++ b/layout/xul/nsXULPopupManager.cpp @@ -2178,6 +2178,7 @@ nsXULPopupManager::HandleKeyboardEventWithKeyCode( if (keyCode == nsIDOMKeyEvent::DOM_VK_ESCAPE) { HidePopup(aTopVisibleMenuItem->Content(), false, false, false, true); aKeyEvent->StopPropagation(); + aKeyEvent->StopCrossProcessForwarding(); aKeyEvent->PreventDefault(); } return true; @@ -2249,6 +2250,7 @@ nsXULPopupManager::HandleKeyboardEventWithKeyCode( if (consume) { aKeyEvent->StopPropagation(); + aKeyEvent->StopCrossProcessForwarding(); aKeyEvent->PreventDefault(); } return true; @@ -2449,6 +2451,7 @@ nsXULPopupManager::KeyUp(nsIDOMKeyEvent* aKeyEvent) } aKeyEvent->StopPropagation(); + aKeyEvent->StopCrossProcessForwarding(); aKeyEvent->PreventDefault(); return NS_OK; // I am consuming event @@ -2469,10 +2472,6 @@ nsXULPopupManager::KeyDown(nsIDOMKeyEvent* aKeyEvent) if (!mActiveMenuBar && (!item || item->PopupType() != ePopupTypeMenu)) return NS_OK; - // Since a menu was open, stop propagation of the event to keep other event - // listeners from becoming confused. - aKeyEvent->StopPropagation(); - int32_t menuAccessKey = -1; // If the key just pressed is the access key (usually Alt), @@ -2510,6 +2509,10 @@ nsXULPopupManager::KeyDown(nsIDOMKeyEvent* aKeyEvent) } } + // Since a menu was open, stop propagation of the event to keep other event + // listeners from becoming confused. + aKeyEvent->StopPropagation(); + aKeyEvent->StopCrossProcessForwarding(); return NS_OK; } @@ -2531,6 +2534,7 @@ nsXULPopupManager::KeyPress(nsIDOMKeyEvent* aKeyEvent) HandleShortcutNavigation(keyEvent, nullptr); if (consume) { aKeyEvent->StopPropagation(); + aKeyEvent->StopCrossProcessForwarding(); aKeyEvent->PreventDefault(); }