Files
palemoon27/dom/push/PushUtil.cpp
T
roytam1 8375688356 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1257418 - Remove USE_DEPENDENT_LIBS. r=gps (fbe746751a)
- Bug 1255817 part 3. Remove the now-unreachable JS_ReportPendingException call in nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject. r=bholley (dbffe901a9)
- Bug 1255817 part 4. Make XPCJSRuntime use MozCrashErrorReporter by default, now that there should be no stray JS_ReportPendingException calls. r=bholley (68d82e4b68)
- Bug 1245000 part 1 - Add a preference for enabling Element.animate; r=bz (d94ab6f1d9)
- Bug 1245000 part 2 - Don't ship Animation.ready; r=bz (129a052a16)
- Bug 1245000 part 3 - Turn on Element.animate in release channels too; r=bz (cc6743c31d)
- Bug 1245000 part 4 - Enable the Animation constructor when Element.animate is enabled; r=bz (8a65bdedcb)
- Bug 1247685 - WebIDL and DOM implementation changes for app server keys. r=mt,baku (69870bd979)
- Bug 1248565 - Introduce MOZ_LOG_* variables for mozilla logging. r=erahm (ea236d3b26)
- Bug 1258231 - Lock while iterating console messages. r=mccr8 (2b54be114d)
- bug 1252104 - make NS_ERROR_GET_CODE() and NS_ERROR_GET_MODULE() constexpr r=froydnj (f29ae0f6de)
- Bug 1221160 - fix AutoTraceLogLock deadlock on Windows; r=froydnj (11f1c2a071)
- Bug 1251895 - don't race on nsTraceRefcnt's object serial number tables; r=mccr8 (2d52aceffe)
2024-07-15 23:14:05 +08:00

59 lines
1.9 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/PushUtil.h"
namespace mozilla {
namespace dom {
/* static */ bool
PushUtil::CopyArrayBufferToArray(const ArrayBuffer& aBuffer,
nsTArray<uint8_t>& aArray)
{
aBuffer.ComputeLengthAndData();
return aArray.SetLength(aBuffer.Length(), fallible) &&
aArray.ReplaceElementsAt(0, aBuffer.Length(), aBuffer.Data(),
aBuffer.Length(), fallible);
}
/* static */ bool
PushUtil::CopyBufferSourceToArray(
const OwningArrayBufferViewOrArrayBuffer& aSource, nsTArray<uint8_t>& aArray)
{
if (aSource.IsArrayBuffer()) {
return CopyArrayBufferToArray(aSource.GetAsArrayBuffer(), aArray);
}
if (aSource.IsArrayBufferView()) {
const ArrayBufferView& view = aSource.GetAsArrayBufferView();
view.ComputeLengthAndData();
return aArray.SetLength(view.Length(), fallible) &&
aArray.ReplaceElementsAt(0, view.Length(), view.Data(),
view.Length(), fallible);
}
MOZ_CRASH("Uninitialized union: expected buffer or view");
}
/* static */ void
PushUtil::CopyArrayToArrayBuffer(JSContext* aCx,
const nsTArray<uint8_t>& aArray,
JS::MutableHandle<JSObject*> aValue,
ErrorResult& aRv)
{
if (aArray.IsEmpty()) {
aValue.set(nullptr);
return;
}
JS::Rooted<JSObject*> buffer(aCx, ArrayBuffer::Create(aCx,
aArray.Length(),
aArray.Elements()));
if (NS_WARN_IF(!buffer)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
aValue.set(buffer);
}
} // namespace dom
} // namespace mozilla