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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ToV8Test.cpp

Issue 2554693003: Migrate WTF::Vector::append() to ::push_back() [part 1 of N] (Closed)
Patch Set: rebase Created 4 years 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "bindings/core/v8/ToV8.h" 5 #include "bindings/core/v8/ToV8.h"
6 6
7 #include "bindings/core/v8/V8Binding.h" 7 #include "bindings/core/v8/V8Binding.h"
8 #include "bindings/core/v8/V8BindingForTesting.h" 8 #include "bindings/core/v8/V8BindingForTesting.h"
9 #include "core/testing/GarbageCollectedScriptWrappable.h" 9 #include "core/testing/GarbageCollectedScriptWrappable.h"
10 #include "platform/heap/Heap.h" 10 #include "platform/heap/Heap.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 V8TestingScope scope; 148 V8TestingScope scope;
149 ScriptValue value(scope.getScriptState(), 149 ScriptValue value(scope.getScriptState(),
150 v8::Number::New(scope.isolate(), 1234)); 150 v8::Number::New(scope.isolate(), 1234));
151 151
152 TEST_TOV8("1234", value); 152 TEST_TOV8("1234", value);
153 } 153 }
154 154
155 TEST(ToV8Test, stringVectors) { 155 TEST(ToV8Test, stringVectors) {
156 V8TestingScope scope; 156 V8TestingScope scope;
157 Vector<String> stringVector; 157 Vector<String> stringVector;
158 stringVector.append("foo"); 158 stringVector.push_back("foo");
159 stringVector.append("bar"); 159 stringVector.push_back("bar");
160 TEST_TOV8("foo,bar", stringVector); 160 TEST_TOV8("foo,bar", stringVector);
161 161
162 Vector<AtomicString> atomicStringVector; 162 Vector<AtomicString> atomicStringVector;
163 atomicStringVector.append("quux"); 163 atomicStringVector.push_back("quux");
164 atomicStringVector.append("bar"); 164 atomicStringVector.push_back("bar");
165 TEST_TOV8("quux,bar", atomicStringVector); 165 TEST_TOV8("quux,bar", atomicStringVector);
166 } 166 }
167 167
168 TEST(ToV8Test, basicTypeVectors) { 168 TEST(ToV8Test, basicTypeVectors) {
169 V8TestingScope scope; 169 V8TestingScope scope;
170 Vector<int> intVector; 170 Vector<int> intVector;
171 intVector.append(42); 171 intVector.push_back(42);
172 intVector.append(23); 172 intVector.push_back(23);
173 TEST_TOV8("42,23", intVector); 173 TEST_TOV8("42,23", intVector);
174 174
175 Vector<long> longVector; 175 Vector<long> longVector;
176 longVector.append(31773); 176 longVector.push_back(31773);
177 longVector.append(404); 177 longVector.push_back(404);
178 TEST_TOV8("31773,404", longVector); 178 TEST_TOV8("31773,404", longVector);
179 179
180 Vector<unsigned> unsignedVector; 180 Vector<unsigned> unsignedVector;
181 unsignedVector.append(1); 181 unsignedVector.push_back(1);
182 unsignedVector.append(2); 182 unsignedVector.push_back(2);
183 TEST_TOV8("1,2", unsignedVector); 183 TEST_TOV8("1,2", unsignedVector);
184 184
185 Vector<unsigned long> unsignedLongVector; 185 Vector<unsigned long> unsignedLongVector;
186 unsignedLongVector.append(1001); 186 unsignedLongVector.push_back(1001);
187 unsignedLongVector.append(2002); 187 unsignedLongVector.push_back(2002);
188 TEST_TOV8("1001,2002", unsignedLongVector); 188 TEST_TOV8("1001,2002", unsignedLongVector);
189 189
190 Vector<float> floatVector; 190 Vector<float> floatVector;
191 floatVector.append(0.125); 191 floatVector.push_back(0.125);
192 floatVector.append(1.); 192 floatVector.push_back(1.);
193 TEST_TOV8("0.125,1", floatVector); 193 TEST_TOV8("0.125,1", floatVector);
194 194
195 Vector<double> doubleVector; 195 Vector<double> doubleVector;
196 doubleVector.append(2.3); 196 doubleVector.push_back(2.3);
197 doubleVector.append(4.2); 197 doubleVector.push_back(4.2);
198 TEST_TOV8("2.3,4.2", doubleVector); 198 TEST_TOV8("2.3,4.2", doubleVector);
199 199
200 Vector<bool> boolVector; 200 Vector<bool> boolVector;
201 boolVector.append(true); 201 boolVector.push_back(true);
202 boolVector.append(true); 202 boolVector.push_back(true);
203 boolVector.append(false); 203 boolVector.push_back(false);
204 TEST_TOV8("true,true,false", boolVector); 204 TEST_TOV8("true,true,false", boolVector);
205 } 205 }
206 206
207 TEST(ToV8Test, dictionaryVector) { 207 TEST(ToV8Test, dictionaryVector) {
208 V8TestingScope scope; 208 V8TestingScope scope;
209 Vector<std::pair<String, int>> dictionary; 209 Vector<std::pair<String, int>> dictionary;
210 dictionary.append(std::make_pair("one", 1)); 210 dictionary.push_back(std::make_pair("one", 1));
211 dictionary.append(std::make_pair("two", 2)); 211 dictionary.push_back(std::make_pair("two", 2));
212 TEST_TOV8("[object Object]", dictionary); 212 TEST_TOV8("[object Object]", dictionary);
213 v8::Local<v8::Context> context = scope.getScriptState()->context(); 213 v8::Local<v8::Context> context = scope.getScriptState()->context();
214 v8::Local<v8::Object> result = 214 v8::Local<v8::Object> result =
215 toV8(dictionary, context->Global(), scope.isolate()) 215 toV8(dictionary, context->Global(), scope.isolate())
216 ->ToObject(context) 216 ->ToObject(context)
217 .ToLocalChecked(); 217 .ToLocalChecked();
218 v8::Local<v8::Value> one = 218 v8::Local<v8::Value> one =
219 result->Get(context, v8String(scope.isolate(), "one")).ToLocalChecked(); 219 result->Get(context, v8String(scope.isolate(), "one")).ToLocalChecked();
220 EXPECT_EQ(1, one->NumberValue(context).FromJust()); 220 EXPECT_EQ(1, one->NumberValue(context).FromJust());
221 v8::Local<v8::Value> two = 221 v8::Local<v8::Value> two =
222 result->Get(context, v8String(scope.isolate(), "two")).ToLocalChecked(); 222 result->Get(context, v8String(scope.isolate(), "two")).ToLocalChecked();
223 EXPECT_EQ(2, two->NumberValue(context).FromJust()); 223 EXPECT_EQ(2, two->NumberValue(context).FromJust());
224 } 224 }
225 225
226 TEST(ToV8Test, heapVector) { 226 TEST(ToV8Test, heapVector) {
227 V8TestingScope scope; 227 V8TestingScope scope;
228 HeapVector<Member<GarbageCollectedScriptWrappable>> v; 228 HeapVector<Member<GarbageCollectedScriptWrappable>> v;
229 v.append(new GarbageCollectedScriptWrappable("hoge")); 229 v.push_back(new GarbageCollectedScriptWrappable("hoge"));
230 v.append(new GarbageCollectedScriptWrappable("fuga")); 230 v.push_back(new GarbageCollectedScriptWrappable("fuga"));
231 v.append(nullptr); 231 v.push_back(nullptr);
232 232
233 TEST_TOV8("hoge,fuga,", v); 233 TEST_TOV8("hoge,fuga,", v);
234 } 234 }
235 235
236 TEST(ToV8Test, withScriptState) { 236 TEST(ToV8Test, withScriptState) {
237 V8TestingScope scope; 237 V8TestingScope scope;
238 ScriptValue value(scope.getScriptState(), 238 ScriptValue value(scope.getScriptState(),
239 v8::Number::New(scope.isolate(), 1234.0)); 239 v8::Number::New(scope.isolate(), 1234.0));
240 240
241 v8::Local<v8::Value> actual = toV8(value, scope.getScriptState()); 241 v8::Local<v8::Value> actual = toV8(value, scope.getScriptState());
242 EXPECT_FALSE(actual.IsEmpty()); 242 EXPECT_FALSE(actual.IsEmpty());
243 243
244 double actualAsNumber = actual.As<v8::Number>()->Value(); 244 double actualAsNumber = actual.As<v8::Number>()->Value();
245 EXPECT_EQ(1234.0, actualAsNumber); 245 EXPECT_EQ(1234.0, actualAsNumber);
246 } 246 }
247 247
248 } // namespace 248 } // namespace
249 249
250 } // namespace blink 250 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698