Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp b/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp |
| index 2e03c090e611b9e57232bb40b00babf95f65f639..1674215d708636a7810e638e281690610b097b9d 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp |
| @@ -5,7 +5,9 @@ |
| #include "bindings/core/v8/serialization/V8ScriptValueSerializer.h" |
| #include "bindings/core/v8/ToV8.h" |
| +#include "bindings/core/v8/V8ImageData.h" |
| #include "core/dom/DOMArrayBufferBase.h" |
| +#include "core/html/ImageData.h" |
| #include "platform/RuntimeEnabledFeatures.h" |
| #include "wtf/AutoReset.h" |
| @@ -83,6 +85,22 @@ void V8ScriptValueSerializer::transfer(Transferables* transferables, ExceptionSt |
| } |
| } |
| +bool V8ScriptValueSerializer::writeDOMObject(ScriptWrappable* wrappable, ExceptionState& exceptionState) |
| +{ |
| + const WrapperTypeInfo* wrapperTypeInfo = wrappable->wrapperTypeInfo(); |
| + if (wrapperTypeInfo == &V8ImageData::wrapperTypeInfo) { |
|
esprehn
2016/09/16 18:41:27
fwiw I wonder if we should use a HashMap of <Wrapp
jbroman
2016/09/16 19:40:02
I suggested doing that to ScriptValueSerializer a
|
| + ImageData* imageData = wrappable->toImpl<ImageData>(); |
| + DOMUint8ClampedArray* pixels = imageData->data(); |
| + writeTag(ImageDataTag); |
| + writeUint32(imageData->width()); |
| + writeUint32(imageData->height()); |
| + writeUint32(pixels->length()); |
| + writeRawBytes(pixels->data(), pixels->length()); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| void V8ScriptValueSerializer::ThrowDataCloneError(v8::Local<v8::String> v8Message) |
| { |
| DCHECK(m_exceptionState); |
| @@ -93,4 +111,27 @@ void V8ScriptValueSerializer::ThrowDataCloneError(v8::Local<v8::String> v8Messag |
| V8ThrowException::throwException(m_scriptState->isolate(), exception); |
| } |
| +v8::Maybe<bool> V8ScriptValueSerializer::WriteHostObject(v8::Isolate* isolate, v8::Local<v8::Object> object) |
| +{ |
| + DCHECK(m_exceptionState); |
| + DCHECK_EQ(isolate, m_scriptState->isolate()); |
| + ExceptionState exceptionState( |
| + isolate, m_exceptionState->context(), |
| + m_exceptionState->interfaceName(), m_exceptionState->propertyName()); |
| + |
| + if (!V8DOMWrapper::isWrapper(isolate, object)) { |
| + exceptionState.throwDOMException(DataCloneError, "An object could not be cloned."); |
| + return v8::Nothing<bool>(); |
| + } |
| + ScriptWrappable* wrappable = toScriptWrappable(object); |
| + bool wroteDOMObject = writeDOMObject(wrappable, exceptionState); |
| + if (wroteDOMObject) { |
| + DCHECK(!exceptionState.hadException()); |
| + return v8::Just(true); |
| + } |
| + if (!exceptionState.hadException()) |
| + exceptionState.throwDOMException(DataCloneError, "An object could not be cloned."); |
|
haraken
2016/09/16 14:17:53
If you want to pass in exceptionState to writeDOMO
jbroman
2016/09/16 14:34:33
I did it this way with the goal of making it simpl
|
| + return v8::Nothing<bool>(); |
| +} |
| + |
| } // namespace blink |