зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1866008 - Remove nsContentUtils::CreateArrayBuffer. r=farre
Differential Revision: https://phabricator.services.mozilla.com/D194460
This commit is contained in:
Родитель
3935078a03
Коммит
1af728d973
|
@ -6691,31 +6691,6 @@ nsresult nsContentUtils::WrapNative(JSContext* cx, nsISupports* native,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsContentUtils::CreateArrayBuffer(JSContext* aCx,
|
||||
const nsACString& aData,
|
||||
JSObject** aResult) {
|
||||
if (!aCx) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
size_t dataLen = aData.Length();
|
||||
*aResult = JS::NewArrayBuffer(aCx, dataLen);
|
||||
if (!*aResult) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (dataLen > 0) {
|
||||
NS_ASSERTION(JS::IsArrayBufferObject(*aResult), "What happened?");
|
||||
JS::AutoCheckCannotGC nogc;
|
||||
bool isShared;
|
||||
memcpy(JS::GetArrayBufferData(*aResult, &isShared, nogc),
|
||||
aData.BeginReading(), dataLen);
|
||||
MOZ_ASSERT(!isShared);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsContentUtils::StripNullChars(const nsAString& aInStr,
|
||||
nsAString& aOutStr) {
|
||||
// In common cases where we don't have nulls in the
|
||||
|
|
|
@ -2314,12 +2314,6 @@ class nsContentUtils {
|
|||
return WrapNative(cx, native, cache, nullptr, vp, aAllowWrapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an arraybuffer from a binary string.
|
||||
*/
|
||||
static nsresult CreateArrayBuffer(JSContext* aCx, const nsACString& aData,
|
||||
JSObject** aResult);
|
||||
|
||||
static void StripNullChars(const nsAString& aInStr, nsAString& aOutStr);
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "mozilla/dom/MessageEventBinding.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "mozilla/dom/Blob.h"
|
||||
|
||||
#include "nsError.h"
|
||||
|
@ -302,9 +303,9 @@ nsresult nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
} else if (mBinaryType == DC_BINARY_TYPE_ARRAYBUFFER) {
|
||||
JS::Rooted<JSObject*> arrayBuf(cx);
|
||||
rv = nsContentUtils::CreateArrayBuffer(cx, aData, arrayBuf.address());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
ErrorResult error;
|
||||
JS::Rooted<JSObject*> arrayBuf(cx, ArrayBuffer::Create(cx, aData, error));
|
||||
ENSURE_SUCCESS(error, error.StealNSResult());
|
||||
jsData.setObject(*arrayBuf);
|
||||
} else {
|
||||
MOZ_CRASH("Unknown binary type!");
|
||||
|
|
|
@ -705,7 +705,7 @@ struct TypedArray : public TypedArray_base<ArrayT> {
|
|||
Span<const element_type> data,
|
||||
ErrorResult& error) {
|
||||
ArrayT array = CreateCommon(cx, creator, data.Length(), error);
|
||||
if (!error.Failed()) {
|
||||
if (!error.Failed() && !data.IsEmpty()) {
|
||||
CopyFrom(cx, data, array);
|
||||
}
|
||||
return array.asObject();
|
||||
|
@ -714,7 +714,7 @@ struct TypedArray : public TypedArray_base<ArrayT> {
|
|||
static inline JSObject* Create(JSContext* cx, Span<const element_type> data,
|
||||
ErrorResult& error) {
|
||||
ArrayT array = CreateCommon(cx, data.Length(), error);
|
||||
if (!error.Failed()) {
|
||||
if (!error.Failed() && !data.IsEmpty()) {
|
||||
CopyFrom(cx, data, array);
|
||||
}
|
||||
return array.asObject();
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/MacroForEach.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsError.h"
|
||||
#include "nsTArray.h"
|
||||
|
@ -42,12 +42,9 @@ SDBResult::GetAsArray(nsTArray<uint8_t>& aData) {
|
|||
NS_IMETHODIMP
|
||||
SDBResult::GetAsArrayBuffer(JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> _retval) {
|
||||
JS::Rooted<JSObject*> arrayBuffer(aCx);
|
||||
nsresult rv =
|
||||
nsContentUtils::CreateArrayBuffer(aCx, mData, arrayBuffer.address());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
ErrorResult rv;
|
||||
JS::Rooted<JSObject*> arrayBuffer(aCx, ArrayBuffer::Create(aCx, mData, rv));
|
||||
ENSURE_SUCCESS(rv, rv.StealNSResult());
|
||||
|
||||
_retval.setObject(*arrayBuffer);
|
||||
return NS_OK;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "mozilla/dom/nsMixedContentBlocker.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/SerializedStackHolder.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "mozilla/dom/UnionTypes.h"
|
||||
#include "mozilla/dom/WindowContext.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
|
@ -2011,10 +2012,9 @@ nsresult WebSocket::CreateAndDispatchMessageEvent(const nsACString& aData,
|
|||
} else if (mBinaryType == dom::BinaryType::Arraybuffer) {
|
||||
messageType = nsIWebSocketEventListener::TYPE_ARRAYBUFFER;
|
||||
|
||||
JS::Rooted<JSObject*> arrayBuf(cx);
|
||||
nsresult rv =
|
||||
nsContentUtils::CreateArrayBuffer(cx, aData, arrayBuf.address());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
ErrorResult rv;
|
||||
JS::Rooted<JSObject*> arrayBuf(cx, ArrayBuffer::Create(cx, aData, rv));
|
||||
ENSURE_SUCCESS(rv, rv.StealNSResult());
|
||||
jsData.setObject(*arrayBuf);
|
||||
} else {
|
||||
MOZ_CRASH("Unknown binary type!");
|
||||
|
|
|
@ -30,10 +30,10 @@
|
|||
#include "mozilla/Services.h"
|
||||
#include "mozilla/Try.h"
|
||||
#include "mozilla/dom/ipc/StructuredCloneData.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsAppRunner.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsChromeRegistry.h"
|
||||
#include "nsIDOMWindowUtils.h" // for nsIJSRAIIHelper
|
||||
#include "nsIFileURL.h"
|
||||
|
@ -560,8 +560,8 @@ nsresult AddonManagerStartup::EncodeBlob(JS::Handle<JS::Value> value,
|
|||
nsCString lz4;
|
||||
MOZ_TRY_VAR(lz4, EncodeLZ4(scData, STRUCTURED_CLONE_MAGIC));
|
||||
|
||||
JS::Rooted<JSObject*> obj(cx);
|
||||
MOZ_TRY(nsContentUtils::CreateArrayBuffer(cx, lz4, &obj.get()));
|
||||
JS::Rooted<JSObject*> obj(cx, dom::ArrayBuffer::Create(cx, lz4, rv));
|
||||
ENSURE_SUCCESS(rv, rv.StealNSResult());
|
||||
|
||||
result.set(JS::ObjectValue(*obj));
|
||||
return NS_OK;
|
||||
|
|
Загрузка…
Ссылка в новой задаче