Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "bindings/core/v8/ScriptValueSerializer.h" | 6 #include "bindings/core/v8/ScriptValueSerializer.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/V8ArrayBuffer.h" | 8 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 9 #include "bindings/core/v8/V8ArrayBufferView.h" | 9 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 10 #include "bindings/core/v8/V8Blob.h" | 10 #include "bindings/core/v8/V8Blob.h" |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 | 489 |
| 490 int SerializedScriptValueWriter::v8StringWriteOptions() | 490 int SerializedScriptValueWriter::v8StringWriteOptions() |
| 491 { | 491 { |
| 492 return v8::String::NO_NULL_TERMINATION; | 492 return v8::String::NO_NULL_TERMINATION; |
| 493 } | 493 } |
| 494 | 494 |
| 495 ScriptValueSerializer::StateBase* ScriptValueSerializer::AbstractObjectState::se rializeProperties(bool ignoreIndexed, ScriptValueSerializer& serializer) | 495 ScriptValueSerializer::StateBase* ScriptValueSerializer::AbstractObjectState::se rializeProperties(bool ignoreIndexed, ScriptValueSerializer& serializer) |
| 496 { | 496 { |
| 497 while (m_index < m_propertyNames->Length()) { | 497 while (m_index < m_propertyNames->Length()) { |
| 498 if (!m_nameDone) { | 498 if (!m_nameDone) { |
| 499 v8::Local<v8::Value> propertyName = m_propertyNames->Get(m_index); | 499 v8::Local<v8::Value> propertyName; |
| 500 if (StateBase* newState = serializer.checkException(this)) | 500 if (!m_propertyNames->Get(serializer.context(), m_index).ToLocal(&pr opertyName)) |
| 501 return newState; | 501 return serializer.handleError(JSException, "", this); |
|
Yuki
2015/04/07 07:37:57
Can we add any descriptions for the error?
bashi
2015/04/07 08:47:01
Done.
| |
| 502 if (propertyName.IsEmpty()) | |
| 503 return serializer.handleError(InputError, "Empty property names cannot be cloned.", this); | |
| 504 bool hasStringProperty = propertyName->IsString() && v8CallBoolean(c omposite()->HasRealNamedProperty(serializer.context(), propertyName.As<v8::Strin g>())); | 502 bool hasStringProperty = propertyName->IsString() && v8CallBoolean(c omposite()->HasRealNamedProperty(serializer.context(), propertyName.As<v8::Strin g>())); |
| 505 if (StateBase* newState = serializer.checkException(this)) | 503 if (StateBase* newState = serializer.checkException(this)) |
| 506 return newState; | 504 return newState; |
| 507 bool hasIndexedProperty = !hasStringProperty && propertyName->IsUint 32() && v8CallBoolean(composite()->HasRealIndexedProperty(serializer.context(), propertyName->Uint32Value())); | 505 bool hasIndexedProperty = !hasStringProperty && propertyName->IsUint 32() && v8CallBoolean(composite()->HasRealIndexedProperty(serializer.context(), propertyName->Uint32Value())); |
| 508 if (StateBase* newState = serializer.checkException(this)) | 506 if (StateBase* newState = serializer.checkException(this)) |
| 509 return newState; | 507 return newState; |
| 510 if (hasStringProperty || (hasIndexedProperty && !ignoreIndexed)) { | 508 if (hasStringProperty || (hasIndexedProperty && !ignoreIndexed)) { |
| 511 m_propertyName = propertyName; | 509 m_propertyName = propertyName; |
| 512 } else { | 510 } else { |
| 513 ++m_index; | 511 ++m_index; |
| 514 continue; | 512 continue; |
| 515 } | 513 } |
| 516 } | 514 } |
| 517 ASSERT(!m_propertyName.IsEmpty()); | 515 ASSERT(!m_propertyName.IsEmpty()); |
| 518 if (!m_nameDone) { | 516 if (!m_nameDone) { |
| 519 m_nameDone = true; | 517 m_nameDone = true; |
| 520 if (StateBase* newState = serializer.doSerialize(m_propertyName, thi s)) | 518 if (StateBase* newState = serializer.doSerialize(m_propertyName, thi s)) |
| 521 return newState; | 519 return newState; |
| 522 } | 520 } |
| 523 v8::Local<v8::Value> value = composite()->Get(m_propertyName); | 521 v8::Local<v8::Value> value; |
| 524 if (StateBase* newState = serializer.checkException(this)) | 522 if (!composite()->Get(serializer.context(), m_propertyName).ToLocal(&val ue)) |
| 525 return newState; | 523 return serializer.handleError(JSException, "", this); |
|
Yuki
2015/04/07 07:37:57
Can we add any descriptions for the error?
bashi
2015/04/07 08:47:01
Done.
| |
| 526 m_nameDone = false; | 524 m_nameDone = false; |
| 527 m_propertyName.Clear(); | 525 m_propertyName.Clear(); |
| 528 ++m_index; | 526 ++m_index; |
| 529 ++m_numSerializedProperties; | 527 ++m_numSerializedProperties; |
| 530 // If we return early here, it's either because we have pushed a new sta te onto the | 528 // If we return early here, it's either because we have pushed a new sta te onto the |
| 531 // serialization state stack or because we have encountered an error (an d in both cases | 529 // serialization state stack or because we have encountered an error (an d in both cases |
| 532 // we are unwinding the native stack). | 530 // we are unwinding the native stack). |
| 533 if (StateBase* newState = serializer.doSerialize(value, this)) | 531 if (StateBase* newState = serializer.doSerialize(value, this)) |
| 534 return newState; | 532 return newState; |
| 535 } | 533 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 546 } | 544 } |
| 547 | 545 |
| 548 ScriptValueSerializer::StateBase* ScriptValueSerializer::ObjectState::objectDone (unsigned numProperties, ScriptValueSerializer& serializer) | 546 ScriptValueSerializer::StateBase* ScriptValueSerializer::ObjectState::objectDone (unsigned numProperties, ScriptValueSerializer& serializer) |
| 549 { | 547 { |
| 550 return serializer.writeObject(numProperties, this); | 548 return serializer.writeObject(numProperties, this); |
| 551 } | 549 } |
| 552 | 550 |
| 553 ScriptValueSerializer::StateBase* ScriptValueSerializer::DenseArrayState::advanc e(ScriptValueSerializer& serializer) | 551 ScriptValueSerializer::StateBase* ScriptValueSerializer::DenseArrayState::advanc e(ScriptValueSerializer& serializer) |
| 554 { | 552 { |
| 555 while (m_arrayIndex < m_arrayLength) { | 553 while (m_arrayIndex < m_arrayLength) { |
| 556 v8::Local<v8::Value> value = composite().As<v8::Array>()->Get(m_arrayInd ex); | 554 v8::Local<v8::Value> value; |
| 555 if (!composite().As<v8::Array>()->Get(serializer.context(), m_arrayIndex ).ToLocal(&value)) | |
| 556 return serializer.handleError(JSException, "", this); | |
|
Yuki
2015/04/07 07:37:57
Can we add any descriptions for the error?
bashi
2015/04/07 08:47:01
Done.
| |
| 557 m_arrayIndex++; | 557 m_arrayIndex++; |
| 558 if (StateBase* newState = serializer.checkException(this)) | 558 if (StateBase* newState = serializer.checkException(this)) |
| 559 return newState; | 559 return newState; |
| 560 if (StateBase* newState = serializer.doSerialize(value, this)) | 560 if (StateBase* newState = serializer.doSerialize(value, this)) |
| 561 return newState; | 561 return newState; |
| 562 } | 562 } |
| 563 return serializeProperties(true, serializer); | 563 return serializeProperties(true, serializer); |
| 564 } | 564 } |
| 565 | 565 |
| 566 ScriptValueSerializer::StateBase* ScriptValueSerializer::DenseArrayState::object Done(unsigned numProperties, ScriptValueSerializer& serializer) | 566 ScriptValueSerializer::StateBase* ScriptValueSerializer::DenseArrayState::object Done(unsigned numProperties, ScriptValueSerializer& serializer) |
| (...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1924 return false; | 1924 return false; |
| 1925 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; | 1925 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; |
| 1926 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); | 1926 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); |
| 1927 if (objectReference >= m_objectPool.size()) | 1927 if (objectReference >= m_objectPool.size()) |
| 1928 return false; | 1928 return false; |
| 1929 *object = m_objectPool[objectReference]; | 1929 *object = m_objectPool[objectReference]; |
| 1930 return true; | 1930 return true; |
| 1931 } | 1931 } |
| 1932 | 1932 |
| 1933 } // namespace blink | 1933 } // namespace blink |
| OLD | NEW |