summaryrefslogtreecommitdiffstats
path: root/dom/messagechannel
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /dom/messagechannel
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz
firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/messagechannel')
-rw-r--r--dom/messagechannel/MessagePort.cpp36
-rw-r--r--dom/messagechannel/MessagePort.h6
-rw-r--r--dom/messagechannel/tests/mm_messageChannel.js2
-rw-r--r--dom/messagechannel/tests/mm_messageChannelParent.js8
-rw-r--r--dom/messagechannel/tests/test_event_listener_leaks.html2
-rw-r--r--dom/messagechannel/tests/test_messageChannel.xhtml2
-rw-r--r--dom/messagechannel/tests/test_messageChannel_start.html34
-rw-r--r--dom/messagechannel/tests/test_removedWindow.html6
8 files changed, 64 insertions, 32 deletions
diff --git a/dom/messagechannel/MessagePort.cpp b/dom/messagechannel/MessagePort.cpp
index 23c54cde25..5c07311427 100644
--- a/dom/messagechannel/MessagePort.cpp
+++ b/dom/messagechannel/MessagePort.cpp
@@ -204,7 +204,8 @@ already_AddRefed<MessagePort> MessagePort::Create(nsIGlobalObject* aGlobal,
ErrorResult& aRv) {
MOZ_ASSERT(aGlobal);
- RefPtr<MessagePort> mp = new MessagePort(aGlobal, eStateUnshippedEntangled);
+ RefPtr<MessagePort> mp =
+ new MessagePort(aGlobal, eStateInitializingUnshippedEntangled);
mp->Initialize(aUUID, aDestinationUUID, 1 /* 0 is an invalid sequence ID */,
false /* Neutered */, aRv);
return mp.forget();
@@ -223,11 +224,16 @@ already_AddRefed<MessagePort> MessagePort::Create(
return mp.forget();
}
-void MessagePort::UnshippedEntangle(MessagePort* aEntangledPort) {
+void MessagePort::UnshippedEntangle(RefPtr<MessagePort>& aEntangledPort) {
MOZ_DIAGNOSTIC_ASSERT(aEntangledPort);
MOZ_DIAGNOSTIC_ASSERT(!mUnshippedEntangledPort);
- mUnshippedEntangledPort = aEntangledPort;
+ if (mState == eStateInitializingUnshippedEntangled) {
+ mUnshippedEntangledPort = aEntangledPort;
+ mState = eStateUnshippedEntangled;
+ } else {
+ MOZ_ASSERT_UNREACHABLE("Should not have been called.");
+ }
}
void MessagePort::Initialize(const nsID& aUUID, const nsID& aDestinationUUID,
@@ -251,7 +257,7 @@ void MessagePort::Initialize(const nsID& aUUID, const nsID& aDestinationUUID,
return;
}
} else {
- MOZ_ASSERT(mState == eStateUnshippedEntangled);
+ MOZ_ASSERT(mState == eStateInitializingUnshippedEntangled);
}
// The port has to keep itself alive until it's entangled.
@@ -332,6 +338,12 @@ void MessagePort::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
return;
}
+ if (mState == eStateInitializingUnshippedEntangled) {
+ MOZ_ASSERT_UNREACHABLE(
+ "Should be eStateUnshippedEntangled or eStateDisentangled by now.");
+ return;
+ }
+
// If we are unshipped we are connected to the other port on the same thread.
if (mState == eStateUnshippedEntangled) {
MOZ_DIAGNOSTIC_ASSERT(mUnshippedEntangledPort);
@@ -390,6 +402,11 @@ void MessagePort::Dispatch() {
}
switch (mState) {
+ case eStateInitializingUnshippedEntangled:
+ MOZ_ASSERT_UNREACHABLE(
+ "Should be eStateUnshippedEntangled or eStateDisentangled by now.");
+ break;
+
case eStateUnshippedEntangled:
// Everything is fine here. We have messages because the other
// port populates our queue directly.
@@ -459,6 +476,17 @@ void MessagePort::CloseInternal(bool aSoftly) {
// now invalid.
mRefMessageBodyService->ForgetPort(mIdentifier->uuid());
+ if (mState == eStateInitializingUnshippedEntangled) {
+ // We can end up here if we failed to create our WorkerRef. Our Create
+ // method will end up returning an error and MessageChannel will not bother
+ // creating our counterpart port or calling UnshippedEntangle (and we
+ // assert on this).
+ mState = eStateDisentangledForClose;
+
+ UpdateMustKeepAlive();
+ return;
+ }
+
if (mState == eStateUnshippedEntangled) {
MOZ_DIAGNOSTIC_ASSERT(mUnshippedEntangledPort);
diff --git a/dom/messagechannel/MessagePort.h b/dom/messagechannel/MessagePort.h
index b0365e6b81..2ed4fdabaa 100644
--- a/dom/messagechannel/MessagePort.h
+++ b/dom/messagechannel/MessagePort.h
@@ -110,7 +110,7 @@ class MessagePort final : public DOMEventTargetHelper {
// Non WebIDL methods
- void UnshippedEntangle(MessagePort* aEntangledPort);
+ void UnshippedEntangle(RefPtr<MessagePort>& aEntangledPort);
bool CanBeCloned() const { return !mHasBeenTransferredOrClosed; }
@@ -127,6 +127,10 @@ class MessagePort final : public DOMEventTargetHelper {
private:
enum State {
+ // The plan is to be eStateUnshippedEntangled once we are told about our
+ // unshipped entangled counterpart.
+ eStateInitializingUnshippedEntangled,
+
// When a port is created by a MessageChannel it is entangled with the
// other. They both run on the same thread, same event loop and the
// messages are added to the queues without using PBackground actors.
diff --git a/dom/messagechannel/tests/mm_messageChannel.js b/dom/messagechannel/tests/mm_messageChannel.js
index 7acd5df530..8cc104e748 100644
--- a/dom/messagechannel/tests/mm_messageChannel.js
+++ b/dom/messagechannel/tests/mm_messageChannel.js
@@ -71,6 +71,6 @@ function emptyTest(msg) {
sendAsyncMessage("EmptyTest:FinishPrepare", { message: "OK" });
}
-function notTransferableTest(msg) {
+function notTransferableTest() {
sendAsyncMessage("NotTransferableTest:FinishPrepare", { message: "OK" });
}
diff --git a/dom/messagechannel/tests/mm_messageChannelParent.js b/dom/messagechannel/tests/mm_messageChannelParent.js
index a5595722a2..f103a1746b 100644
--- a/dom/messagechannel/tests/mm_messageChannelParent.js
+++ b/dom/messagechannel/tests/mm_messageChannelParent.js
@@ -72,7 +72,7 @@ function close_test(finish) {
is(msg.data.message, "OK", "");
ok(port, "");
- port.onmessage = message => {
+ port.onmessage = () => {
ok(false, "Port is alive.");
finish();
};
@@ -92,7 +92,7 @@ function close_test(finish) {
function empty_transferable(finish) {
ok(mm, "empty_transferable");
- let finishPrepare = msg => {
+ let finishPrepare = () => {
ok(true, "Same basic test.");
mm.removeMessageListener("EmptyTest:FinishPrepare", finishPrepare);
finish();
@@ -106,7 +106,7 @@ function empty_transferable(finish) {
function not_transferable(finish) {
ok(mm, "not_transferable");
- let finishPrepare = msg => {
+ let finishPrepare = () => {
ok(true, "Same basic test.");
finish();
};
@@ -118,7 +118,7 @@ function not_transferable(finish) {
/*
* Test preparation
*/
-function finishLoad(msg) {
+function finishLoad() {
run_tests();
}
diff --git a/dom/messagechannel/tests/test_event_listener_leaks.html b/dom/messagechannel/tests/test_event_listener_leaks.html
index 93ed5215d3..579491dab3 100644
--- a/dom/messagechannel/tests/test_event_listener_leaks.html
+++ b/dom/messagechannel/tests/test_event_listener_leaks.html
@@ -23,7 +23,7 @@ async function useMessagePort(contentWindow) {
mc.port1.postMessage("foo");
await new Promise(resolve => {
- mc.port2.onmessage = e => {
+ mc.port2.onmessage = () => {
contentWindow.messageCount += 1;
resolve();
};
diff --git a/dom/messagechannel/tests/test_messageChannel.xhtml b/dom/messagechannel/tests/test_messageChannel.xhtml
index e51359d67d..cac2a4f066 100644
--- a/dom/messagechannel/tests/test_messageChannel.xhtml
+++ b/dom/messagechannel/tests/test_messageChannel.xhtml
@@ -17,7 +17,7 @@
var channel = new MessageChannel();
ok(channel, "MessageChannel is created");
- channel.port1.onmessage = function(evt) {
+ channel.port1.onmessage = function() {
ok(true, "message received!");
SimpleTest.finish();
}
diff --git a/dom/messagechannel/tests/test_messageChannel_start.html b/dom/messagechannel/tests/test_messageChannel_start.html
index 4bc49cc0d6..f9e86da385 100644
--- a/dom/messagechannel/tests/test_messageChannel_start.html
+++ b/dom/messagechannel/tests/test_messageChannel_start.html
@@ -36,12 +36,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
var events = 2;
- a.port1.onmessage = function(evt) {
+ a.port1.onmessage = function() {
ok(true, "This method should be called");
if (!--events) runTests();
}
- a.port2.onmessage = function(evt) {
+ a.port2.onmessage = function() {
ok(true, "This method should be called");
if (!--events) runTests();
}
@@ -55,11 +55,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
a.port2.postMessage(43);
ok(true, "MessagePort{1,2}.postmessage() invoked");
- a.port1.addEventListener('message', function(evt) {
+ a.port1.addEventListener('message', function() {
ok(false, "This method should not be called");
});
- a.port2.addEventListener('message', function(evt) {
+ a.port2.addEventListener('message', function() {
ok(false, "This method should not be called");
});
@@ -76,12 +76,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
var events = 2;
- a.port1.addEventListener('message', function(evt) {
+ a.port1.addEventListener('message', function() {
ok(true, "This method should be called");
if (!--events) runTests();
});
- a.port2.addEventListener('message', function(evt) {
+ a.port2.addEventListener('message', function() {
ok(true, "This method should be called");
if (!--events) runTests();
});
@@ -100,12 +100,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
var events = 1;
- a.port1.addEventListener('message', function(evt) {
+ a.port1.addEventListener('message', function() {
ok(true, "This method should be called");
if (!--events) runTests();
});
- a.port2.addEventListener('message', function(evt) {
+ a.port2.addEventListener('message', function() {
ok(false, "This method should not be called");
});
@@ -122,11 +122,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
var events = 1;
- a.port1.addEventListener('message', function(evt) {
+ a.port1.addEventListener('message', function() {
ok(false, "This method should not be called");
});
- a.port2.addEventListener('message', function(evt) {
+ a.port2.addEventListener('message', function() {
ok(true, "This method should be called");
if (!--events) runTests();
});
@@ -144,12 +144,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
setTimeout(function() {
var events = 2;
- a.port1.onmessage = function(evt) {
+ a.port1.onmessage = function() {
ok(true, "This method should be called");
if (!--events) runTests();
}
- a.port2.onmessage = function(evt) {
+ a.port2.onmessage = function() {
ok(true, "This method should be called");
if (!--events) runTests();
}
@@ -167,13 +167,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
var events = 2;
a.port1.start();
- a.port1.addEventListener('message', function(evt) {
+ a.port1.addEventListener('message', function() {
ok(true, "This method should be called");
if (!--events) runTests();
});
a.port2.start();
- a.port2.addEventListener('message', function(evt) {
+ a.port2.addEventListener('message', function() {
ok(true, "This method should be called");
if (!--events) runTests();
});
@@ -191,17 +191,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
addEventListener('message', testOnMessageCloneCb, false);
function testOnMessageCloneCb(event) {
- a.port1.onmessage = function(evt) {
+ a.port1.onmessage = function() {
ok(true, "This method should be called");
testOnMessageCloneFinish();
}
- event.data.onmessage = function(evt) {
+ event.data.onmessage = function() {
ok(true, "This method should be called");
testOnMessageCloneFinish();
}
- a.port2.onmessage = function(evt) {
+ a.port2.onmessage = function() {
ok(false, "This method should not be called");
}
}
diff --git a/dom/messagechannel/tests/test_removedWindow.html b/dom/messagechannel/tests/test_removedWindow.html
index b660000fd8..0413a7afeb 100644
--- a/dom/messagechannel/tests/test_removedWindow.html
+++ b/dom/messagechannel/tests/test_removedWindow.html
@@ -30,13 +30,13 @@ async function runTest() {
// This should silently fail.
pre.port1.postMessage(42);
- pre.port2.onmessage = e => {
+ pre.port2.onmessage = () => {
ok(false, "No messages should be received!");
}
// This should silently fail.
post.port1.postMessage(42);
- post.port2.onmessage = e => {
+ post.port2.onmessage = () => {
ok(false, "No messages should be received!");
}
@@ -45,7 +45,7 @@ async function runTest() {
let mc = new MessageChannel();
mc.port1.postMessage(42);
- mc.port2.onmessage = e => {
+ mc.port2.onmessage = () => {
ok(true, "Ready to complete the test");
SimpleTest.finish();
}