Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: Source/bindings/modules/v8/IDBBindingUtilities.cpp

Issue 660243003: v8::Handle should be replaced with v8::Local in Source/bindings/modules (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git/+/master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "modules/indexeddb/IDBTracing.h" 46 #include "modules/indexeddb/IDBTracing.h"
47 #include "platform/RuntimeEnabledFeatures.h" 47 #include "platform/RuntimeEnabledFeatures.h"
48 #include "platform/SharedBuffer.h" 48 #include "platform/SharedBuffer.h"
49 #include "wtf/ArrayBufferView.h" 49 #include "wtf/ArrayBufferView.h"
50 #include "wtf/MathExtras.h" 50 #include "wtf/MathExtras.h"
51 #include "wtf/Uint8Array.h" 51 #include "wtf/Uint8Array.h"
52 #include "wtf/Vector.h" 52 #include "wtf/Vector.h"
53 53
54 namespace blink { 54 namespace blink {
55 55
56 static v8::Handle<v8::Value> deserializeIDBValueBuffer(v8::Isolate*, SharedBuffe r*, const Vector<blink::WebBlobInfo>*); 56 static v8::Local<v8::Value> deserializeIDBValueBuffer(v8::Isolate*, SharedBuffer *, const Vector<blink::WebBlobInfo>*);
57 57
58 static v8::Handle<v8::Value> toV8(const IDBKeyPath& value, v8::Handle<v8::Object > creationContext, v8::Isolate* isolate) 58 static v8::Local<v8::Value> toV8(const IDBKeyPath& value, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
59 { 59 {
60 switch (value.type()) { 60 switch (value.type()) {
61 case IDBKeyPath::NullType: 61 case IDBKeyPath::NullType:
62 return v8::Null(isolate); 62 return v8::Null(isolate);
63 case IDBKeyPath::StringType: 63 case IDBKeyPath::StringType:
64 return v8String(isolate, value.string()); 64 return v8String(isolate, value.string());
65 case IDBKeyPath::ArrayType: 65 case IDBKeyPath::ArrayType:
66 RefPtrWillBeRawPtr<DOMStringList> keyPaths = DOMStringList::create(); 66 RefPtrWillBeRawPtr<DOMStringList> keyPaths = DOMStringList::create();
67 for (Vector<String>::const_iterator it = value.array().begin(); it != va lue.array().end(); ++it) 67 for (Vector<String>::const_iterator it = value.array().begin(); it != va lue.array().end(); ++it)
68 keyPaths->append(*it); 68 keyPaths->append(*it);
69 return toV8(keyPaths.release(), creationContext, isolate); 69 return toV8(keyPaths.release(), creationContext, isolate);
70 } 70 }
71 ASSERT_NOT_REACHED(); 71 ASSERT_NOT_REACHED();
72 return v8::Undefined(isolate); 72 return v8::Undefined(isolate);
73 } 73 }
74 74
75 static v8::Handle<v8::Value> toV8(const IDBKey* key, v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate) 75 static v8::Local<v8::Value> toV8(const IDBKey* key, v8::Local<v8::Object> creati onContext, v8::Isolate* isolate)
76 { 76 {
77 if (!key) { 77 if (!key) {
78 // This should be undefined, not null. 78 // This should be undefined, not null.
79 // Spec: http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl- def-IDBKeyRange 79 // Spec: http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl- def-IDBKeyRange
80 return v8Undefined(); 80 return v8Undefined();
81 } 81 }
82 82
83 switch (key->type()) { 83 switch (key->type()) {
84 case IDBKey::InvalidType: 84 case IDBKey::InvalidType:
85 case IDBKey::MinType: 85 case IDBKey::MinType:
(...skipping 13 matching lines...) Expand all
99 for (size_t i = 0; i < key->array().size(); ++i) 99 for (size_t i = 0; i < key->array().size(); ++i)
100 array->Set(i, toV8(key->array()[i].get(), creationContext, isola te)); 100 array->Set(i, toV8(key->array()[i].get(), creationContext, isola te));
101 return array; 101 return array;
102 } 102 }
103 } 103 }
104 104
105 ASSERT_NOT_REACHED(); 105 ASSERT_NOT_REACHED();
106 return v8Undefined(); 106 return v8Undefined();
107 } 107 }
108 108
109 static v8::Handle<v8::Value> toV8(const IDBAny* impl, v8::Handle<v8::Object> cre ationContext, v8::Isolate* isolate) 109 static v8::Local<v8::Value> toV8(const IDBAny* impl, v8::Local<v8::Object> creat ionContext, v8::Isolate* isolate)
110 { 110 {
111 if (!impl) 111 if (!impl)
112 return v8::Null(isolate); 112 return v8::Null(isolate);
113 113
114 switch (impl->type()) { 114 switch (impl->type()) {
115 case IDBAny::UndefinedType: 115 case IDBAny::UndefinedType:
116 return v8::Undefined(isolate); 116 return v8::Undefined(isolate);
117 case IDBAny::NullType: 117 case IDBAny::NullType:
118 return v8::Null(isolate); 118 return v8::Null(isolate);
119 case IDBAny::DOMStringListType: 119 case IDBAny::DOMStringListType:
120 return toV8(impl->domStringList(), creationContext, isolate); 120 return toV8(impl->domStringList(), creationContext, isolate);
121 case IDBAny::IDBCursorType: { 121 case IDBAny::IDBCursorType: {
122 // Ensure request wrapper is kept alive at least as long as the cursor w rapper, 122 // Ensure request wrapper is kept alive at least as long as the cursor w rapper,
123 // so that event listeners are retained. 123 // so that event listeners are retained.
124 v8::Handle<v8::Value> cursor = toV8(impl->idbCursor(), creationContext, isolate); 124 v8::Local<v8::Value> cursor = toV8(impl->idbCursor(), creationContext, i solate);
125 v8::Handle<v8::Value> request = toV8(impl->idbCursor()->request(), creat ionContext, isolate); 125 v8::Local<v8::Value> request = toV8(impl->idbCursor()->request(), creati onContext, isolate);
126 126
127 // FIXME: Due to race at worker shutdown, V8 may return empty handles. 127 // FIXME: Due to race at worker shutdown, V8 may return empty handles.
128 if (!cursor.IsEmpty()) 128 if (!cursor.IsEmpty())
129 V8HiddenValue::setHiddenValue(isolate, cursor->ToObject(), V8HiddenV alue::idbCursorRequest(isolate), request); 129 V8HiddenValue::setHiddenValue(isolate, cursor->ToObject(), V8HiddenV alue::idbCursorRequest(isolate), request);
130 return cursor; 130 return cursor;
131 } 131 }
132 case IDBAny::IDBCursorWithValueType: { 132 case IDBAny::IDBCursorWithValueType: {
133 // Ensure request wrapper is kept alive at least as long as the cursor w rapper, 133 // Ensure request wrapper is kept alive at least as long as the cursor w rapper,
134 // so that event listeners are retained. 134 // so that event listeners are retained.
135 v8::Handle<v8::Value> cursor = toV8(impl->idbCursorWithValue(), creation Context, isolate); 135 v8::Local<v8::Value> cursor = toV8(impl->idbCursorWithValue(), creationC ontext, isolate);
136 v8::Handle<v8::Value> request = toV8(impl->idbCursorWithValue()->request (), creationContext, isolate); 136 v8::Local<v8::Value> request = toV8(impl->idbCursorWithValue()->request( ), creationContext, isolate);
137 137
138 // FIXME: Due to race at worker shutdown, V8 may return empty handles. 138 // FIXME: Due to race at worker shutdown, V8 may return empty handles.
139 if (!cursor.IsEmpty()) 139 if (!cursor.IsEmpty())
140 V8HiddenValue::setHiddenValue(isolate, cursor->ToObject(), V8HiddenV alue::idbCursorRequest(isolate), request); 140 V8HiddenValue::setHiddenValue(isolate, cursor->ToObject(), V8HiddenV alue::idbCursorRequest(isolate), request);
141 return cursor; 141 return cursor;
142 } 142 }
143 case IDBAny::IDBDatabaseType: 143 case IDBAny::IDBDatabaseType:
144 return toV8(impl->idbDatabase(), creationContext, isolate); 144 return toV8(impl->idbDatabase(), creationContext, isolate);
145 case IDBAny::IDBIndexType: 145 case IDBAny::IDBIndexType:
146 return toV8(impl->idbIndex(), creationContext, isolate); 146 return toV8(impl->idbIndex(), creationContext, isolate);
147 case IDBAny::IDBObjectStoreType: 147 case IDBAny::IDBObjectStoreType:
148 return toV8(impl->idbObjectStore(), creationContext, isolate); 148 return toV8(impl->idbObjectStore(), creationContext, isolate);
149 case IDBAny::IDBTransactionType: 149 case IDBAny::IDBTransactionType:
150 return toV8(impl->idbTransaction(), creationContext, isolate); 150 return toV8(impl->idbTransaction(), creationContext, isolate);
151 case IDBAny::BufferType: 151 case IDBAny::BufferType:
152 return deserializeIDBValueBuffer(isolate, impl->buffer(), impl->blobInfo ()); 152 return deserializeIDBValueBuffer(isolate, impl->buffer(), impl->blobInfo ());
153 case IDBAny::StringType: 153 case IDBAny::StringType:
154 return v8String(isolate, impl->string()); 154 return v8String(isolate, impl->string());
155 case IDBAny::IntegerType: 155 case IDBAny::IntegerType:
156 return v8::Number::New(isolate, impl->integer()); 156 return v8::Number::New(isolate, impl->integer());
157 case IDBAny::KeyType: 157 case IDBAny::KeyType:
158 return toV8(impl->key(), creationContext, isolate); 158 return toV8(impl->key(), creationContext, isolate);
159 case IDBAny::KeyPathType: 159 case IDBAny::KeyPathType:
160 return toV8(impl->keyPath(), creationContext, isolate); 160 return toV8(impl->keyPath(), creationContext, isolate);
161 case IDBAny::BufferKeyAndKeyPathType: { 161 case IDBAny::BufferKeyAndKeyPathType: {
162 v8::Handle<v8::Value> value = deserializeIDBValueBuffer(isolate, impl->b uffer(), impl->blobInfo()); 162 v8::Local<v8::Value> value = deserializeIDBValueBuffer(isolate, impl->bu ffer(), impl->blobInfo());
163 v8::Handle<v8::Value> key = toV8(impl->key(), creationContext, isolate); 163 v8::Local<v8::Value> key = toV8(impl->key(), creationContext, isolate);
164 bool injected = injectV8KeyIntoV8Value(isolate, key, value, impl->keyPat h()); 164 bool injected = injectV8KeyIntoV8Value(isolate, key, value, impl->keyPat h());
165 ASSERT_UNUSED(injected, injected); 165 ASSERT_UNUSED(injected, injected);
166 return value; 166 return value;
167 } 167 }
168 } 168 }
169 169
170 ASSERT_NOT_REACHED(); 170 ASSERT_NOT_REACHED();
171 return v8::Undefined(isolate); 171 return v8::Undefined(isolate);
172 } 172 }
173 173
174 static const size_t maximumDepth = 2000; 174 static const size_t maximumDepth = 2000;
175 175
176 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Handle<v8::Value> value, Vector<v8::Handle<v8::Array> >& stack, bool allowExperimentalTypes = fal se) 176 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Local<v8::Value> value, Vector<v8::Local<v8::Array> >& stack, bool allowExperimentalTypes = false )
177 { 177 {
178 if (value->IsNumber() && !std::isnan(value->NumberValue())) 178 if (value->IsNumber() && !std::isnan(value->NumberValue()))
179 return IDBKey::createNumber(value->NumberValue()); 179 return IDBKey::createNumber(value->NumberValue());
180 if (value->IsString()) 180 if (value->IsString())
181 return IDBKey::createString(toCoreString(value.As<v8::String>())); 181 return IDBKey::createString(toCoreString(value.As<v8::String>()));
182 if (value->IsDate() && !std::isnan(value->NumberValue())) 182 if (value->IsDate() && !std::isnan(value->NumberValue()))
183 return IDBKey::createDate(value->NumberValue()); 183 return IDBKey::createDate(value->NumberValue());
184 if (value->IsUint8Array() && (allowExperimentalTypes || RuntimeEnabledFeatur es::indexedDBExperimentalEnabled())) { 184 if (value->IsUint8Array() && (allowExperimentalTypes || RuntimeEnabledFeatur es::indexedDBExperimentalEnabled())) {
185 // Per discussion in https://www.w3.org/Bugs/Public/show_bug.cgi?id=2333 2 the 185 // Per discussion in https://www.w3.org/Bugs/Public/show_bug.cgi?id=2333 2 the
186 // input type is constrained to Uint8Array to match the output type. 186 // input type is constrained to Uint8Array to match the output type.
187 ArrayBufferView* view = blink::V8ArrayBufferView::toImpl(value->ToObject ()); 187 ArrayBufferView* view = blink::V8ArrayBufferView::toImpl(value->ToObject ());
188 const char* start = static_cast<const char*>(view->baseAddress()); 188 const char* start = static_cast<const char*>(view->baseAddress());
189 size_t length = view->byteLength(); 189 size_t length = view->byteLength();
190 return IDBKey::createBinary(SharedBuffer::create(start, length)); 190 return IDBKey::createBinary(SharedBuffer::create(start, length));
191 } 191 }
192 if (value->IsArray()) { 192 if (value->IsArray()) {
193 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value); 193 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value);
194 194
195 if (stack.contains(array)) 195 if (stack.contains(array))
196 return 0; 196 return 0;
197 if (stack.size() >= maximumDepth) 197 if (stack.size() >= maximumDepth)
198 return 0; 198 return 0;
199 stack.append(array); 199 stack.append(array);
200 200
201 IDBKey::KeyArray subkeys; 201 IDBKey::KeyArray subkeys;
202 uint32_t length = array->Length(); 202 uint32_t length = array->Length();
203 for (uint32_t i = 0; i < length; ++i) { 203 for (uint32_t i = 0; i < length; ++i) {
204 v8::Local<v8::Value> item = array->Get(v8::Int32::New(isolate, i)); 204 v8::Local<v8::Value> item = array->Get(v8::Int32::New(isolate, i));
205 IDBKey* subkey = createIDBKeyFromValue(isolate, item, stack, allowEx perimentalTypes); 205 IDBKey* subkey = createIDBKeyFromValue(isolate, item, stack, allowEx perimentalTypes);
206 if (!subkey) 206 if (!subkey)
207 subkeys.append(IDBKey::createInvalid()); 207 subkeys.append(IDBKey::createInvalid());
208 else 208 else
209 subkeys.append(subkey); 209 subkeys.append(subkey);
210 } 210 }
211 211
212 stack.removeLast(); 212 stack.removeLast();
213 return IDBKey::createArray(subkeys); 213 return IDBKey::createArray(subkeys);
214 } 214 }
215 return 0; 215 return 0;
216 } 216 }
217 217
218 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Handle<v8::Value> value, bool allowExperimentalTypes = false) 218 static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Local<v8::Value> value, bool allowExperimentalTypes = false)
219 { 219 {
220 Vector<v8::Handle<v8::Array> > stack; 220 Vector<v8::Local<v8::Array> > stack;
221 if (IDBKey* key = createIDBKeyFromValue(isolate, value, stack, allowExperime ntalTypes)) 221 if (IDBKey* key = createIDBKeyFromValue(isolate, value, stack, allowExperime ntalTypes))
222 return key; 222 return key;
223 return IDBKey::createInvalid(); 223 return IDBKey::createInvalid();
224 } 224 }
225 225
226 template<typename T> 226 template<typename T>
227 static bool getValueFrom(T indexOrName, v8::Handle<v8::Value>& v8Value) 227 static bool getValueFrom(T indexOrName, v8::Local<v8::Value>& v8Value)
228 { 228 {
229 v8::Local<v8::Object> object = v8Value->ToObject(); 229 v8::Local<v8::Object> object = v8Value->ToObject();
230 if (!object->Has(indexOrName)) 230 if (!object->Has(indexOrName))
231 return false; 231 return false;
232 v8Value = object->Get(indexOrName); 232 v8Value = object->Get(indexOrName);
233 return true; 233 return true;
234 } 234 }
235 235
236 template<typename T> 236 template<typename T>
237 static bool setValue(v8::Handle<v8::Value>& v8Object, T indexOrName, const v8::H andle<v8::Value>& v8Value) 237 static bool setValue(v8::Local<v8::Value>& v8Object, T indexOrName, const v8::Lo cal<v8::Value>& v8Value)
238 { 238 {
239 v8::Local<v8::Object> object = v8Object->ToObject(); 239 v8::Local<v8::Object> object = v8Object->ToObject();
240 return object->Set(indexOrName, v8Value); 240 return object->Set(indexOrName, v8Value);
241 } 241 }
242 242
243 static bool get(v8::Isolate* isolate, v8::Handle<v8::Value>& object, const Strin g& keyPathElement, v8::Handle<v8::Value>& result) 243 static bool get(v8::Isolate* isolate, v8::Local<v8::Value>& object, const String & keyPathElement, v8::Local<v8::Value>& result)
244 { 244 {
245 if (object->IsString() && keyPathElement == "length") { 245 if (object->IsString() && keyPathElement == "length") {
246 int32_t length = v8::Handle<v8::String>::Cast(object)->Length(); 246 int32_t length = v8::Local<v8::String>::Cast(object)->Length();
247 result = v8::Number::New(isolate, length); 247 result = v8::Number::New(isolate, length);
248 return true; 248 return true;
249 } 249 }
250 return object->IsObject() && getValueFrom(v8String(isolate, keyPathElement), result); 250 return object->IsObject() && getValueFrom(v8String(isolate, keyPathElement), result);
251 } 251 }
252 252
253 static bool canSet(v8::Handle<v8::Value>& object, const String& keyPathElement) 253 static bool canSet(v8::Local<v8::Value>& object, const String& keyPathElement)
254 { 254 {
255 return object->IsObject(); 255 return object->IsObject();
256 } 256 }
257 257
258 static bool set(v8::Isolate* isolate, v8::Handle<v8::Value>& object, const Strin g& keyPathElement, const v8::Handle<v8::Value>& v8Value) 258 static bool set(v8::Isolate* isolate, v8::Local<v8::Value>& object, const String & keyPathElement, const v8::Local<v8::Value>& v8Value)
259 { 259 {
260 return canSet(object, keyPathElement) && setValue(object, v8String(isolate, keyPathElement), v8Value); 260 return canSet(object, keyPathElement) && setValue(object, v8String(isolate, keyPathElement), v8Value);
261 } 261 }
262 262
263 static v8::Handle<v8::Value> getNthValueOnKeyPath(v8::Isolate* isolate, v8::Hand le<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index) 263 static v8::Local<v8::Value> getNthValueOnKeyPath(v8::Isolate* isolate, v8::Local <v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index)
264 { 264 {
265 v8::Handle<v8::Value> currentValue(rootValue); 265 v8::Local<v8::Value> currentValue(rootValue);
266 ASSERT(index <= keyPathElements.size()); 266 ASSERT(index <= keyPathElements.size());
267 for (size_t i = 0; i < index; ++i) { 267 for (size_t i = 0; i < index; ++i) {
268 v8::Handle<v8::Value> parentValue(currentValue); 268 v8::Local<v8::Value> parentValue(currentValue);
269 if (!get(isolate, parentValue, keyPathElements[i], currentValue)) 269 if (!get(isolate, parentValue, keyPathElements[i], currentValue))
270 return v8Undefined(); 270 return v8Undefined();
271 } 271 }
272 272
273 return currentValue; 273 return currentValue;
274 } 274 }
275 275
276 static bool canInjectNthValueOnKeyPath(v8::Isolate* isolate, v8::Handle<v8::Valu e>& rootValue, const Vector<String>& keyPathElements, size_t index) 276 static bool canInjectNthValueOnKeyPath(v8::Isolate* isolate, v8::Local<v8::Value >& rootValue, const Vector<String>& keyPathElements, size_t index)
277 { 277 {
278 if (!rootValue->IsObject()) 278 if (!rootValue->IsObject())
279 return false; 279 return false;
280 280
281 v8::Handle<v8::Value> currentValue(rootValue); 281 v8::Local<v8::Value> currentValue(rootValue);
282 282
283 ASSERT(index <= keyPathElements.size()); 283 ASSERT(index <= keyPathElements.size());
284 for (size_t i = 0; i < index; ++i) { 284 for (size_t i = 0; i < index; ++i) {
285 v8::Handle<v8::Value> parentValue(currentValue); 285 v8::Local<v8::Value> parentValue(currentValue);
286 const String& keyPathElement = keyPathElements[i]; 286 const String& keyPathElement = keyPathElements[i];
287 if (!get(isolate, parentValue, keyPathElement, currentValue)) 287 if (!get(isolate, parentValue, keyPathElement, currentValue))
288 return canSet(parentValue, keyPathElement); 288 return canSet(parentValue, keyPathElement);
289 } 289 }
290 return true; 290 return true;
291 } 291 }
292 292
293 293
294 static v8::Handle<v8::Value> ensureNthValueOnKeyPath(v8::Isolate* isolate, v8::H andle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index ) 294 static v8::Local<v8::Value> ensureNthValueOnKeyPath(v8::Isolate* isolate, v8::Lo cal<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index)
295 { 295 {
296 v8::Handle<v8::Value> currentValue(rootValue); 296 v8::Local<v8::Value> currentValue(rootValue);
297 297
298 ASSERT(index <= keyPathElements.size()); 298 ASSERT(index <= keyPathElements.size());
299 for (size_t i = 0; i < index; ++i) { 299 for (size_t i = 0; i < index; ++i) {
300 v8::Handle<v8::Value> parentValue(currentValue); 300 v8::Local<v8::Value> parentValue(currentValue);
301 const String& keyPathElement = keyPathElements[i]; 301 const String& keyPathElement = keyPathElements[i];
302 if (!get(isolate, parentValue, keyPathElement, currentValue)) { 302 if (!get(isolate, parentValue, keyPathElement, currentValue)) {
303 v8::Handle<v8::Object> object = v8::Object::New(isolate); 303 v8::Local<v8::Object> object = v8::Object::New(isolate);
304 if (!set(isolate, parentValue, keyPathElement, object)) 304 if (!set(isolate, parentValue, keyPathElement, object))
305 return v8Undefined(); 305 return v8Undefined();
306 currentValue = object; 306 currentValue = object;
307 } 307 }
308 } 308 }
309 309
310 return currentValue; 310 return currentValue;
311 } 311 }
312 312
313 static IDBKey* createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolat e, const ScriptValue& value, const String& keyPath, bool allowExperimentalTypes) 313 static IDBKey* createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolat e, const ScriptValue& value, const String& keyPath, bool allowExperimentalTypes)
314 { 314 {
315 Vector<String> keyPathElements; 315 Vector<String> keyPathElements;
316 IDBKeyPathParseError error; 316 IDBKeyPathParseError error;
317 IDBParseKeyPath(keyPath, keyPathElements, error); 317 IDBParseKeyPath(keyPath, keyPathElements, error);
318 ASSERT(error == IDBKeyPathParseErrorNone); 318 ASSERT(error == IDBKeyPathParseErrorNone);
319 ASSERT(isolate->InContext()); 319 ASSERT(isolate->InContext());
320 320
321 v8::HandleScope handleScope(isolate); 321 v8::HandleScope handleScope(isolate);
322 v8::Handle<v8::Value> v8Value(value.v8Value()); 322 v8::Local<v8::Value> v8Value(value.v8Value());
323 v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(isolate, v8Value, keyPathEl ements, keyPathElements.size())); 323 v8::Local<v8::Value> v8Key(getNthValueOnKeyPath(isolate, v8Value, keyPathEle ments, keyPathElements.size()));
324 if (v8Key.IsEmpty()) 324 if (v8Key.IsEmpty())
325 return 0; 325 return 0;
326 return createIDBKeyFromValue(isolate, v8Key, allowExperimentalTypes); 326 return createIDBKeyFromValue(isolate, v8Key, allowExperimentalTypes);
327 } 327 }
328 328
329 static IDBKey* createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolat e, const ScriptValue& value, const IDBKeyPath& keyPath, bool allowExperimentalTy pes = false) 329 static IDBKey* createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolat e, const ScriptValue& value, const IDBKeyPath& keyPath, bool allowExperimentalTy pes = false)
330 { 330 {
331 ASSERT(!keyPath.isNull()); 331 ASSERT(!keyPath.isNull());
332 v8::HandleScope handleScope(isolate); 332 v8::HandleScope handleScope(isolate);
333 if (keyPath.type() == IDBKeyPath::ArrayType) { 333 if (keyPath.type() == IDBKeyPath::ArrayType) {
(...skipping 11 matching lines...) Expand all
345 ASSERT(keyPath.type() == IDBKeyPath::StringType); 345 ASSERT(keyPath.type() == IDBKeyPath::StringType);
346 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath .string(), allowExperimentalTypes); 346 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath .string(), allowExperimentalTypes);
347 } 347 }
348 348
349 IDBKey* createIDBKeyFromScriptValueAndKeyPath(v8::Isolate* isolate, const Script Value& value, const IDBKeyPath& keyPath) 349 IDBKey* createIDBKeyFromScriptValueAndKeyPath(v8::Isolate* isolate, const Script Value& value, const IDBKeyPath& keyPath)
350 { 350 {
351 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath"); 351 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath");
352 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath ); 352 return createIDBKeyFromScriptValueAndKeyPathInternal(isolate, value, keyPath );
353 } 353 }
354 354
355 static v8::Handle<v8::Value> deserializeIDBValueBuffer(v8::Isolate* isolate, Sha redBuffer* buffer, const Vector<blink::WebBlobInfo>* blobInfo) 355 static v8::Local<v8::Value> deserializeIDBValueBuffer(v8::Isolate* isolate, Shar edBuffer* buffer, const Vector<blink::WebBlobInfo>* blobInfo)
356 { 356 {
357 ASSERT(isolate->InContext()); 357 ASSERT(isolate->InContext());
358 if (!buffer) 358 if (!buffer)
359 return v8::Null(isolate); 359 return v8::Null(isolate);
360 360
361 // FIXME: The extra copy here can be eliminated by allowing SerializedScript Value to take a raw const char* or const uint8_t*. 361 // FIXME: The extra copy here can be eliminated by allowing SerializedScript Value to take a raw const char* or const uint8_t*.
362 Vector<uint8_t> value; 362 Vector<uint8_t> value;
363 value.append(buffer->data(), buffer->size()); 363 value.append(buffer->data(), buffer->size());
364 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat eFromWireBytes(value); 364 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat eFromWireBytes(value);
365 return serializedValue->deserialize(isolate, 0, blobInfo); 365 return serializedValue->deserialize(isolate, 0, blobInfo);
366 } 366 }
367 367
368 bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Handle<v8::Value> key, v8: :Handle<v8::Value> value, const IDBKeyPath& keyPath) 368 bool injectV8KeyIntoV8Value(v8::Isolate* isolate, v8::Local<v8::Value> key, v8:: Local<v8::Value> value, const IDBKeyPath& keyPath)
369 { 369 {
370 IDB_TRACE("injectIDBV8KeyIntoV8Value"); 370 IDB_TRACE("injectIDBV8KeyIntoV8Value");
371 ASSERT(isolate->InContext()); 371 ASSERT(isolate->InContext());
372 372
373 ASSERT(keyPath.type() == IDBKeyPath::StringType); 373 ASSERT(keyPath.type() == IDBKeyPath::StringType);
374 Vector<String> keyPathElements; 374 Vector<String> keyPathElements;
375 IDBKeyPathParseError error; 375 IDBKeyPathParseError error;
376 IDBParseKeyPath(keyPath.string(), keyPathElements, error); 376 IDBParseKeyPath(keyPath.string(), keyPathElements, error);
377 ASSERT(error == IDBKeyPathParseErrorNone); 377 ASSERT(error == IDBKeyPathParseErrorNone);
378 378
379 if (!keyPathElements.size()) 379 if (!keyPathElements.size())
380 return false; 380 return false;
381 381
382 v8::HandleScope handleScope(isolate); 382 v8::HandleScope handleScope(isolate);
383 v8::Handle<v8::Value> parent(ensureNthValueOnKeyPath(isolate, value, keyPath Elements, keyPathElements.size() - 1)); 383 v8::Local<v8::Value> parent(ensureNthValueOnKeyPath(isolate, value, keyPathE lements, keyPathElements.size() - 1));
384 if (parent.IsEmpty()) 384 if (parent.IsEmpty())
385 return false; 385 return false;
386 386
387 if (!set(isolate, parent, keyPathElements.last(), key)) 387 if (!set(isolate, parent, keyPathElements.last(), key))
388 return false; 388 return false;
389 389
390 return true; 390 return true;
391 } 391 }
392 392
393 bool canInjectIDBKeyIntoScriptValue(v8::Isolate* isolate, const ScriptValue& scr iptValue, const IDBKeyPath& keyPath) 393 bool canInjectIDBKeyIntoScriptValue(v8::Isolate* isolate, const ScriptValue& scr iptValue, const IDBKeyPath& keyPath)
394 { 394 {
395 IDB_TRACE("canInjectIDBKeyIntoScriptValue"); 395 IDB_TRACE("canInjectIDBKeyIntoScriptValue");
396 ASSERT(keyPath.type() == IDBKeyPath::StringType); 396 ASSERT(keyPath.type() == IDBKeyPath::StringType);
397 Vector<String> keyPathElements; 397 Vector<String> keyPathElements;
398 IDBKeyPathParseError error; 398 IDBKeyPathParseError error;
399 IDBParseKeyPath(keyPath.string(), keyPathElements, error); 399 IDBParseKeyPath(keyPath.string(), keyPathElements, error);
400 ASSERT(error == IDBKeyPathParseErrorNone); 400 ASSERT(error == IDBKeyPathParseErrorNone);
401 401
402 if (!keyPathElements.size()) 402 if (!keyPathElements.size())
403 return false; 403 return false;
404 404
405 v8::Handle<v8::Value> v8Value(scriptValue.v8Value()); 405 v8::Local<v8::Value> v8Value(scriptValue.v8Value());
406 return canInjectNthValueOnKeyPath(isolate, v8Value, keyPathElements, keyPath Elements.size() - 1); 406 return canInjectNthValueOnKeyPath(isolate, v8Value, keyPathElements, keyPath Elements.size() - 1);
407 } 407 }
408 408
409 ScriptValue idbAnyToScriptValue(ScriptState* scriptState, IDBAny* any) 409 ScriptValue idbAnyToScriptValue(ScriptState* scriptState, IDBAny* any)
410 { 410 {
411 v8::Isolate* isolate = scriptState->isolate(); 411 v8::Isolate* isolate = scriptState->isolate();
412 v8::HandleScope handleScope(isolate); 412 v8::HandleScope handleScope(isolate);
413 v8::Handle<v8::Value> v8Value(toV8(any, scriptState->context()->Global(), is olate)); 413 v8::Local<v8::Value> v8Value(toV8(any, scriptState->context()->Global(), iso late));
414 return ScriptValue(scriptState, v8Value); 414 return ScriptValue(scriptState, v8Value);
415 } 415 }
416 416
417 ScriptValue idbKeyToScriptValue(ScriptState* scriptState, IDBKey* key) 417 ScriptValue idbKeyToScriptValue(ScriptState* scriptState, IDBKey* key)
418 { 418 {
419 v8::Isolate* isolate = scriptState->isolate(); 419 v8::Isolate* isolate = scriptState->isolate();
420 v8::HandleScope handleScope(isolate); 420 v8::HandleScope handleScope(isolate);
421 v8::Handle<v8::Value> v8Value(toV8(key, scriptState->context()->Global(), is olate)); 421 v8::Local<v8::Value> v8Value(toV8(key, scriptState->context()->Global(), iso late));
422 return ScriptValue(scriptState, v8Value); 422 return ScriptValue(scriptState, v8Value);
423 } 423 }
424 424
425 IDBKey* scriptValueToIDBKey(v8::Isolate* isolate, const ScriptValue& scriptValue ) 425 IDBKey* scriptValueToIDBKey(v8::Isolate* isolate, const ScriptValue& scriptValue )
426 { 426 {
427 ASSERT(isolate->InContext()); 427 ASSERT(isolate->InContext());
428 v8::HandleScope handleScope(isolate); 428 v8::HandleScope handleScope(isolate);
429 v8::Handle<v8::Value> v8Value(scriptValue.v8Value()); 429 v8::Local<v8::Value> v8Value(scriptValue.v8Value());
430 return createIDBKeyFromValue(isolate, v8Value); 430 return createIDBKeyFromValue(isolate, v8Value);
431 } 431 }
432 432
433 IDBKeyRange* scriptValueToIDBKeyRange(v8::Isolate* isolate, const ScriptValue& s criptValue) 433 IDBKeyRange* scriptValueToIDBKeyRange(v8::Isolate* isolate, const ScriptValue& s criptValue)
434 { 434 {
435 v8::HandleScope handleScope(isolate); 435 v8::HandleScope handleScope(isolate);
436 v8::Handle<v8::Value> value(scriptValue.v8Value()); 436 v8::Local<v8::Value> value(scriptValue.v8Value());
437 return V8IDBKeyRange::toImplWithTypeCheck(isolate, value); 437 return V8IDBKeyRange::toImplWithTypeCheck(isolate, value);
438 } 438 }
439 439
440 ScriptValue deserializeScriptValue(ScriptState* scriptState, SerializedScriptVal ue* serializedValue, const Vector<blink::WebBlobInfo>* blobInfo) 440 ScriptValue deserializeScriptValue(ScriptState* scriptState, SerializedScriptVal ue* serializedValue, const Vector<blink::WebBlobInfo>* blobInfo)
441 { 441 {
442 v8::Isolate* isolate = scriptState->isolate(); 442 v8::Isolate* isolate = scriptState->isolate();
443 v8::HandleScope handleScope(isolate); 443 v8::HandleScope handleScope(isolate);
444 if (serializedValue) 444 if (serializedValue)
445 return ScriptValue(scriptState, serializedValue->deserialize(isolate, 0, blobInfo)); 445 return ScriptValue(scriptState, serializedValue->deserialize(isolate, 0, blobInfo));
446 return ScriptValue(scriptState, v8::Null(isolate)); 446 return ScriptValue(scriptState, v8::Null(isolate));
(...skipping 11 matching lines...) Expand all
458 const bool allowExperimentalTypes = true; 458 const bool allowExperimentalTypes = true;
459 IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate, scriptValue, keyPath, allowExperimentalTypes); 459 IDBKey* expectedKey = createIDBKeyFromScriptValueAndKeyPathInternal(isolate, scriptValue, keyPath, allowExperimentalTypes);
460 ASSERT(!expectedKey || expectedKey->isEqual(key)); 460 ASSERT(!expectedKey || expectedKey->isEqual(key));
461 461
462 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), keyPath); 462 bool injected = injectV8KeyIntoV8Value(isolate, keyValue.v8Value(), scriptVa lue.v8Value(), keyPath);
463 ASSERT_UNUSED(injected, injected); 463 ASSERT_UNUSED(injected, injected);
464 } 464 }
465 #endif 465 #endif
466 466
467 } // namespace blink 467 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/modules/v8/IDBBindingUtilities.h ('k') | Source/bindings/modules/v8/custom/V8CryptoCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698