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

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

Issue 11337028: Merge 132922 - Remove ensureAuxiliaryContext (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1312/
Patch Set: Created 8 years, 1 month 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 return currentValue; 173 return currentValue;
174 } 174 }
175 175
176 static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValu e& value, const String& keyPath) 176 static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValu e& value, const String& keyPath)
177 { 177 {
178 Vector<String> keyPathElements; 178 Vector<String> keyPathElements;
179 IDBKeyPathParseError error; 179 IDBKeyPathParseError error;
180 IDBParseKeyPath(keyPath, keyPathElements, error); 180 IDBParseKeyPath(keyPath, keyPathElements, error);
181 ASSERT(error == IDBKeyPathParseErrorNone); 181 ASSERT(error == IDBKeyPathParseErrorNone);
182 ASSERT(v8::Context::InContext());
182 183
183 v8::HandleScope handleScope; 184 v8::HandleScope handleScope;
184 v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext ());
185
186 v8::Handle<v8::Value> v8Value(value.v8Value()); 185 v8::Handle<v8::Value> v8Value(value.v8Value());
187 v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, k eyPathElements.size())); 186 v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, k eyPathElements.size()));
188 if (v8Key.IsEmpty()) 187 if (v8Key.IsEmpty())
189 return 0; 188 return 0;
190 return createIDBKeyFromValue(v8Key); 189 return createIDBKeyFromValue(v8Key);
191 } 190 }
192 191
193 PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValue& valu e, const IDBKeyPath& keyPath) 192 PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValue& valu e, const IDBKeyPath& keyPath)
194 { 193 {
195 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath"); 194 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath");
196 ASSERT(!keyPath.isNull()); 195 ASSERT(!keyPath.isNull());
196 ASSERT(v8::Context::InContext());
197 197
198 v8::HandleScope scope; 198
199 v8::HandleScope handleScope;
199 if (keyPath.type() == IDBKeyPath::ArrayType) { 200 if (keyPath.type() == IDBKeyPath::ArrayType) {
200 IDBKey::KeyArray result; 201 IDBKey::KeyArray result;
201 const Vector<String>& array = keyPath.array(); 202 const Vector<String>& array = keyPath.array();
202 for (size_t i = 0; i < array.size(); ++i) { 203 for (size_t i = 0; i < array.size(); ++i) {
203 RefPtr<IDBKey> key = createIDBKeyFromScriptValueAndKeyPath(value, ar ray[i]); 204 RefPtr<IDBKey> key = createIDBKeyFromScriptValueAndKeyPath(value, ar ray[i]);
204 if (!key) 205 if (!key)
205 return 0; 206 return 0;
206 result.append(key); 207 result.append(key);
207 } 208 }
208 return IDBKey::createArray(result); 209 return IDBKey::createArray(result);
209 } 210 }
210 211
211 ASSERT(keyPath.type() == IDBKeyPath::StringType); 212 ASSERT(keyPath.type() == IDBKeyPath::StringType);
212 return createIDBKeyFromScriptValueAndKeyPath(value, keyPath.string()); 213 return createIDBKeyFromScriptValueAndKeyPath(value, keyPath.string());
213 } 214 }
214 215
215 // FIXME: The only reason this exists is because we need a v8::Context and scope inside a timer. Is there a better / more general way to do this?
216 ScriptValue deserializeIDBValue(ScriptExecutionContext* scriptContext, PassRefPt r<SerializedScriptValue> prpValue) 216 ScriptValue deserializeIDBValue(ScriptExecutionContext* scriptContext, PassRefPt r<SerializedScriptValue> prpValue)
217 { 217 {
218 ASSERT(v8::Context::InContext());
218 v8::HandleScope handleScope; 219 v8::HandleScope handleScope;
219 v8::Context::Scope contextScope(toV8Context(scriptContext, UseCurrentWorld)) ;
220 RefPtr<SerializedScriptValue> serializedValue = prpValue; 220 RefPtr<SerializedScriptValue> serializedValue = prpValue;
221 if (serializedValue) 221 if (serializedValue)
222 return ScriptValue(serializedValue->deserialize()); 222 return ScriptValue(serializedValue->deserialize());
223 return ScriptValue(v8::Null()); 223 return ScriptValue(v8::Null());
224 } 224 }
225 225
226 bool injectIDBKeyIntoScriptValue(PassRefPtr<IDBKey> key, ScriptValue& value, con st IDBKeyPath& keyPath) 226 bool injectIDBKeyIntoScriptValue(PassRefPtr<IDBKey> key, ScriptValue& value, con st IDBKeyPath& keyPath)
227 { 227 {
228 IDB_TRACE("injectIDBKeyIntoScriptValue"); 228 IDB_TRACE("injectIDBKeyIntoScriptValue");
229 ASSERT(v8::Context::InContext());
229 230
230 ASSERT(keyPath.type() == IDBKeyPath::StringType); 231 ASSERT(keyPath.type() == IDBKeyPath::StringType);
231 Vector<String> keyPathElements; 232 Vector<String> keyPathElements;
232 IDBKeyPathParseError error; 233 IDBKeyPathParseError error;
233 IDBParseKeyPath(keyPath.string(), keyPathElements, error); 234 IDBParseKeyPath(keyPath.string(), keyPathElements, error);
234 ASSERT(error == IDBKeyPathParseErrorNone); 235 ASSERT(error == IDBKeyPathParseErrorNone);
235 236
236 if (!keyPathElements.size()) 237 if (!keyPathElements.size())
237 return 0; 238 return 0;
238 239
239 v8::HandleScope handleScope; 240 v8::HandleScope handleScope;
240 v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext ());
241
242 v8::Handle<v8::Value> v8Value(value.v8Value()); 241 v8::Handle<v8::Value> v8Value(value.v8Value());
243 v8::Handle<v8::Value> parent(ensureNthValueOnKeyPath(v8Value, keyPathElement s, keyPathElements.size() - 1)); 242 v8::Handle<v8::Value> parent(ensureNthValueOnKeyPath(v8Value, keyPathElement s, keyPathElements.size() - 1));
244 if (parent.IsEmpty()) 243 if (parent.IsEmpty())
245 return false; 244 return false;
246 245
247 if (!set(parent, keyPathElements.last(), toV8(key.get()))) 246 if (!set(parent, keyPathElements.last(), toV8(key.get())))
248 return false; 247 return false;
249 248
250 return true; 249 return true;
251 } 250 }
252 251
253 bool canInjectIDBKeyIntoScriptValue(const ScriptValue& scriptValue, const IDBKey Path& keyPath) 252 bool canInjectIDBKeyIntoScriptValue(const ScriptValue& scriptValue, const IDBKey Path& keyPath)
254 { 253 {
255 IDB_TRACE("canInjectIDBKeyIntoScriptValue"); 254 IDB_TRACE("canInjectIDBKeyIntoScriptValue");
256 ASSERT(keyPath.type() == IDBKeyPath::StringType); 255 ASSERT(keyPath.type() == IDBKeyPath::StringType);
257 Vector<String> keyPathElements; 256 Vector<String> keyPathElements;
258 IDBKeyPathParseError error; 257 IDBKeyPathParseError error;
259 IDBParseKeyPath(keyPath.string(), keyPathElements, error); 258 IDBParseKeyPath(keyPath.string(), keyPathElements, error);
260 ASSERT(error == IDBKeyPathParseErrorNone); 259 ASSERT(error == IDBKeyPathParseErrorNone);
261 260
262 if (!keyPathElements.size()) 261 if (!keyPathElements.size())
263 return false; 262 return false;
264 263
265 v8::Handle<v8::Value> v8Value(scriptValue.v8Value()); 264 v8::Handle<v8::Value> v8Value(scriptValue.v8Value());
266 return canInjectNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements. size() - 1); 265 return canInjectNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements. size() - 1);
267 } 266 }
268 267
269 ScriptValue idbKeyToScriptValue(ScriptExecutionContext* scriptContext, PassRefPt r<IDBKey> key) 268 ScriptValue idbKeyToScriptValue(ScriptExecutionContext* scriptContext, PassRefPt r<IDBKey> key)
270 { 269 {
270 ASSERT(v8::Context::InContext());
271 v8::HandleScope handleScope; 271 v8::HandleScope handleScope;
272 v8::Context::Scope contextScope(toV8Context(scriptContext, UseCurrentWorld)) ;
273
274 v8::Handle<v8::Value> v8Value(toV8(key.get())); 272 v8::Handle<v8::Value> v8Value(toV8(key.get()));
275 return ScriptValue(v8Value); 273 return ScriptValue(v8Value);
276 } 274 }
277 275
278 } // namespace WebCore 276 } // namespace WebCore
279 277
280 #endif 278 #endif
OLDNEW
« no previous file with comments | « Source/WebCore/Modules/indexeddb/IDBRequest.cpp ('k') | Source/WebCore/bindings/v8/V8PerIsolateData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698