| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "bindings/v8/SerializedScriptValue.h" | 32 #include "bindings/core/v8/SerializedScriptValue.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/ExceptionState.h" |
| 35 #include "bindings/core/v8/V8Binding.h" |
| 34 #include "bindings/core/v8/V8Blob.h" | 36 #include "bindings/core/v8/V8Blob.h" |
| 35 #include "bindings/core/v8/V8File.h" | 37 #include "bindings/core/v8/V8File.h" |
| 36 #include "bindings/core/v8/V8FileList.h" | 38 #include "bindings/core/v8/V8FileList.h" |
| 37 #include "bindings/core/v8/V8ImageData.h" | 39 #include "bindings/core/v8/V8ImageData.h" |
| 38 #include "bindings/core/v8/V8MessagePort.h" | 40 #include "bindings/core/v8/V8MessagePort.h" |
| 41 #include "bindings/core/v8/WorkerScriptController.h" |
| 39 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h" | 42 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h" |
| 40 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h" | 43 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h" |
| 41 #include "bindings/core/v8/custom/V8DataViewCustom.h" | 44 #include "bindings/core/v8/custom/V8DataViewCustom.h" |
| 42 #include "bindings/core/v8/custom/V8Float32ArrayCustom.h" | 45 #include "bindings/core/v8/custom/V8Float32ArrayCustom.h" |
| 43 #include "bindings/core/v8/custom/V8Float64ArrayCustom.h" | 46 #include "bindings/core/v8/custom/V8Float64ArrayCustom.h" |
| 44 #include "bindings/core/v8/custom/V8Int16ArrayCustom.h" | 47 #include "bindings/core/v8/custom/V8Int16ArrayCustom.h" |
| 45 #include "bindings/core/v8/custom/V8Int32ArrayCustom.h" | 48 #include "bindings/core/v8/custom/V8Int32ArrayCustom.h" |
| 46 #include "bindings/core/v8/custom/V8Int8ArrayCustom.h" | 49 #include "bindings/core/v8/custom/V8Int8ArrayCustom.h" |
| 47 #include "bindings/core/v8/custom/V8Uint16ArrayCustom.h" | 50 #include "bindings/core/v8/custom/V8Uint16ArrayCustom.h" |
| 48 #include "bindings/core/v8/custom/V8Uint32ArrayCustom.h" | 51 #include "bindings/core/v8/custom/V8Uint32ArrayCustom.h" |
| 49 #include "bindings/core/v8/custom/V8Uint8ArrayCustom.h" | 52 #include "bindings/core/v8/custom/V8Uint8ArrayCustom.h" |
| 50 #include "bindings/core/v8/custom/V8Uint8ClampedArrayCustom.h" | 53 #include "bindings/core/v8/custom/V8Uint8ClampedArrayCustom.h" |
| 51 #include "bindings/modules/v8/V8CryptoKey.h" | 54 #include "bindings/modules/v8/V8CryptoKey.h" |
| 52 #include "bindings/modules/v8/V8DOMFileSystem.h" | 55 #include "bindings/modules/v8/V8DOMFileSystem.h" |
| 53 #include "bindings/v8/ExceptionState.h" | |
| 54 #include "bindings/v8/V8Binding.h" | |
| 55 #include "bindings/v8/WorkerScriptController.h" | |
| 56 #include "core/dom/ExceptionCode.h" | 56 #include "core/dom/ExceptionCode.h" |
| 57 #include "core/dom/MessagePort.h" | 57 #include "core/dom/MessagePort.h" |
| 58 #include "core/fileapi/Blob.h" | 58 #include "core/fileapi/Blob.h" |
| 59 #include "core/fileapi/File.h" | 59 #include "core/fileapi/File.h" |
| 60 #include "core/fileapi/FileList.h" | 60 #include "core/fileapi/FileList.h" |
| 61 #include "core/html/ImageData.h" | 61 #include "core/html/ImageData.h" |
| 62 #include "core/html/canvas/DataView.h" | 62 #include "core/html/canvas/DataView.h" |
| 63 #include "platform/SharedBuffer.h" | 63 #include "platform/SharedBuffer.h" |
| 64 #include "platform/heap/Handle.h" | 64 #include "platform/heap/Handle.h" |
| 65 #include "public/platform/Platform.h" | 65 #include "public/platform/Platform.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 { | 364 { |
| 365 int stringLength = string->Length(); | 365 int stringLength = string->Length(); |
| 366 int utf8Length = string->Utf8Length(); | 366 int utf8Length = string->Utf8Length(); |
| 367 ASSERT(stringLength >= 0 && utf8Length >= 0); | 367 ASSERT(stringLength >= 0 && utf8Length >= 0); |
| 368 | 368 |
| 369 append(StringTag); | 369 append(StringTag); |
| 370 doWriteUint32(static_cast<uint32_t>(utf8Length)); | 370 doWriteUint32(static_cast<uint32_t>(utf8Length)); |
| 371 ensureSpace(utf8Length); | 371 ensureSpace(utf8Length); |
| 372 | 372 |
| 373 // ASCII fast path. | 373 // ASCII fast path. |
| 374 if (stringLength == utf8Length) | 374 if (stringLength == utf8Length) { |
| 375 string->WriteOneByte(byteAt(m_position), 0, utf8Length, v8StringWrit
eOptions()); | 375 string->WriteOneByte(byteAt(m_position), 0, utf8Length, v8StringWrit
eOptions()); |
| 376 else { | 376 } else { |
| 377 char* buffer = reinterpret_cast<char*>(byteAt(m_position)); | 377 char* buffer = reinterpret_cast<char*>(byteAt(m_position)); |
| 378 string->WriteUtf8(buffer, utf8Length, 0, v8StringWriteOptions()); | 378 string->WriteUtf8(buffer, utf8Length, 0, v8StringWriteOptions()); |
| 379 } | 379 } |
| 380 m_position += utf8Length; | 380 m_position += utf8Length; |
| 381 } | 381 } |
| 382 | 382 |
| 383 void writeUCharString(v8::Handle<v8::String>& string) | 383 void writeUCharString(v8::Handle<v8::String>& string) |
| 384 { | 384 { |
| 385 int length = string->Length(); | 385 int length = string->Length(); |
| 386 ASSERT(length >= 0); | 386 ASSERT(length >= 0); |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 if (StateBase* newState = serializer.checkException(this)) | 1077 if (StateBase* newState = serializer.checkException(this)) |
| 1078 return newState; | 1078 return newState; |
| 1079 if (propertyName.IsEmpty()) | 1079 if (propertyName.IsEmpty()) |
| 1080 return serializer.handleError(InputError, "Empty propert
y names cannot be cloned.", this); | 1080 return serializer.handleError(InputError, "Empty propert
y names cannot be cloned.", this); |
| 1081 bool hasStringProperty = propertyName->IsString() && composi
te()->HasRealNamedProperty(propertyName.As<v8::String>()); | 1081 bool hasStringProperty = propertyName->IsString() && composi
te()->HasRealNamedProperty(propertyName.As<v8::String>()); |
| 1082 if (StateBase* newState = serializer.checkException(this)) | 1082 if (StateBase* newState = serializer.checkException(this)) |
| 1083 return newState; | 1083 return newState; |
| 1084 bool hasIndexedProperty = !hasStringProperty && propertyName
->IsUint32() && composite()->HasRealIndexedProperty(propertyName->Uint32Value())
; | 1084 bool hasIndexedProperty = !hasStringProperty && propertyName
->IsUint32() && composite()->HasRealIndexedProperty(propertyName->Uint32Value())
; |
| 1085 if (StateBase* newState = serializer.checkException(this)) | 1085 if (StateBase* newState = serializer.checkException(this)) |
| 1086 return newState; | 1086 return newState; |
| 1087 if (hasStringProperty || (hasIndexedProperty && !ignoreIndex
ed)) | 1087 if (hasStringProperty || (hasIndexedProperty && !ignoreIndex
ed)) { |
| 1088 m_propertyName = propertyName; | 1088 m_propertyName = propertyName; |
| 1089 else { | 1089 } else { |
| 1090 ++m_index; | 1090 ++m_index; |
| 1091 continue; | 1091 continue; |
| 1092 } | 1092 } |
| 1093 } | 1093 } |
| 1094 ASSERT(!m_propertyName.IsEmpty()); | 1094 ASSERT(!m_propertyName.IsEmpty()); |
| 1095 if (!m_nameDone) { | 1095 if (!m_nameDone) { |
| 1096 m_nameDone = true; | 1096 m_nameDone = true; |
| 1097 if (StateBase* newState = serializer.doSerialize(m_propertyN
ame, this)) | 1097 if (StateBase* newState = serializer.doSerialize(m_propertyN
ame, this)) |
| 1098 return newState; | 1098 return newState; |
| 1099 } | 1099 } |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 uint32_t objectReference; | 1515 uint32_t objectReference; |
| 1516 uint32_t arrayBufferIndex; | 1516 uint32_t arrayBufferIndex; |
| 1517 if ((value->IsObject() || value->IsDate() || value->IsRegExp()) | 1517 if ((value->IsObject() || value->IsDate() || value->IsRegExp()) |
| 1518 && m_objectPool.tryGet(value.As<v8::Object>(), &objectReference)) { | 1518 && m_objectPool.tryGet(value.As<v8::Object>(), &objectReference)) { |
| 1519 // Note that IsObject() also detects wrappers (eg, it will catch the thi
ngs | 1519 // Note that IsObject() also detects wrappers (eg, it will catch the thi
ngs |
| 1520 // that we grey and write below). | 1520 // that we grey and write below). |
| 1521 ASSERT(!value->IsString()); | 1521 ASSERT(!value->IsString()); |
| 1522 m_writer.writeObjectReference(objectReference); | 1522 m_writer.writeObjectReference(objectReference); |
| 1523 } else if (value.IsEmpty()) { | 1523 } else if (value.IsEmpty()) { |
| 1524 return handleError(InputError, "The empty property name cannot be cloned
.", next); | 1524 return handleError(InputError, "The empty property name cannot be cloned
.", next); |
| 1525 } else if (value->IsUndefined()) | 1525 } else if (value->IsUndefined()) { |
| 1526 m_writer.writeUndefined(); | 1526 m_writer.writeUndefined(); |
| 1527 else if (value->IsNull()) | 1527 } else if (value->IsNull()) { |
| 1528 m_writer.writeNull(); | 1528 m_writer.writeNull(); |
| 1529 else if (value->IsTrue()) | 1529 } else if (value->IsTrue()) { |
| 1530 m_writer.writeTrue(); | 1530 m_writer.writeTrue(); |
| 1531 else if (value->IsFalse()) | 1531 } else if (value->IsFalse()) { |
| 1532 m_writer.writeFalse(); | 1532 m_writer.writeFalse(); |
| 1533 else if (value->IsInt32()) | 1533 } else if (value->IsInt32()) { |
| 1534 m_writer.writeInt32(value->Int32Value()); | 1534 m_writer.writeInt32(value->Int32Value()); |
| 1535 else if (value->IsUint32()) | 1535 } else if (value->IsUint32()) { |
| 1536 m_writer.writeUint32(value->Uint32Value()); | 1536 m_writer.writeUint32(value->Uint32Value()); |
| 1537 else if (value->IsNumber()) | 1537 } else if (value->IsNumber()) { |
| 1538 m_writer.writeNumber(value.As<v8::Number>()->Value()); | 1538 m_writer.writeNumber(value.As<v8::Number>()->Value()); |
| 1539 else if (V8ArrayBufferView::hasInstance(value, isolate())) | 1539 } else if (V8ArrayBufferView::hasInstance(value, isolate())) { |
| 1540 return writeAndGreyArrayBufferView(value.As<v8::Object>(), next); | 1540 return writeAndGreyArrayBufferView(value.As<v8::Object>(), next); |
| 1541 else if (value->IsString()) | 1541 } else if (value->IsString()) { |
| 1542 writeString(value); | 1542 writeString(value); |
| 1543 else if (V8MessagePort::hasInstance(value, isolate())) { | 1543 } else if (V8MessagePort::hasInstance(value, isolate())) { |
| 1544 uint32_t messagePortIndex; | 1544 uint32_t messagePortIndex; |
| 1545 if (m_transferredMessagePorts.tryGet(value.As<v8::Object>(), &messagePor
tIndex)) | 1545 if (m_transferredMessagePorts.tryGet(value.As<v8::Object>(), &messagePor
tIndex)) { |
| 1546 m_writer.writeTransferredMessagePort(messagePortIndex); | 1546 m_writer.writeTransferredMessagePort(messagePortIndex); |
| 1547 else | 1547 } else { |
| 1548 return handleError(DataCloneError, "A MessagePort could not be c
loned.", next); | 1548 return handleError(DataCloneError, "A MessagePort could not be clone
d.", next); |
| 1549 } else if (V8ArrayBuffer::hasInstance(value, isolate()) && m_transferredArra
yBuffers.tryGet(value.As<v8::Object>(), &arrayBufferIndex)) | 1549 } |
| 1550 } else if (V8ArrayBuffer::hasInstance(value, isolate()) && m_transferredArra
yBuffers.tryGet(value.As<v8::Object>(), &arrayBufferIndex)) { |
| 1550 return writeTransferredArrayBuffer(value, arrayBufferIndex, next); | 1551 return writeTransferredArrayBuffer(value, arrayBufferIndex, next); |
| 1551 else { | 1552 } else { |
| 1552 v8::Handle<v8::Object> jsObject = value.As<v8::Object>(); | 1553 v8::Handle<v8::Object> jsObject = value.As<v8::Object>(); |
| 1553 if (jsObject.IsEmpty()) | 1554 if (jsObject.IsEmpty()) |
| 1554 return handleError(DataCloneError, "An object could not be cloned.",
next); | 1555 return handleError(DataCloneError, "An object could not be cloned.",
next); |
| 1555 greyObject(jsObject); | 1556 greyObject(jsObject); |
| 1556 if (value->IsDate()) | 1557 if (value->IsDate()) { |
| 1557 m_writer.writeDate(value->NumberValue()); | 1558 m_writer.writeDate(value->NumberValue()); |
| 1558 else if (value->IsStringObject()) | 1559 } else if (value->IsStringObject()) { |
| 1559 writeStringObject(value); | 1560 writeStringObject(value); |
| 1560 else if (value->IsNumberObject()) | 1561 } else if (value->IsNumberObject()) { |
| 1561 writeNumberObject(value); | 1562 writeNumberObject(value); |
| 1562 else if (value->IsBooleanObject()) | 1563 } else if (value->IsBooleanObject()) { |
| 1563 writeBooleanObject(value); | 1564 writeBooleanObject(value); |
| 1564 else if (value->IsArray()) { | 1565 } else if (value->IsArray()) { |
| 1565 return startArrayState(value.As<v8::Array>(), next); | 1566 return startArrayState(value.As<v8::Array>(), next); |
| 1566 } else if (V8File::hasInstance(value, isolate())) | 1567 } else if (V8File::hasInstance(value, isolate())) { |
| 1567 return writeFile(value, next); | 1568 return writeFile(value, next); |
| 1568 else if (V8Blob::hasInstance(value, isolate())) | 1569 } else if (V8Blob::hasInstance(value, isolate())) { |
| 1569 return writeBlob(value, next); | 1570 return writeBlob(value, next); |
| 1570 else if (V8DOMFileSystem::hasInstance(value, isolate())) | 1571 } else if (V8DOMFileSystem::hasInstance(value, isolate())) { |
| 1571 return writeDOMFileSystem(value, next); | 1572 return writeDOMFileSystem(value, next); |
| 1572 else if (V8FileList::hasInstance(value, isolate())) | 1573 } else if (V8FileList::hasInstance(value, isolate())) { |
| 1573 return writeFileList(value, next); | 1574 return writeFileList(value, next); |
| 1574 else if (V8CryptoKey::hasInstance(value, isolate())) { | 1575 } else if (V8CryptoKey::hasInstance(value, isolate())) { |
| 1575 if (!writeCryptoKey(value)) | 1576 if (!writeCryptoKey(value)) |
| 1576 return handleError(DataCloneError, "Couldn't serialize key data"
, next); | 1577 return handleError(DataCloneError, "Couldn't serialize key data"
, next); |
| 1577 } else if (V8ImageData::hasInstance(value, isolate())) | 1578 } else if (V8ImageData::hasInstance(value, isolate())) { |
| 1578 writeImageData(value); | 1579 writeImageData(value); |
| 1579 else if (value->IsRegExp()) | 1580 } else if (value->IsRegExp()) { |
| 1580 writeRegExp(value); | 1581 writeRegExp(value); |
| 1581 else if (V8ArrayBuffer::hasInstance(value, isolate())) | 1582 } else if (V8ArrayBuffer::hasInstance(value, isolate())) { |
| 1582 return writeArrayBuffer(value, next); | 1583 return writeArrayBuffer(value, next); |
| 1583 else if (value->IsObject()) { | 1584 } else if (value->IsObject()) { |
| 1584 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat
iveError()) | 1585 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat
iveError()) |
| 1585 return handleError(DataCloneError, "An object could not be clone
d.", next); | 1586 return handleError(DataCloneError, "An object could not be clone
d.", next); |
| 1586 return startObjectState(jsObject, next); | 1587 return startObjectState(jsObject, next); |
| 1587 } else | 1588 } else { |
| 1588 return handleError(DataCloneError, "A value could not be cloned.", n
ext); | 1589 return handleError(DataCloneError, "A value could not be cloned.", n
ext); |
| 1590 } |
| 1589 } | 1591 } |
| 1590 return 0; | 1592 return 0; |
| 1591 } | 1593 } |
| 1592 | 1594 |
| 1593 // Interface used by Reader to create objects of composite types. | 1595 // Interface used by Reader to create objects of composite types. |
| 1594 class CompositeCreator { | 1596 class CompositeCreator { |
| 1595 public: | 1597 public: |
| 1596 virtual ~CompositeCreator() { } | 1598 virtual ~CompositeCreator() { } |
| 1597 | 1599 |
| 1598 virtual bool consumeTopOfStack(v8::Handle<v8::Value>*) = 0; | 1600 virtual bool consumeTopOfStack(v8::Handle<v8::Value>*) = 0; |
| (...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3053 // If the allocated memory was not registered before, then this class is lik
ely | 3055 // If the allocated memory was not registered before, then this class is lik
ely |
| 3054 // used in a context other then Worker's onmessage environment and the prese
nce of | 3056 // used in a context other then Worker's onmessage environment and the prese
nce of |
| 3055 // current v8 context is not guaranteed. Avoid calling v8 then. | 3057 // current v8 context is not guaranteed. Avoid calling v8 then. |
| 3056 if (m_externallyAllocatedMemory) { | 3058 if (m_externallyAllocatedMemory) { |
| 3057 ASSERT(v8::Isolate::GetCurrent()); | 3059 ASSERT(v8::Isolate::GetCurrent()); |
| 3058 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); | 3060 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); |
| 3059 } | 3061 } |
| 3060 } | 3062 } |
| 3061 | 3063 |
| 3062 } // namespace WebCore | 3064 } // namespace WebCore |
| OLD | NEW |