| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 int expected) { | 125 int expected) { |
| 126 IDBKey* idb_key = | 126 IDBKey* idb_key = |
| 127 CheckKeyFromValueAndKeyPathInternal(isolate, value, key_path); | 127 CheckKeyFromValueAndKeyPathInternal(isolate, value, key_path); |
| 128 ASSERT_TRUE(idb_key); | 128 ASSERT_TRUE(idb_key); |
| 129 ASSERT_EQ(IDBKey::kNumberType, idb_key->GetType()); | 129 ASSERT_EQ(IDBKey::kNumberType, idb_key->GetType()); |
| 130 ASSERT_TRUE(expected == idb_key->Number()); | 130 ASSERT_TRUE(expected == idb_key->Number()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // SerializedScriptValue header format offsets are inferred from the Blink and | 133 // SerializedScriptValue header format offsets are inferred from the Blink and |
| 134 // V8 serialization code. The code below DCHECKs that | 134 // V8 serialization code. The code below DCHECKs that |
| 135 constexpr static size_t kSSVHeaderBlinkVersionOffset = 0; | 135 constexpr static size_t kSSVHeaderBlinkVersionTagOffset = 0; |
| 136 constexpr static size_t kSSVHeaderBlinkVersionTagOffset = 1; | 136 constexpr static size_t kSSVHeaderBlinkVersionOffset = 1; |
| 137 constexpr static size_t kSSVHeaderV8VersionOffset = 2; | 137 constexpr static size_t kSSVHeaderV8VersionTagOffset = 2; |
| 138 constexpr static size_t kSSVHeaderV8VersionTagOffset = 3; | 138 constexpr static size_t kSSVHeaderV8VersionOffset = 3; |
| 139 | |
| 140 // 13 is v8::internal::kLatestVersion in v8/src/value-serializer.cc at the | |
| 141 // time when this test was written. Unlike Blink, V8 does not currently export | |
| 142 // its serialization version, so this number might get stale. | |
| 143 constexpr static unsigned char kV8LatestKnownVersion = 13; | |
| 144 | 139 |
| 145 // Follows the same steps as the IndexedDB value serialization code. | 140 // Follows the same steps as the IndexedDB value serialization code. |
| 146 void SerializeV8Value(v8::Local<v8::Value> value, | 141 void SerializeV8Value(v8::Local<v8::Value> value, |
| 147 v8::Isolate* isolate, | 142 v8::Isolate* isolate, |
| 148 Vector<char>* wire_bytes) { | 143 Vector<char>* wire_bytes) { |
| 149 NonThrowableExceptionState non_throwable_exception_state; | 144 NonThrowableExceptionState non_throwable_exception_state; |
| 150 | 145 |
| 151 SerializedScriptValue::SerializeOptions options; | 146 SerializedScriptValue::SerializeOptions options; |
| 152 RefPtr<SerializedScriptValue> serialized_value = | 147 RefPtr<SerializedScriptValue> serialized_value = |
| 153 SerializedScriptValue::Serialize(isolate, value, options, | 148 SerializedScriptValue::Serialize(isolate, value, options, |
| 154 non_throwable_exception_state); | 149 non_throwable_exception_state); |
| 155 serialized_value->ToWireBytes(*wire_bytes); | 150 serialized_value->ToWireBytes(*wire_bytes); |
| 156 | 151 |
| 157 // Sanity check that the serialization header has not changed, as the tests | 152 // Sanity check that the serialization header has not changed, as the tests |
| 158 // that use this method rely on the header format. | 153 // that use this method rely on the header format. |
| 159 // | 154 // |
| 160 // The cast from char* to unsigned char* is necessary to avoid VS2015 warning | 155 // The cast from char* to unsigned char* is necessary to avoid VS2015 warning |
| 161 // C4309 (truncation of constant value). This happens because VersionTag is | 156 // C4309 (truncation of constant value). This happens because VersionTag is |
| 162 // 0xFF. | 157 // 0xFF. |
| 163 const unsigned char* wire_data = | 158 const unsigned char* wire_data = |
| 164 reinterpret_cast<unsigned char*>(wire_bytes->Data()); | 159 reinterpret_cast<unsigned char*>(wire_bytes->Data()); |
| 160 ASSERT_EQ(static_cast<unsigned char>(kVersionTag), |
| 161 wire_data[kSSVHeaderBlinkVersionTagOffset]); |
| 165 ASSERT_EQ( | 162 ASSERT_EQ( |
| 166 static_cast<unsigned char>(SerializedScriptValue::kWireFormatVersion), | 163 static_cast<unsigned char>(SerializedScriptValue::kWireFormatVersion), |
| 167 wire_data[kSSVHeaderBlinkVersionOffset]); | 164 wire_data[kSSVHeaderBlinkVersionOffset]); |
| 168 ASSERT_EQ(static_cast<unsigned char>(kVersionTag), | |
| 169 wire_data[kSSVHeaderBlinkVersionTagOffset]); | |
| 170 | 165 |
| 171 ASSERT_GE(static_cast<unsigned char>(kV8LatestKnownVersion), | |
| 172 wire_data[kSSVHeaderV8VersionOffset]); | |
| 173 ASSERT_EQ(static_cast<unsigned char>(kVersionTag), | 166 ASSERT_EQ(static_cast<unsigned char>(kVersionTag), |
| 174 wire_data[kSSVHeaderV8VersionTagOffset]); | 167 wire_data[kSSVHeaderV8VersionTagOffset]); |
| 168 ASSERT_EQ(v8::ValueSerializer::GetCurrentDataFormatVersion(), |
| 169 wire_data[kSSVHeaderV8VersionOffset]); |
| 175 } | 170 } |
| 176 | 171 |
| 177 PassRefPtr<IDBValue> CreateIDBValue(v8::Isolate* isolate, | 172 PassRefPtr<IDBValue> CreateIDBValue(v8::Isolate* isolate, |
| 178 Vector<char>& wire_bytes, | 173 Vector<char>& wire_bytes, |
| 179 double primary_key, | 174 double primary_key, |
| 180 const WebString& key_path) { | 175 const WebString& key_path) { |
| 181 WebData web_data(SharedBuffer::AdoptVector(wire_bytes)); | 176 WebData web_data(SharedBuffer::AdoptVector(wire_bytes)); |
| 182 Vector<WebBlobInfo> web_blob_info; | 177 Vector<WebBlobInfo> web_blob_info; |
| 183 WebIDBKey web_idb_key = WebIDBKey::CreateNumber(primary_key); | 178 WebIDBKey web_idb_key = WebIDBKey::CreateNumber(primary_key); |
| 184 WebIDBKeyPath web_idb_key_path(key_path); | 179 WebIDBKeyPath web_idb_key_path(key_path); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 387 |
| 393 v8::Local<v8::Value> v8_value = DeserializeIDBValue( | 388 v8::Local<v8::Value> v8_value = DeserializeIDBValue( |
| 394 isolate, scope.GetContext()->Global(), idb_value.Get()); | 389 isolate, scope.GetContext()->Global(), idb_value.Get()); |
| 395 EXPECT_TRUE(!scope.GetExceptionState().HadException()); | 390 EXPECT_TRUE(!scope.GetExceptionState().HadException()); |
| 396 ASSERT_TRUE(v8_value->IsNumber()); | 391 ASSERT_TRUE(v8_value->IsNumber()); |
| 397 v8::Local<v8::Number> v8_number = v8_value.As<v8::Number>(); | 392 v8::Local<v8::Number> v8_number = v8_value.As<v8::Number>(); |
| 398 EXPECT_EQ(v8_number->Value(), 42.0); | 393 EXPECT_EQ(v8_number->Value(), 42.0); |
| 399 } | 394 } |
| 400 | 395 |
| 401 } // namespace blink | 396 } // namespace blink |
| OLD | NEW |