mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 23:38:38 +09:00
Issue #2197 - Part 1b: Transferables should be arrays of objects
Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1336020
This commit is contained in:
parent
438cdbd913
commit
47147d58b0
24 changed files with 118 additions and 129 deletions
|
|
@ -396,49 +396,37 @@ MessagePort::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|||
void
|
||||
MessagePort::PostMessage(JSContext* aCx,
|
||||
JS::Handle<JS::Value> aMessage,
|
||||
const Sequence<JS::Value>& aTransferable,
|
||||
const Sequence<JSObject*>& 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.IsEmpty()) {
|
||||
// Here we want to check if the transerable object list contains
|
||||
// this port. No other checks are done.
|
||||
for (const JS::Value& value : aTransferable) {
|
||||
if (!value.isObject()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> object(aCx, &value.toObject());
|
||||
|
||||
MessagePort* port = nullptr;
|
||||
nsresult rv = UNWRAP_OBJECT(MessagePort, &object, port);
|
||||
if (NS_FAILED(rv)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (port == this) {
|
||||
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
return;
|
||||
}
|
||||
// Here we want to check if the transferable object list contains
|
||||
// this port.
|
||||
for (uint32_t i = 0; i < aTransferable.Length(); ++i) {
|
||||
JSObject* rawObject = aTransferable[i];
|
||||
if (!rawObject) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// The input sequence only comes from the generated bindings code, which
|
||||
// ensures it is rooted.
|
||||
JS::HandleValueArray elements =
|
||||
JS::HandleValueArray::fromMarkedLocation(aTransferable.Length(),
|
||||
aTransferable.Elements());
|
||||
JS::Rooted<JSObject*> object(aCx, rawObject);
|
||||
|
||||
JSObject* array =
|
||||
JS_NewArrayObject(aCx, elements);
|
||||
if (!array) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
MessagePort* port = nullptr;
|
||||
nsresult rv = UNWRAP_OBJECT(MessagePort, &object, port);
|
||||
if (NS_SUCCEEDED(rv) && port == this) {
|
||||
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
transferable.setObject(*array);
|
||||
JS::Rooted<JS::Value> transferable(aCx, JS::UndefinedValue());
|
||||
|
||||
aRv = nsContentUtils::CreateJSValueFromSequenceOfObject(aCx,
|
||||
aTransferable,
|
||||
&transferable);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<SharedMessagePortMessage> data = new SharedMessagePortMessage();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue