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

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

Issue 1743763004: Use v8::MicrotasksScope internally in V8RecursionScope. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v8rs-2-endofscope
Patch Set: v8_helpers Created 4 years, 9 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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 : m_scope(v8::Isolate::GetCurrent()) 76 : m_scope(v8::Isolate::GetCurrent())
77 { 77 {
78 } 78 }
79 79
80 ~ScriptPromiseTest() 80 ~ScriptPromiseTest()
81 { 81 {
82 // FIXME: We put this statement here to clear an exception from the isol ate. 82 // FIXME: We put this statement here to clear an exception from the isol ate.
83 createClosure(callback, v8::Undefined(m_scope.isolate()), m_scope.isolat e()); 83 createClosure(callback, v8::Undefined(m_scope.isolate()), m_scope.isolat e());
84 84
85 // Execute all pending microtasks 85 // Execute all pending microtasks
86 isolate()->RunMicrotasks(); 86 v8::MicrotasksScope::PerformCheckpoint(isolate());
87 } 87 }
88 88
89 String toString(const ScriptValue& value) 89 String toString(const ScriptValue& value)
90 { 90 {
91 return toCoreString(value.v8Value()->ToString(getScriptState()->context( )).ToLocalChecked()); 91 return toCoreString(value.v8Value()->ToString(getScriptState()->context( )).ToLocalChecked());
92 } 92 }
93 93
94 Vector<String> toStringArray(const ScriptValue& value) 94 Vector<String> toStringArray(const ScriptValue& value)
95 { 95 {
96 NonThrowableExceptionState exceptionState; 96 NonThrowableExceptionState exceptionState;
(...skipping 20 matching lines...) Expand all
117 { 117 {
118 Resolver resolver(getScriptState()); 118 Resolver resolver(getScriptState());
119 ScriptPromise promise = resolver.promise(); 119 ScriptPromise promise = resolver.promise();
120 ScriptValue onFulfilled, onRejected; 120 ScriptValue onFulfilled, onRejected;
121 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected)); 121 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected));
122 122
123 ASSERT_FALSE(promise.isEmpty()); 123 ASSERT_FALSE(promise.isEmpty());
124 EXPECT_TRUE(onFulfilled.isEmpty()); 124 EXPECT_TRUE(onFulfilled.isEmpty());
125 EXPECT_TRUE(onRejected.isEmpty()); 125 EXPECT_TRUE(onRejected.isEmpty());
126 126
127 isolate()->RunMicrotasks(); 127 v8::MicrotasksScope::PerformCheckpoint(isolate());
128 resolver.resolve(v8String(isolate(), "hello")); 128 resolver.resolve(v8String(isolate(), "hello"));
129 129
130 EXPECT_TRUE(onFulfilled.isEmpty()); 130 EXPECT_TRUE(onFulfilled.isEmpty());
131 EXPECT_TRUE(onRejected.isEmpty()); 131 EXPECT_TRUE(onRejected.isEmpty());
132 132
133 isolate()->RunMicrotasks(); 133 v8::MicrotasksScope::PerformCheckpoint(isolate());
134 134
135 EXPECT_EQ("hello", toString(onFulfilled)); 135 EXPECT_EQ("hello", toString(onFulfilled));
136 EXPECT_TRUE(onRejected.isEmpty()); 136 EXPECT_TRUE(onRejected.isEmpty());
137 } 137 }
138 138
139 TEST_F(ScriptPromiseTest, resolveThen) 139 TEST_F(ScriptPromiseTest, resolveThen)
140 { 140 {
141 Resolver resolver(getScriptState()); 141 Resolver resolver(getScriptState());
142 ScriptPromise promise = resolver.promise(); 142 ScriptPromise promise = resolver.promise();
143 ScriptValue onFulfilled, onRejected; 143 ScriptValue onFulfilled, onRejected;
144 resolver.resolve(v8String(isolate(), "hello")); 144 resolver.resolve(v8String(isolate(), "hello"));
145 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected)); 145 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected));
146 146
147 ASSERT_FALSE(promise.isEmpty()); 147 ASSERT_FALSE(promise.isEmpty());
148 EXPECT_TRUE(onFulfilled.isEmpty()); 148 EXPECT_TRUE(onFulfilled.isEmpty());
149 EXPECT_TRUE(onRejected.isEmpty()); 149 EXPECT_TRUE(onRejected.isEmpty());
150 150
151 isolate()->RunMicrotasks(); 151 v8::MicrotasksScope::PerformCheckpoint(isolate());
152 152
153 EXPECT_EQ("hello", toString(onFulfilled)); 153 EXPECT_EQ("hello", toString(onFulfilled));
154 EXPECT_TRUE(onRejected.isEmpty()); 154 EXPECT_TRUE(onRejected.isEmpty());
155 } 155 }
156 156
157 TEST_F(ScriptPromiseTest, thenReject) 157 TEST_F(ScriptPromiseTest, thenReject)
158 { 158 {
159 Resolver resolver(getScriptState()); 159 Resolver resolver(getScriptState());
160 ScriptPromise promise = resolver.promise(); 160 ScriptPromise promise = resolver.promise();
161 ScriptValue onFulfilled, onRejected; 161 ScriptValue onFulfilled, onRejected;
162 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected)); 162 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected));
163 163
164 ASSERT_FALSE(promise.isEmpty()); 164 ASSERT_FALSE(promise.isEmpty());
165 EXPECT_TRUE(onFulfilled.isEmpty()); 165 EXPECT_TRUE(onFulfilled.isEmpty());
166 EXPECT_TRUE(onRejected.isEmpty()); 166 EXPECT_TRUE(onRejected.isEmpty());
167 167
168 isolate()->RunMicrotasks(); 168 v8::MicrotasksScope::PerformCheckpoint(isolate());
169 resolver.reject(v8String(isolate(), "hello")); 169 resolver.reject(v8String(isolate(), "hello"));
170 170
171 EXPECT_TRUE(onFulfilled.isEmpty()); 171 EXPECT_TRUE(onFulfilled.isEmpty());
172 EXPECT_TRUE(onRejected.isEmpty()); 172 EXPECT_TRUE(onRejected.isEmpty());
173 173
174 isolate()->RunMicrotasks(); 174 v8::MicrotasksScope::PerformCheckpoint(isolate());
175 175
176 EXPECT_TRUE(onFulfilled.isEmpty()); 176 EXPECT_TRUE(onFulfilled.isEmpty());
177 EXPECT_EQ("hello", toString(onRejected)); 177 EXPECT_EQ("hello", toString(onRejected));
178 } 178 }
179 179
180 TEST_F(ScriptPromiseTest, rejectThen) 180 TEST_F(ScriptPromiseTest, rejectThen)
181 { 181 {
182 Resolver resolver(getScriptState()); 182 Resolver resolver(getScriptState());
183 ScriptPromise promise = resolver.promise(); 183 ScriptPromise promise = resolver.promise();
184 ScriptValue onFulfilled, onRejected; 184 ScriptValue onFulfilled, onRejected;
185 resolver.reject(v8String(isolate(), "hello")); 185 resolver.reject(v8String(isolate(), "hello"));
186 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected)); 186 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected));
187 187
188 ASSERT_FALSE(promise.isEmpty()); 188 ASSERT_FALSE(promise.isEmpty());
189 EXPECT_TRUE(onFulfilled.isEmpty()); 189 EXPECT_TRUE(onFulfilled.isEmpty());
190 EXPECT_TRUE(onRejected.isEmpty()); 190 EXPECT_TRUE(onRejected.isEmpty());
191 191
192 isolate()->RunMicrotasks(); 192 v8::MicrotasksScope::PerformCheckpoint(isolate());
193 193
194 EXPECT_TRUE(onFulfilled.isEmpty()); 194 EXPECT_TRUE(onFulfilled.isEmpty());
195 EXPECT_EQ("hello", toString(onRejected)); 195 EXPECT_EQ("hello", toString(onRejected));
196 } 196 }
197 197
198 TEST_F(ScriptPromiseTest, castPromise) 198 TEST_F(ScriptPromiseTest, castPromise)
199 { 199 {
200 ScriptPromise promise = Resolver(getScriptState()).promise(); 200 ScriptPromise promise = Resolver(getScriptState()).promise();
201 ScriptPromise newPromise = ScriptPromise::cast(getScriptState(), promise.v8V alue()); 201 ScriptPromise newPromise = ScriptPromise::cast(getScriptState(), promise.v8V alue());
202 202
(...skipping 16 matching lines...) Expand all
219 EXPECT_NE(promise1.v8Value(), promise2.v8Value()); 219 EXPECT_NE(promise1.v8Value(), promise2.v8Value());
220 220
221 ASSERT_TRUE(promise1.v8Value()->IsPromise()); 221 ASSERT_TRUE(promise1.v8Value()->IsPromise());
222 ASSERT_TRUE(promise2.v8Value()->IsPromise()); 222 ASSERT_TRUE(promise2.v8Value()->IsPromise());
223 223
224 EXPECT_TRUE(onFulfilled1.isEmpty()); 224 EXPECT_TRUE(onFulfilled1.isEmpty());
225 EXPECT_TRUE(onFulfilled2.isEmpty()); 225 EXPECT_TRUE(onFulfilled2.isEmpty());
226 EXPECT_TRUE(onRejected1.isEmpty()); 226 EXPECT_TRUE(onRejected1.isEmpty());
227 EXPECT_TRUE(onRejected2.isEmpty()); 227 EXPECT_TRUE(onRejected2.isEmpty());
228 228
229 isolate()->RunMicrotasks(); 229 v8::MicrotasksScope::PerformCheckpoint(isolate());
230 230
231 EXPECT_EQ("hello", toString(onFulfilled1)); 231 EXPECT_EQ("hello", toString(onFulfilled1));
232 EXPECT_EQ("hello", toString(onFulfilled2)); 232 EXPECT_EQ("hello", toString(onFulfilled2));
233 EXPECT_TRUE(onRejected1.isEmpty()); 233 EXPECT_TRUE(onRejected1.isEmpty());
234 EXPECT_TRUE(onRejected2.isEmpty()); 234 EXPECT_TRUE(onRejected2.isEmpty());
235 } 235 }
236 236
237 TEST_F(ScriptPromiseTest, reject) 237 TEST_F(ScriptPromiseTest, reject)
238 { 238 {
239 ScriptValue onFulfilled, onRejected; 239 ScriptValue onFulfilled, onRejected;
240 240
241 ScriptValue value = ScriptValue(getScriptState(), v8String(isolate(), "hello ")); 241 ScriptValue value = ScriptValue(getScriptState(), v8String(isolate(), "hello "));
242 ScriptPromise promise = ScriptPromise::reject(getScriptState(), ScriptValue( value)); 242 ScriptPromise promise = ScriptPromise::reject(getScriptState(), ScriptValue( value));
243 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected)); 243 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected));
244 244
245 ASSERT_FALSE(promise.isEmpty()); 245 ASSERT_FALSE(promise.isEmpty());
246 ASSERT_TRUE(promise.v8Value()->IsPromise()); 246 ASSERT_TRUE(promise.v8Value()->IsPromise());
247 247
248 EXPECT_TRUE(onFulfilled.isEmpty()); 248 EXPECT_TRUE(onFulfilled.isEmpty());
249 EXPECT_TRUE(onRejected.isEmpty()); 249 EXPECT_TRUE(onRejected.isEmpty());
250 250
251 isolate()->RunMicrotasks(); 251 v8::MicrotasksScope::PerformCheckpoint(isolate());
252 252
253 EXPECT_TRUE(onFulfilled.isEmpty()); 253 EXPECT_TRUE(onFulfilled.isEmpty());
254 EXPECT_EQ("hello", toString(onRejected)); 254 EXPECT_EQ("hello", toString(onRejected));
255 } 255 }
256 256
257 TEST_F(ScriptPromiseTest, rejectWithExceptionState) 257 TEST_F(ScriptPromiseTest, rejectWithExceptionState)
258 { 258 {
259 ScriptValue onFulfilled, onRejected; 259 ScriptValue onFulfilled, onRejected;
260 ScriptPromise promise = ScriptPromise::rejectWithDOMException(getScriptState (), DOMException::create(SyntaxError, "some syntax error")); 260 ScriptPromise promise = ScriptPromise::rejectWithDOMException(getScriptState (), DOMException::create(SyntaxError, "some syntax error"));
261 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected)); 261 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected));
262 262
263 ASSERT_FALSE(promise.isEmpty()); 263 ASSERT_FALSE(promise.isEmpty());
264 EXPECT_TRUE(onFulfilled.isEmpty()); 264 EXPECT_TRUE(onFulfilled.isEmpty());
265 EXPECT_TRUE(onRejected.isEmpty()); 265 EXPECT_TRUE(onRejected.isEmpty());
266 266
267 isolate()->RunMicrotasks(); 267 v8::MicrotasksScope::PerformCheckpoint(isolate());
268 268
269 EXPECT_TRUE(onFulfilled.isEmpty()); 269 EXPECT_TRUE(onFulfilled.isEmpty());
270 EXPECT_EQ("SyntaxError: some syntax error", toString(onRejected)); 270 EXPECT_EQ("SyntaxError: some syntax error", toString(onRejected));
271 } 271 }
272 272
273 TEST_F(ScriptPromiseTest, allWithEmptyPromises) 273 TEST_F(ScriptPromiseTest, allWithEmptyPromises)
274 { 274 {
275 ScriptValue onFulfilled, onRejected; 275 ScriptValue onFulfilled, onRejected;
276 276
277 ScriptPromise promise = ScriptPromise::all(getScriptState(), Vector<ScriptPr omise>()); 277 ScriptPromise promise = ScriptPromise::all(getScriptState(), Vector<ScriptPr omise>());
278 ASSERT_FALSE(promise.isEmpty()); 278 ASSERT_FALSE(promise.isEmpty());
279 279
280 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected)); 280 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected));
281 281
282 EXPECT_TRUE(onFulfilled.isEmpty()); 282 EXPECT_TRUE(onFulfilled.isEmpty());
283 EXPECT_TRUE(onRejected.isEmpty()); 283 EXPECT_TRUE(onRejected.isEmpty());
284 284
285 isolate()->RunMicrotasks(); 285 v8::MicrotasksScope::PerformCheckpoint(isolate());
286 286
287 EXPECT_FALSE(onFulfilled.isEmpty()); 287 EXPECT_FALSE(onFulfilled.isEmpty());
288 EXPECT_TRUE(toStringArray(onFulfilled).isEmpty()); 288 EXPECT_TRUE(toStringArray(onFulfilled).isEmpty());
289 EXPECT_TRUE(onRejected.isEmpty()); 289 EXPECT_TRUE(onRejected.isEmpty());
290 } 290 }
291 291
292 TEST_F(ScriptPromiseTest, allWithResolvedPromises) 292 TEST_F(ScriptPromiseTest, allWithResolvedPromises)
293 { 293 {
294 ScriptValue onFulfilled, onRejected; 294 ScriptValue onFulfilled, onRejected;
295 295
296 Vector<ScriptPromise> promises; 296 Vector<ScriptPromise> promises;
297 promises.append(ScriptPromise::cast(getScriptState(), v8String(isolate(), "h ello"))); 297 promises.append(ScriptPromise::cast(getScriptState(), v8String(isolate(), "h ello")));
298 promises.append(ScriptPromise::cast(getScriptState(), v8String(isolate(), "w orld"))); 298 promises.append(ScriptPromise::cast(getScriptState(), v8String(isolate(), "w orld")));
299 299
300 ScriptPromise promise = ScriptPromise::all(getScriptState(), promises); 300 ScriptPromise promise = ScriptPromise::all(getScriptState(), promises);
301 ASSERT_FALSE(promise.isEmpty()); 301 ASSERT_FALSE(promise.isEmpty());
302 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected)); 302 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected));
303 303
304 EXPECT_TRUE(onFulfilled.isEmpty()); 304 EXPECT_TRUE(onFulfilled.isEmpty());
305 EXPECT_TRUE(onRejected.isEmpty()); 305 EXPECT_TRUE(onRejected.isEmpty());
306 306
307 isolate()->RunMicrotasks(); 307 v8::MicrotasksScope::PerformCheckpoint(isolate());
308 308
309 EXPECT_FALSE(onFulfilled.isEmpty()); 309 EXPECT_FALSE(onFulfilled.isEmpty());
310 Vector<String> values = toStringArray(onFulfilled); 310 Vector<String> values = toStringArray(onFulfilled);
311 EXPECT_EQ(2u, values.size()); 311 EXPECT_EQ(2u, values.size());
312 EXPECT_EQ("hello", values[0]); 312 EXPECT_EQ("hello", values[0]);
313 EXPECT_EQ("world", values[1]); 313 EXPECT_EQ("world", values[1]);
314 EXPECT_TRUE(onRejected.isEmpty()); 314 EXPECT_TRUE(onRejected.isEmpty());
315 } 315 }
316 316
317 TEST_F(ScriptPromiseTest, allWithRejectedPromise) 317 TEST_F(ScriptPromiseTest, allWithRejectedPromise)
318 { 318 {
319 ScriptValue onFulfilled, onRejected; 319 ScriptValue onFulfilled, onRejected;
320 320
321 Vector<ScriptPromise> promises; 321 Vector<ScriptPromise> promises;
322 promises.append(ScriptPromise::cast(getScriptState(), v8String(isolate(), "h ello"))); 322 promises.append(ScriptPromise::cast(getScriptState(), v8String(isolate(), "h ello")));
323 promises.append(ScriptPromise::reject(getScriptState(), v8String(isolate(), "world"))); 323 promises.append(ScriptPromise::reject(getScriptState(), v8String(isolate(), "world")));
324 324
325 ScriptPromise promise = ScriptPromise::all(getScriptState(), promises); 325 ScriptPromise promise = ScriptPromise::all(getScriptState(), promises);
326 ASSERT_FALSE(promise.isEmpty()); 326 ASSERT_FALSE(promise.isEmpty());
327 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected)); 327 promise.then(Function::createFunction(getScriptState(), &onFulfilled), Funct ion::createFunction(getScriptState(), &onRejected));
328 328
329 EXPECT_TRUE(onFulfilled.isEmpty()); 329 EXPECT_TRUE(onFulfilled.isEmpty());
330 EXPECT_TRUE(onRejected.isEmpty()); 330 EXPECT_TRUE(onRejected.isEmpty());
331 331
332 isolate()->RunMicrotasks(); 332 v8::MicrotasksScope::PerformCheckpoint(isolate());
333 333
334 EXPECT_TRUE(onFulfilled.isEmpty()); 334 EXPECT_TRUE(onFulfilled.isEmpty());
335 EXPECT_FALSE(onRejected.isEmpty()); 335 EXPECT_FALSE(onRejected.isEmpty());
336 EXPECT_EQ("world", toString(onRejected)); 336 EXPECT_EQ("world", toString(onRejected));
337 } 337 }
338 338
339 } // namespace 339 } // namespace
340 340
341 } // namespace blink 341 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698