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

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

Issue 23961005: Pass isolate to v8 integers factory functions (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/Dictionary.cpp ('k') | Source/bindings/v8/ScriptDebugServer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return array; 67 return array;
68 } 68 }
69 } 69 }
70 70
71 ASSERT_NOT_REACHED(); 71 ASSERT_NOT_REACHED();
72 return v8Undefined(); 72 return v8Undefined();
73 } 73 }
74 74
75 static const size_t maximumDepth = 2000; 75 static const size_t maximumDepth = 2000;
76 76
77 static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value, Vec tor<v8::Handle<v8::Array> >& stack) 77 static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value, Vec tor<v8::Handle<v8::Array> >& stack, v8::Isolate* isolate)
78 { 78 {
79 if (value->IsNumber() && !std::isnan(value->NumberValue())) 79 if (value->IsNumber() && !std::isnan(value->NumberValue()))
80 return IDBKey::createNumber(value->NumberValue()); 80 return IDBKey::createNumber(value->NumberValue());
81 if (value->IsString()) 81 if (value->IsString())
82 return IDBKey::createString(toWebCoreString(value)); 82 return IDBKey::createString(toWebCoreString(value));
83 if (value->IsDate() && !std::isnan(value->NumberValue())) 83 if (value->IsDate() && !std::isnan(value->NumberValue()))
84 return IDBKey::createDate(value->NumberValue()); 84 return IDBKey::createDate(value->NumberValue());
85 if (value->IsArray()) { 85 if (value->IsArray()) {
86 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value); 86 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value);
87 87
88 if (stack.contains(array)) 88 if (stack.contains(array))
89 return 0; 89 return 0;
90 if (stack.size() >= maximumDepth) 90 if (stack.size() >= maximumDepth)
91 return 0; 91 return 0;
92 stack.append(array); 92 stack.append(array);
93 93
94 IDBKey::KeyArray subkeys; 94 IDBKey::KeyArray subkeys;
95 uint32_t length = array->Length(); 95 uint32_t length = array->Length();
96 for (uint32_t i = 0; i < length; ++i) { 96 for (uint32_t i = 0; i < length; ++i) {
97 v8::Local<v8::Value> item = array->Get(v8::Int32::New(i)); 97 v8::Local<v8::Value> item = array->Get(v8::Int32::New(i, isolate));
98 RefPtr<IDBKey> subkey = createIDBKeyFromValue(item, stack); 98 RefPtr<IDBKey> subkey = createIDBKeyFromValue(item, stack, isolate);
99 if (!subkey) 99 if (!subkey)
100 subkeys.append(IDBKey::createInvalid()); 100 subkeys.append(IDBKey::createInvalid());
101 else 101 else
102 subkeys.append(subkey); 102 subkeys.append(subkey);
103 } 103 }
104 104
105 stack.removeLast(); 105 stack.removeLast();
106 return IDBKey::createArray(subkeys); 106 return IDBKey::createArray(subkeys);
107 } 107 }
108 return 0; 108 return 0;
109 } 109 }
110 110
111 PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value) 111 static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value, v8: :Isolate* isolate)
112 { 112 {
113 Vector<v8::Handle<v8::Array> > stack; 113 Vector<v8::Handle<v8::Array> > stack;
114 RefPtr<IDBKey> key = createIDBKeyFromValue(value, stack); 114 RefPtr<IDBKey> key = createIDBKeyFromValue(value, stack, isolate);
115 if (key) 115 if (key)
116 return key; 116 return key;
117 return IDBKey::createInvalid(); 117 return IDBKey::createInvalid();
118 } 118 }
119 119
120 template<typename T> 120 template<typename T>
121 static bool getValueFrom(T indexOrName, v8::Handle<v8::Value>& v8Value) 121 static bool getValueFrom(T indexOrName, v8::Handle<v8::Value>& v8Value)
122 { 122 {
123 v8::Local<v8::Object> object = v8Value->ToObject(); 123 v8::Local<v8::Object> object = v8Value->ToObject();
124 if (!object->Has(indexOrName)) 124 if (!object->Has(indexOrName))
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 IDBKeyPathParseError error; 210 IDBKeyPathParseError error;
211 IDBParseKeyPath(keyPath, keyPathElements, error); 211 IDBParseKeyPath(keyPath, keyPathElements, error);
212 ASSERT(error == IDBKeyPathParseErrorNone); 212 ASSERT(error == IDBKeyPathParseErrorNone);
213 ASSERT(v8::Context::InContext()); 213 ASSERT(v8::Context::InContext());
214 214
215 v8::HandleScope handleScope(isolate); 215 v8::HandleScope handleScope(isolate);
216 v8::Handle<v8::Value> v8Value(value.v8Value()); 216 v8::Handle<v8::Value> v8Value(value.v8Value());
217 v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, k eyPathElements.size(), isolate)); 217 v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, k eyPathElements.size(), isolate));
218 if (v8Key.IsEmpty()) 218 if (v8Key.IsEmpty())
219 return 0; 219 return 0;
220 return createIDBKeyFromValue(v8Key); 220 return createIDBKeyFromValue(v8Key, isolate);
221 } 221 }
222 222
223 PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(DOMRequestState* state, const ScriptValue& value, const IDBKeyPath& keyPath) 223 PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(DOMRequestState* state, const ScriptValue& value, const IDBKeyPath& keyPath)
224 { 224 {
225 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath"); 225 IDB_TRACE("createIDBKeyFromScriptValueAndKeyPath");
226 ASSERT(!keyPath.isNull()); 226 ASSERT(!keyPath.isNull());
227 ASSERT(v8::Context::InContext()); 227 ASSERT(v8::Context::InContext());
228 228
229 229
230 v8::Isolate* isolate = state ? state->context()->GetIsolate() : v8::Isolate: :GetCurrent(); 230 v8::Isolate* isolate = state ? state->context()->GetIsolate() : v8::Isolate: :GetCurrent();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 v8::Handle<v8::Value> v8Value(idbKeyToV8Value(key.get(), state->context()->G etIsolate())); 323 v8::Handle<v8::Value> v8Value(idbKeyToV8Value(key.get(), state->context()->G etIsolate()));
324 return ScriptValue(v8Value); 324 return ScriptValue(v8Value);
325 } 325 }
326 326
327 PassRefPtr<IDBKey> scriptValueToIDBKey(DOMRequestState* state, const ScriptValue & scriptValue) 327 PassRefPtr<IDBKey> scriptValueToIDBKey(DOMRequestState* state, const ScriptValue & scriptValue)
328 { 328 {
329 ASSERT(v8::Context::InContext()); 329 ASSERT(v8::Context::InContext());
330 v8::Isolate* isolate = state ? state->context()->GetIsolate() : v8::Isolate: :GetCurrent(); 330 v8::Isolate* isolate = state ? state->context()->GetIsolate() : v8::Isolate: :GetCurrent();
331 v8::HandleScope handleScope(isolate); 331 v8::HandleScope handleScope(isolate);
332 v8::Handle<v8::Value> v8Value(scriptValue.v8Value()); 332 v8::Handle<v8::Value> v8Value(scriptValue.v8Value());
333 return createIDBKeyFromValue(v8Value); 333 return createIDBKeyFromValue(v8Value, isolate);
334 } 334 }
335 335
336 PassRefPtr<IDBKeyRange> scriptValueToIDBKeyRange(DOMRequestState* state, const S criptValue& scriptValue) 336 PassRefPtr<IDBKeyRange> scriptValueToIDBKeyRange(DOMRequestState* state, const S criptValue& scriptValue)
337 { 337 {
338 v8::Isolate* isolate = state ? state->context()->GetIsolate() : v8::Isolate: :GetCurrent(); 338 v8::Isolate* isolate = state ? state->context()->GetIsolate() : v8::Isolate: :GetCurrent();
339 v8::HandleScope handleScope(isolate); 339 v8::HandleScope handleScope(isolate);
340 v8::Handle<v8::Value> value(scriptValue.v8Value()); 340 v8::Handle<v8::Value> value(scriptValue.v8Value());
341 if (V8IDBKeyRange::HasInstance(value, isolate, worldType(isolate))) 341 if (V8IDBKeyRange::HasInstance(value, isolate, worldType(isolate)))
342 return V8IDBKeyRange::toNative(value.As<v8::Object>()); 342 return V8IDBKeyRange::toNative(value.As<v8::Object>());
343 return 0; 343 return 0;
344 } 344 }
345 345
346 } // namespace WebCore 346 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/Dictionary.cpp ('k') | Source/bindings/v8/ScriptDebugServer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698