Issue #2197 - Part 1a: postMessages should have transferable as [] by default

Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1336020
This commit is contained in:
FranklinDM 2023-04-07 09:56:33 +08:00 committed by roytam1
commit 438cdbd913
22 changed files with 52 additions and 58 deletions

View file

@ -394,20 +394,19 @@ MessagePort::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
}
void
MessagePort::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Optional<Sequence<JS::Value>>& aTransferable,
MessagePort::PostMessage(JSContext* aCx,
JS::Handle<JS::Value> aMessage,
const Sequence<JS::Value>& aTransferable,
ErrorResult& aRv)
{
// We *must* clone the data here, or the JS::Value could be modified
// by script
JS::Rooted<JS::Value> transferable(aCx, JS::UndefinedValue());
if (aTransferable.WasPassed()) {
const Sequence<JS::Value>& realTransferable = aTransferable.Value();
if (!aTransferable.IsEmpty()) {
// Here we want to check if the transerable object list contains
// this port. No other checks are done.
for (const JS::Value& value : realTransferable) {
for (const JS::Value& value : aTransferable) {
if (!value.isObject()) {
continue;
}
@ -429,8 +428,8 @@ MessagePort::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
// The input sequence only comes from the generated bindings code, which
// ensures it is rooted.
JS::HandleValueArray elements =
JS::HandleValueArray::fromMarkedLocation(realTransferable.Length(),
realTransferable.Elements());
JS::HandleValueArray::fromMarkedLocation(aTransferable.Length(),
aTransferable.Elements());
JSObject* array =
JS_NewArrayObject(aCx, elements);