diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index b277404b8cd..860b8602e5e 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -54,11 +54,10 @@ #include "nsScriptNameSpaceManager.h" #include "StructuredCloneTags.h" #include "mozilla/AutoRestore.h" -#include "mozilla/dom/CryptoKey.h" #include "mozilla/dom/ErrorEvent.h" -#include "mozilla/dom/ImageDataBinding.h" #include "mozilla/dom/ImageData.h" -#include "mozilla/dom/StructuredClone.h" +#include "mozilla/dom/CryptoKey.h" +#include "mozilla/dom/ImageDataBinding.h" #include "mozilla/dom/SubtleCryptoBinding.h" #include "nsAXPCNativeCallContext.h" #include "mozilla/CycleCollectedJSRuntime.h" @@ -2812,7 +2811,25 @@ NS_DOMReadStructuredClone(JSContext* cx, void* closure) { if (tag == SCTAG_DOM_IMAGEDATA) { - return ReadStructuredCloneImageData(cx, reader); + // Read the information out of the stream. + uint32_t width, height; + JS::Rooted dataArray(cx); + if (!JS_ReadUint32Pair(reader, &width, &height) || + !JS_ReadTypedArray(reader, &dataArray)) { + return nullptr; + } + MOZ_ASSERT(dataArray.isObject()); + + // Protect the result from a moving GC in ~nsRefPtr. + JS::Rooted result(cx); + { + // Construct the ImageData. + nsRefPtr imageData = new ImageData(width, height, + dataArray.toObject()); + // Wrap it in a JS::Value. + result = imageData->WrapObject(cx); + } + return result; } else if (tag == SCTAG_DOM_WEBCRYPTO_KEY) { nsIGlobalObject *global = xpc::GetNativeForGlobal(JS::CurrentGlobalOrNull(cx)); if (!global) { @@ -2846,7 +2863,17 @@ NS_DOMWriteStructuredClone(JSContext* cx, // Handle ImageData cloning ImageData* imageData; if (NS_SUCCEEDED(UNWRAP_OBJECT(ImageData, obj, imageData))) { - return WriteStructuredCloneImageData(cx, writer, imageData); + // Prepare the ImageData internals. + uint32_t width = imageData->Width(); + uint32_t height = imageData->Height(); + JS::Rooted dataArray(cx, imageData->GetDataObject()); + + // Write the internals to the stream. + JSAutoCompartment ac(cx, dataArray); + JS::Rooted arrayValue(cx, JS::ObjectValue(*dataArray)); + return JS_WriteUint32Pair(writer, SCTAG_DOM_IMAGEDATA, 0) && + JS_WriteUint32Pair(writer, width, height) && + JS_WriteTypedArray(writer, arrayValue); } // Handle Key cloning diff --git a/dom/bindings/StructuredClone.cpp b/dom/bindings/StructuredClone.cpp deleted file mode 100644 index b191a1d472d..00000000000 --- a/dom/bindings/StructuredClone.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/StructuredClone.h" - -#include "js/StructuredClone.h" -#include "mozilla/dom/ImageData.h" -#include "mozilla/dom/StructuredCloneTags.h" - -namespace mozilla { -namespace dom { - -JSObject* -ReadStructuredCloneImageData(JSContext* aCx, JSStructuredCloneReader* aReader) -{ - // Read the information out of the stream. - uint32_t width, height; - JS::Rooted dataArray(aCx); - if (!JS_ReadUint32Pair(aReader, &width, &height) || - !JS_ReadTypedArray(aReader, &dataArray)) { - return nullptr; - } - MOZ_ASSERT(dataArray.isObject()); - - // Protect the result from a moving GC in ~nsRefPtr. - JS::Rooted result(aCx); - { - // Construct the ImageData. - nsRefPtr imageData = new ImageData(width, height, - dataArray.toObject()); - // Wrap it in a JS::Value. - result = imageData->WrapObject(aCx); - } - return result; -} - -bool -WriteStructuredCloneImageData(JSContext* aCx, JSStructuredCloneWriter* aWriter, - ImageData* aImageData) -{ - uint32_t width = aImageData->Width(); - uint32_t height = aImageData->Height(); - JS::Rooted dataArray(aCx, aImageData->GetDataObject()); - - JSAutoCompartment ac(aCx, dataArray); - JS::Rooted arrayValue(aCx, JS::ObjectValue(*dataArray)); - return JS_WriteUint32Pair(aWriter, SCTAG_DOM_IMAGEDATA, 0) && - JS_WriteUint32Pair(aWriter, width, height) && - JS_WriteTypedArray(aWriter, arrayValue); -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/bindings/StructuredClone.h b/dom/bindings/StructuredClone.h deleted file mode 100644 index bfd7700c6d0..00000000000 --- a/dom/bindings/StructuredClone.h +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -class JSObject; -struct JSContext; -struct JSStructuredCloneReader; -struct JSStructuredCloneWriter; - -namespace mozilla { -namespace dom { - -class ImageData; - -JSObject* -ReadStructuredCloneImageData(JSContext* aCx, JSStructuredCloneReader* aReader); - -bool -WriteStructuredCloneImageData(JSContext* aCx, JSStructuredCloneWriter* aWriter, - ImageData* aImageData); - -} // namespace dom -} // namespace mozilla diff --git a/dom/bindings/moz.build b/dom/bindings/moz.build index 261cce6bb5b..874903c977a 100644 --- a/dom/bindings/moz.build +++ b/dom/bindings/moz.build @@ -30,7 +30,6 @@ EXPORTS.mozilla.dom += [ 'OwningNonNull.h', 'PrimitiveConversions.h', 'RootedDictionary.h', - 'StructuredClone.h', 'ToJSValue.h', 'TypedArray.h', 'UnionMember.h', @@ -82,10 +81,6 @@ UNIFIED_SOURCES += [ 'ToJSValue.cpp', ] -SOURCES += [ - 'StructuredClone.cpp', -] - include('/ipc/chromium/chromium-config.mozbuild') if CONFIG['MOZ_AUDIO_CHANNEL_MANAGER']: diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 7e9f174f117..1a66a34e1f7 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -48,7 +48,6 @@ #include "mozilla/dom/MessageEventBinding.h" #include "mozilla/dom/MessagePortList.h" #include "mozilla/dom/ScriptSettings.h" -#include "mozilla/dom/StructuredClone.h" #include "mozilla/dom/WorkerBinding.h" #include "mozilla/Preferences.h" #include "nsAlgorithm.h" @@ -353,7 +352,25 @@ struct WorkerStructuredCloneCallbacks // See if the object is an ImageData. else if (aTag == SCTAG_DOM_IMAGEDATA) { MOZ_ASSERT(!aData); - return ReadStructuredCloneImageData(aCx, aReader); + + // Read the information out of the stream. + uint32_t width, height; + JS::Rooted dataArray(aCx); + if (!JS_ReadUint32Pair(aReader, &width, &height) || + !JS_ReadTypedArray(aReader, &dataArray)) + { + return nullptr; + } + MOZ_ASSERT(dataArray.isObject()); + + { + // Construct the ImageData. + nsRefPtr imageData = new ImageData(width, height, + dataArray.toObject()); + // Wrap it in a JS::Value, protected from a moving GC during ~nsRefPtr. + result = imageData->WrapObject(aCx); + } + return result; } Error(aCx, 0); @@ -401,7 +418,17 @@ struct WorkerStructuredCloneCallbacks { ImageData* imageData = nullptr; if (NS_SUCCEEDED(UNWRAP_OBJECT(ImageData, aObj, imageData))) { - return WriteStructuredCloneImageData(aCx, aWriter, imageData); + // Prepare the ImageData internals. + uint32_t width = imageData->Width(); + uint32_t height = imageData->Height(); + JS::Rooted dataArray(aCx, imageData->GetDataObject()); + + // Write the internals to the stream. + JSAutoCompartment ac(aCx, dataArray); + JS::Rooted arrayValue(aCx, JS::ObjectValue(*dataArray)); + return JS_WriteUint32Pair(aWriter, SCTAG_DOM_IMAGEDATA, 0) && + JS_WriteUint32Pair(aWriter, width, height) && + JS_WriteTypedArray(aWriter, arrayValue); } }