| 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 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 if (!closeComposite(&composite)) | 1818 if (!closeComposite(&composite)) |
| 1819 return false; | 1819 return false; |
| 1820 array = composite.As<v8::Array>(); | 1820 array = composite.As<v8::Array>(); |
| 1821 } | 1821 } |
| 1822 if (array.IsEmpty()) | 1822 if (array.IsEmpty()) |
| 1823 return false; | 1823 return false; |
| 1824 if (!initializeObject(array, numProperties, value)) | 1824 if (!initializeObject(array, numProperties, value)) |
| 1825 return false; | 1825 return false; |
| 1826 if (length > stackDepth()) | 1826 if (length > stackDepth()) |
| 1827 return false; | 1827 return false; |
| 1828 v8::Isolate* isolate = m_reader.scriptState()->isolate(); | |
| 1829 v8::Local<v8::Context> context = m_reader.scriptState()->context(); | 1828 v8::Local<v8::Context> context = m_reader.scriptState()->context(); |
| 1830 for (unsigned i = 0, stackPos = stackDepth() - length; i < length; i++, stac
kPos++) { | 1829 for (unsigned i = 0, stackPos = stackDepth() - length; i < length; i++, stac
kPos++) { |
| 1831 v8::Local<v8::Value> elem = element(stackPos); | 1830 v8::Local<v8::Value> elem = element(stackPos); |
| 1832 if (!elem->IsUndefined()) { | 1831 if (!elem->IsUndefined()) { |
| 1833 // TODO(jsbell): Use DefineOwnProperty when exposed by v8. http://cr
bug.com/475206 | 1832 if (!v8CallBoolean(array->CreateDataProperty(context, i, elem))) |
| 1834 if (!v8CallBoolean(array->ForceSet(context, v8::Integer::New(isolate
, i), elem))) | |
| 1835 return false; | 1833 return false; |
| 1836 } | 1834 } |
| 1837 } | 1835 } |
| 1838 pop(length); | 1836 pop(length); |
| 1839 return true; | 1837 return true; |
| 1840 } | 1838 } |
| 1841 | 1839 |
| 1842 void ScriptValueDeserializer::pushObjectReference(const v8::Local<v8::Value>& ob
ject) | 1840 void ScriptValueDeserializer::pushObjectReference(const v8::Local<v8::Value>& ob
ject) |
| 1843 { | 1841 { |
| 1844 m_objectPool.append(object); | 1842 m_objectPool.append(object); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1890 | 1888 |
| 1891 bool ScriptValueDeserializer::initializeObject(v8::Local<v8::Object> object, uin
t32_t numProperties, v8::Local<v8::Value>* value) | 1889 bool ScriptValueDeserializer::initializeObject(v8::Local<v8::Object> object, uin
t32_t numProperties, v8::Local<v8::Value>* value) |
| 1892 { | 1890 { |
| 1893 unsigned length = 2 * numProperties; | 1891 unsigned length = 2 * numProperties; |
| 1894 if (length > stackDepth()) | 1892 if (length > stackDepth()) |
| 1895 return false; | 1893 return false; |
| 1896 v8::Local<v8::Context> context = m_reader.scriptState()->context(); | 1894 v8::Local<v8::Context> context = m_reader.scriptState()->context(); |
| 1897 for (unsigned i = stackDepth() - length; i < stackDepth(); i += 2) { | 1895 for (unsigned i = stackDepth() - length; i < stackDepth(); i += 2) { |
| 1898 v8::Local<v8::Value> propertyName = element(i); | 1896 v8::Local<v8::Value> propertyName = element(i); |
| 1899 v8::Local<v8::Value> propertyValue = element(i + 1); | 1897 v8::Local<v8::Value> propertyValue = element(i + 1); |
| 1900 // TODO(jsbell): Use DefineOwnProperty when exposed by v8. http://crbug.
com/475206 | 1898 bool result = false; |
| 1901 if (!v8CallBoolean(object->ForceSet(context, propertyName, propertyValue
))) | 1899 if (propertyName->IsString()) |
| 1900 result = v8CallBoolean(object->CreateDataProperty(context, propertyN
ame.As<v8::String>(), propertyValue)); |
| 1901 else if (propertyName->IsUint32()) |
| 1902 result = v8CallBoolean(object->CreateDataProperty(context, propertyN
ame.As<v8::Uint32>()->Value(), propertyValue)); |
| 1903 else |
| 1904 ASSERT_NOT_REACHED(); |
| 1905 if (!result) |
| 1902 return false; | 1906 return false; |
| 1903 } | 1907 } |
| 1904 pop(length); | 1908 pop(length); |
| 1905 *value = object; | 1909 *value = object; |
| 1906 return true; | 1910 return true; |
| 1907 } | 1911 } |
| 1908 | 1912 |
| 1909 bool ScriptValueDeserializer::read(v8::Local<v8::Value>* value) | 1913 bool ScriptValueDeserializer::read(v8::Local<v8::Value>* value) |
| 1910 { | 1914 { |
| 1911 return m_reader.read(value, *this); | 1915 return m_reader.read(value, *this); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1940 return false; | 1944 return false; |
| 1941 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; | 1945 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; |
| 1942 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); | 1946 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); |
| 1943 if (objectReference >= m_objectPool.size()) | 1947 if (objectReference >= m_objectPool.size()) |
| 1944 return false; | 1948 return false; |
| 1945 *object = m_objectPool[objectReference]; | 1949 *object = m_objectPool[objectReference]; |
| 1946 return true; | 1950 return true; |
| 1947 } | 1951 } |
| 1948 | 1952 |
| 1949 } // namespace blink | 1953 } // namespace blink |
| OLD | NEW |