| OLD | NEW |
| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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(scriptState()->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; |
| 97 return toImplArray<Vector<String>>(value.v8Value(), 0, scriptState()->is
olate(), exceptionState); | 97 return toImplArray<Vector<String>>(value.v8Value(), 0, getScriptState()-
>isolate(), exceptionState); |
| 98 } | 98 } |
| 99 | 99 |
| 100 ScriptState* scriptState() const { return m_scope.scriptState(); } | 100 ScriptState* getScriptState() const { return m_scope.getScriptState(); } |
| 101 v8::Isolate* isolate() const { return m_scope.isolate(); } | 101 v8::Isolate* isolate() const { return m_scope.isolate(); } |
| 102 | 102 |
| 103 protected: | 103 protected: |
| 104 typedef ScriptPromise::InternalResolver Resolver; | 104 typedef ScriptPromise::InternalResolver Resolver; |
| 105 V8TestingScope m_scope; | 105 V8TestingScope m_scope; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 TEST_F(ScriptPromiseTest, constructFromNonPromise) | 108 TEST_F(ScriptPromiseTest, constructFromNonPromise) |
| 109 { | 109 { |
| 110 v8::TryCatch trycatch(isolate()); | 110 v8::TryCatch trycatch(isolate()); |
| 111 ScriptPromise promise(scriptState(), v8::Undefined(isolate())); | 111 ScriptPromise promise(getScriptState(), v8::Undefined(isolate())); |
| 112 ASSERT_TRUE(trycatch.HasCaught()); | 112 ASSERT_TRUE(trycatch.HasCaught()); |
| 113 ASSERT_TRUE(promise.isEmpty()); | 113 ASSERT_TRUE(promise.isEmpty()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 TEST_F(ScriptPromiseTest, thenResolve) | 116 TEST_F(ScriptPromiseTest, thenResolve) |
| 117 { | 117 { |
| 118 Resolver resolver(scriptState()); | 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(scriptState(), &onFulfilled), Function
::createFunction(scriptState(), &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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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(scriptState()); | 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(scriptState(), &onFulfilled), Function
::createFunction(scriptState(), &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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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(scriptState()); | 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(scriptState(), &onFulfilled), Function
::createFunction(scriptState(), &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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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(scriptState()); | 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(scriptState(), &onFulfilled), Function
::createFunction(scriptState(), &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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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(scriptState()).promise(); | 200 ScriptPromise promise = Resolver(getScriptState()).promise(); |
| 201 ScriptPromise newPromise = ScriptPromise::cast(scriptState(), promise.v8Valu
e()); | 201 ScriptPromise newPromise = ScriptPromise::cast(getScriptState(), promise.v8V
alue()); |
| 202 | 202 |
| 203 ASSERT_FALSE(promise.isEmpty()); | 203 ASSERT_FALSE(promise.isEmpty()); |
| 204 EXPECT_EQ(promise.v8Value(), newPromise.v8Value()); | 204 EXPECT_EQ(promise.v8Value(), newPromise.v8Value()); |
| 205 } | 205 } |
| 206 | 206 |
| 207 TEST_F(ScriptPromiseTest, castNonPromise) | 207 TEST_F(ScriptPromiseTest, castNonPromise) |
| 208 { | 208 { |
| 209 ScriptValue onFulfilled1, onFulfilled2, onRejected1, onRejected2; | 209 ScriptValue onFulfilled1, onFulfilled2, onRejected1, onRejected2; |
| 210 | 210 |
| 211 ScriptValue value = ScriptValue(scriptState(), v8String(isolate(), "hello"))
; | 211 ScriptValue value = ScriptValue(getScriptState(), v8String(isolate(), "hello
")); |
| 212 ScriptPromise promise1 = ScriptPromise::cast(scriptState(), ScriptValue(valu
e)); | 212 ScriptPromise promise1 = ScriptPromise::cast(getScriptState(), ScriptValue(v
alue)); |
| 213 ScriptPromise promise2 = ScriptPromise::cast(scriptState(), ScriptValue(valu
e)); | 213 ScriptPromise promise2 = ScriptPromise::cast(getScriptState(), ScriptValue(v
alue)); |
| 214 promise1.then(Function::createFunction(scriptState(), &onFulfilled1), Functi
on::createFunction(scriptState(), &onRejected1)); | 214 promise1.then(Function::createFunction(getScriptState(), &onFulfilled1), Fun
ction::createFunction(getScriptState(), &onRejected1)); |
| 215 promise2.then(Function::createFunction(scriptState(), &onFulfilled2), Functi
on::createFunction(scriptState(), &onRejected2)); | 215 promise2.then(Function::createFunction(getScriptState(), &onFulfilled2), Fun
ction::createFunction(getScriptState(), &onRejected2)); |
| 216 | 216 |
| 217 ASSERT_FALSE(promise1.isEmpty()); | 217 ASSERT_FALSE(promise1.isEmpty()); |
| 218 ASSERT_FALSE(promise2.isEmpty()); | 218 ASSERT_FALSE(promise2.isEmpty()); |
| 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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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(scriptState(), v8String(isolate(), "hello"))
; | 241 ScriptValue value = ScriptValue(getScriptState(), v8String(isolate(), "hello
")); |
| 242 ScriptPromise promise = ScriptPromise::reject(scriptState(), ScriptValue(val
ue)); | 242 ScriptPromise promise = ScriptPromise::reject(getScriptState(), ScriptValue(
value)); |
| 243 promise.then(Function::createFunction(scriptState(), &onFulfilled), Function
::createFunction(scriptState(), &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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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(scriptState(),
DOMException::create(SyntaxError, "some syntax error")); | 260 ScriptPromise promise = ScriptPromise::rejectWithDOMException(getScriptState
(), DOMException::create(SyntaxError, "some syntax error")); |
| 261 promise.then(Function::createFunction(scriptState(), &onFulfilled), Function
::createFunction(scriptState(), &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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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(scriptState(), Vector<ScriptPromi
se>()); | 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(scriptState(), &onFulfilled), Function
::createFunction(scriptState(), &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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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(scriptState(), v8String(isolate(), "hell
o"))); | 297 promises.append(ScriptPromise::cast(getScriptState(), v8String(isolate(), "h
ello"))); |
| 298 promises.append(ScriptPromise::cast(scriptState(), v8String(isolate(), "worl
d"))); | 298 promises.append(ScriptPromise::cast(getScriptState(), v8String(isolate(), "w
orld"))); |
| 299 | 299 |
| 300 ScriptPromise promise = ScriptPromise::all(scriptState(), promises); | 300 ScriptPromise promise = ScriptPromise::all(getScriptState(), promises); |
| 301 ASSERT_FALSE(promise.isEmpty()); | 301 ASSERT_FALSE(promise.isEmpty()); |
| 302 promise.then(Function::createFunction(scriptState(), &onFulfilled), Function
::createFunction(scriptState(), &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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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(scriptState(), v8String(isolate(), "hell
o"))); | 322 promises.append(ScriptPromise::cast(getScriptState(), v8String(isolate(), "h
ello"))); |
| 323 promises.append(ScriptPromise::reject(scriptState(), v8String(isolate(), "wo
rld"))); | 323 promises.append(ScriptPromise::reject(getScriptState(), v8String(isolate(),
"world"))); |
| 324 | 324 |
| 325 ScriptPromise promise = ScriptPromise::all(scriptState(), promises); | 325 ScriptPromise promise = ScriptPromise::all(getScriptState(), promises); |
| 326 ASSERT_FALSE(promise.isEmpty()); | 326 ASSERT_FALSE(promise.isEmpty()); |
| 327 promise.then(Function::createFunction(scriptState(), &onFulfilled), Function
::createFunction(scriptState(), &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 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 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 |
| OLD | NEW |