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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 const String& keyPath, | 122 const String& keyPath, |
123 int expected) { | 123 int expected) { |
124 IDBKey* idbKey = checkKeyFromValueAndKeyPathInternal(isolate, value, keyPath); | 124 IDBKey* idbKey = checkKeyFromValueAndKeyPathInternal(isolate, value, keyPath); |
125 ASSERT_TRUE(idbKey); | 125 ASSERT_TRUE(idbKey); |
126 ASSERT_EQ(IDBKey::NumberType, idbKey->getType()); | 126 ASSERT_EQ(IDBKey::NumberType, idbKey->getType()); |
127 ASSERT_TRUE(expected == idbKey->number()); | 127 ASSERT_TRUE(expected == idbKey->number()); |
128 } | 128 } |
129 | 129 |
130 // SerializedScriptValue header format offsets are inferred from the Blink and | 130 // SerializedScriptValue header format offsets are inferred from the Blink and |
131 // V8 serialization code. The code below DCHECKs that | 131 // V8 serialization code. The code below DCHECKs that |
132 constexpr static size_t kSSVHeaderBlinkVersionOffset = 0; | 132 constexpr static size_t kSSVHeaderBlinkVersionTagOffset = 0; |
133 constexpr static size_t kSSVHeaderBlinkVersionTagOffset = 1; | 133 constexpr static size_t kSSVHeaderBlinkVersionOffset = 1; |
134 constexpr static size_t kSSVHeaderV8VersionOffset = 2; | 134 constexpr static size_t kSSVHeaderV8VersionTagOffset = 2; |
135 constexpr static size_t kSSVHeaderV8VersionTagOffset = 3; | 135 constexpr static size_t kSSVHeaderV8VersionOffset = 3; |
136 | 136 |
137 // 13 is v8::internal::kLatestVersion in v8/src/value-serializer.cc at the | 137 // 13 is v8::internal::kLatestVersion in v8/src/value-serializer.cc at the |
138 // time when this test was written. Unlike Blink, V8 does not currently export | 138 // time when this test was written. Unlike Blink, V8 does not currently export |
139 // its serialization version, so this number might get stale. | 139 // its serialization version, so this number might get stale. |
140 constexpr static unsigned char kV8LatestKnownVersion = 13; | 140 constexpr static unsigned char kV8LatestKnownVersion = 13; |
141 | 141 |
142 // Follows the same steps as the IndexedDB value serialization code. | 142 // Follows the same steps as the IndexedDB value serialization code. |
143 void serializeV8Value(v8::Local<v8::Value> value, | 143 void serializeV8Value(v8::Local<v8::Value> value, |
144 v8::Isolate* isolate, | 144 v8::Isolate* isolate, |
145 Vector<char>* wireBytes) { | 145 Vector<char>* wireBytes) { |
146 NonThrowableExceptionState nonThrowableExceptionState; | 146 NonThrowableExceptionState nonThrowableExceptionState; |
147 | 147 |
148 SerializedScriptValue::SerializeOptions options; | 148 SerializedScriptValue::SerializeOptions options; |
149 RefPtr<SerializedScriptValue> serializedValue = | 149 RefPtr<SerializedScriptValue> serializedValue = |
150 SerializedScriptValue::serialize(isolate, value, options, | 150 SerializedScriptValue::serialize(isolate, value, options, |
151 nonThrowableExceptionState); | 151 nonThrowableExceptionState); |
152 serializedValue->toWireBytes(*wireBytes); | 152 serializedValue->toWireBytes(*wireBytes); |
153 | 153 |
154 // Sanity check that the serialization header has not changed, as the tests | 154 // Sanity check that the serialization header has not changed, as the tests |
155 // that use this method rely on the header format. | 155 // that use this method rely on the header format. |
156 // | 156 // |
157 // The cast from char* to unsigned char* is necessary to avoid VS2015 warning | 157 // The cast from char* to unsigned char* is necessary to avoid VS2015 warning |
158 // C4309 (truncation of constant value). This happens because VersionTag is | 158 // C4309 (truncation of constant value). This happens because VersionTag is |
159 // 0xFF. | 159 // 0xFF. |
160 const unsigned char* wireData = | 160 const unsigned char* wireData = |
161 reinterpret_cast<unsigned char*>(wireBytes->data()); | 161 reinterpret_cast<unsigned char*>(wireBytes->data()); |
| 162 ASSERT_EQ(static_cast<unsigned char>(VersionTag), |
| 163 wireData[kSSVHeaderBlinkVersionTagOffset]); |
162 ASSERT_EQ( | 164 ASSERT_EQ( |
163 static_cast<unsigned char>(SerializedScriptValue::wireFormatVersion), | 165 static_cast<unsigned char>(SerializedScriptValue::wireFormatVersion), |
164 wireData[kSSVHeaderBlinkVersionOffset]); | 166 wireData[kSSVHeaderBlinkVersionOffset]); |
| 167 |
165 ASSERT_EQ(static_cast<unsigned char>(VersionTag), | 168 ASSERT_EQ(static_cast<unsigned char>(VersionTag), |
166 wireData[kSSVHeaderBlinkVersionTagOffset]); | 169 wireData[kSSVHeaderV8VersionTagOffset]); |
167 | |
168 ASSERT_GE(static_cast<unsigned char>(kV8LatestKnownVersion), | 170 ASSERT_GE(static_cast<unsigned char>(kV8LatestKnownVersion), |
169 wireData[kSSVHeaderV8VersionOffset]); | 171 wireData[kSSVHeaderV8VersionOffset]); |
170 ASSERT_EQ(static_cast<unsigned char>(VersionTag), | |
171 wireData[kSSVHeaderV8VersionTagOffset]); | |
172 } | 172 } |
173 | 173 |
174 PassRefPtr<IDBValue> createIDBValue(v8::Isolate* isolate, | 174 PassRefPtr<IDBValue> createIDBValue(v8::Isolate* isolate, |
175 Vector<char>& wireBytes, | 175 Vector<char>& wireBytes, |
176 double primaryKey, | 176 double primaryKey, |
177 const WebString& keyPath) { | 177 const WebString& keyPath) { |
178 WebData webData(SharedBuffer::adoptVector(wireBytes)); | 178 WebData webData(SharedBuffer::adoptVector(wireBytes)); |
179 Vector<WebBlobInfo> webBlobInfo; | 179 Vector<WebBlobInfo> webBlobInfo; |
180 WebIDBKey webIdbKey = WebIDBKey::createNumber(primaryKey); | 180 WebIDBKey webIdbKey = WebIDBKey::createNumber(primaryKey); |
181 WebIDBKeyPath webIdbKeyPath(keyPath); | 181 WebIDBKeyPath webIdbKeyPath(keyPath); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 384 |
385 v8::Local<v8::Value> v8Value = | 385 v8::Local<v8::Value> v8Value = |
386 deserializeIDBValue(isolate, scope.context()->Global(), idbValue.get()); | 386 deserializeIDBValue(isolate, scope.context()->Global(), idbValue.get()); |
387 EXPECT_TRUE(!scope.getExceptionState().hadException()); | 387 EXPECT_TRUE(!scope.getExceptionState().hadException()); |
388 ASSERT_TRUE(v8Value->IsNumber()); | 388 ASSERT_TRUE(v8Value->IsNumber()); |
389 v8::Local<v8::Number> v8Number = v8Value.As<v8::Number>(); | 389 v8::Local<v8::Number> v8Number = v8Value.As<v8::Number>(); |
390 EXPECT_EQ(v8Number->Value(), 42.0); | 390 EXPECT_EQ(v8Number->Value(), 42.0); |
391 } | 391 } |
392 | 392 |
393 } // namespace blink | 393 } // namespace blink |
OLD | NEW |