Index: Source/bindings/v8/SerializedScriptValue.cpp |
diff --git a/Source/bindings/v8/SerializedScriptValue.cpp b/Source/bindings/v8/SerializedScriptValue.cpp |
index f067774e36bb9221dced0e7938c974740067e937..82a0ee382d047588ad9325213aab8ba6f6f0417f 100644 |
--- a/Source/bindings/v8/SerializedScriptValue.cpp |
+++ b/Source/bindings/v8/SerializedScriptValue.cpp |
@@ -688,7 +688,6 @@ public: |
Success, |
InputError, |
DataCloneError, |
- InvalidStateError, |
JSException, |
JSFailure |
}; |
@@ -1131,7 +1130,7 @@ private: |
if (!arrayBuffer) |
return 0; |
if (arrayBuffer->isNeutered()) |
- return handleError(InvalidStateError, next); |
+ return handleError(DataCloneError, next); |
ASSERT(!m_transferredArrayBuffers.contains(value.As<v8::Object>())); |
m_writer.writeArrayBuffer(*arrayBuffer); |
return 0; |
@@ -2221,21 +2220,27 @@ private: |
} // namespace |
+PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, ExceptionState& exceptionState, v8::Isolate* isolate) |
+{ |
+ bool didThrow; |
+ return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers, didThrow, &exceptionState, isolate)); |
+} |
+ |
PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Isolate* isolate) |
{ |
- return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers, didThrow, isolate)); |
+ return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers, didThrow, 0, isolate)); |
} |
PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExceptions(v8::Handle<v8::Value> value, v8::Isolate* isolate) |
{ |
bool didThrow; |
- return adoptRef(new SerializedScriptValue(value, 0, 0, didThrow, isolate, DoNotThrowExceptions)); |
+ return adoptRef(new SerializedScriptValue(value, 0, 0, didThrow, 0, isolate, DoNotThrowExceptions)); |
} |
PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const ScriptValue& value, bool& didThrow, ScriptState* state) |
{ |
ScriptScope scope(state); |
- return adoptRef(new SerializedScriptValue(value.v8Value(), 0, 0, didThrow, state->isolate())); |
+ return adoptRef(new SerializedScriptValue(value.v8Value(), 0, 0, didThrow, 0, state->isolate())); |
} |
PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const String& data) |
@@ -2336,13 +2341,16 @@ inline void neuterBinding(ArrayBufferView* object) |
} |
} |
-PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValue::transferArrayBuffers(ArrayBufferArray& arrayBuffers, bool& didThrow, v8::Isolate* isolate) |
+PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValue::transferArrayBuffers(ArrayBufferArray& arrayBuffers, bool& didThrow, ExceptionState* exceptionState, v8::Isolate* isolate) |
{ |
ASSERT(arrayBuffers.size()); |
for (size_t i = 0; i < arrayBuffers.size(); i++) { |
if (arrayBuffers[i]->isNeutered()) { |
- setDOMException(InvalidStateError, isolate); |
+ if (exceptionState) |
+ exceptionState->throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " is already neutered."); |
+ else |
+ setDOMException(DataCloneError, isolate); |
didThrow = true; |
return nullptr; |
} |
@@ -2360,7 +2368,10 @@ PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu |
bool result = arrayBuffers[i]->transfer(contents->at(i), neuteredViews); |
if (!result) { |
- setDOMException(InvalidStateError, isolate); |
+ if (exceptionState) |
+ exceptionState->throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " could not be transferred."); |
+ else |
+ setDOMException(DataCloneError, isolate); |
didThrow = true; |
return nullptr; |
} |
@@ -2372,7 +2383,7 @@ PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu |
return contents.release(); |
} |
-SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Isolate* isolate, ExceptionPolicy policy) |
+SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, ExceptionState* exceptionState, v8::Isolate* isolate, ExceptionPolicy policy) |
: m_externallyAllocatedMemory(0) |
{ |
didThrow = false; |
@@ -2385,8 +2396,12 @@ SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag |
if (status == Serializer::JSException) { |
didThrow = true; |
// If there was a JS exception thrown, re-throw it. |
- if (policy == ThrowExceptions) |
- tryCatch.ReThrow(); |
+ if (policy == ThrowExceptions) { |
+ if (exceptionState) |
+ exceptionState->setException(tryCatch.Exception()); |
+ else |
+ tryCatch.ReThrow(); |
+ } |
return; |
} |
} |
@@ -2396,13 +2411,14 @@ SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag |
// If there was an input error, throw a new exception outside |
// of the TryCatch scope. |
didThrow = true; |
- if (policy == ThrowExceptions) |
- setDOMException(DataCloneError, isolate); |
- return; |
- case Serializer::InvalidStateError: |
- didThrow = true; |
- if (policy == ThrowExceptions) |
- setDOMException(InvalidStateError, isolate); |
+ if (policy == ThrowExceptions) { |
+ if (exceptionState) { |
+ // FIXME possible to generate a better error messsage than this? |
+ exceptionState->throwDOMException(DataCloneError, "An object could not be cloned."); |
+ } else { |
+ setDOMException(DataCloneError, isolate); |
+ } |
+ } |
return; |
case Serializer::JSFailure: |
// If there was a JS failure (but no exception), there's not |
@@ -2414,7 +2430,7 @@ SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag |
m_data = writer.takeWireString(); |
ASSERT(m_data.impl()->hasOneRef()); |
if (arrayBuffers && arrayBuffers->size()) |
- m_arrayBufferContentsArray = transferArrayBuffers(*arrayBuffers, didThrow, isolate); |
+ m_arrayBufferContentsArray = transferArrayBuffers(*arrayBuffers, didThrow, exceptionState, isolate); |
return; |
case Serializer::JSException: |
// We should never get here because this case was handled above. |