| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 return cachedObjectTemplate(&privateTemplateUniqueKey, V8PromiseCustom::Prim
itiveWrapperFieldCount, isolate); | 85 return cachedObjectTemplate(&privateTemplateUniqueKey, V8PromiseCustom::Prim
itiveWrapperFieldCount, isolate); |
| 86 } | 86 } |
| 87 | 87 |
| 88 v8::Local<v8::ObjectTemplate> internalObjectTemplate(v8::Isolate* isolate) | 88 v8::Local<v8::ObjectTemplate> internalObjectTemplate(v8::Isolate* isolate) |
| 89 { | 89 { |
| 90 // This is only for getting a unique pointer which we can pass to privateTem
plate. | 90 // This is only for getting a unique pointer which we can pass to privateTem
plate. |
| 91 static int privateTemplateUniqueKey; | 91 static int privateTemplateUniqueKey; |
| 92 return cachedObjectTemplate(&privateTemplateUniqueKey, V8PromiseCustom::Inte
rnalFieldCount, isolate); | 92 return cachedObjectTemplate(&privateTemplateUniqueKey, V8PromiseCustom::Inte
rnalFieldCount, isolate); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void promiseResolveCallback(const v8::FunctionCallbackInfo<v8::Value>& args) | 95 void promiseResolveCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 96 { | 96 { |
| 97 ASSERT(!args.Data().IsEmpty()); | 97 ASSERT(!info.Data().IsEmpty()); |
| 98 v8::Local<v8::Object> promise = args.Data().As<v8::Object>(); | 98 v8::Local<v8::Object> promise = info.Data().As<v8::Object>(); |
| 99 v8::Local<v8::Value> result = v8::Undefined(args.GetIsolate()); | 99 v8::Local<v8::Value> result = v8::Undefined(info.GetIsolate()); |
| 100 if (args.Length() > 0) | 100 if (info.Length() > 0) |
| 101 result = args[0]; | 101 result = info[0]; |
| 102 | 102 |
| 103 V8PromiseCustom::resolve(promise, result, args.GetIsolate()); | 103 V8PromiseCustom::resolve(promise, result, info.GetIsolate()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void promiseRejectCallback(const v8::FunctionCallbackInfo<v8::Value>& args) | 106 void promiseRejectCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 107 { | 107 { |
| 108 ASSERT(!args.Data().IsEmpty()); | 108 ASSERT(!info.Data().IsEmpty()); |
| 109 v8::Local<v8::Object> promise = args.Data().As<v8::Object>(); | 109 v8::Local<v8::Object> promise = info.Data().As<v8::Object>(); |
| 110 v8::Local<v8::Value> result = v8::Undefined(args.GetIsolate()); | 110 v8::Local<v8::Value> result = v8::Undefined(info.GetIsolate()); |
| 111 if (args.Length() > 0) | 111 if (info.Length() > 0) |
| 112 result = args[0]; | 112 result = info[0]; |
| 113 | 113 |
| 114 V8PromiseCustom::reject(promise, result, args.GetIsolate()); | 114 V8PromiseCustom::reject(promise, result, info.GetIsolate()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void promiseAllFulfillCallback(const v8::FunctionCallbackInfo<v8::Value>& args) | 117 void promiseAllFulfillCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 118 { | 118 { |
| 119 v8::Isolate* isolate = args.GetIsolate(); | 119 v8::Isolate* isolate = info.GetIsolate(); |
| 120 ASSERT(!args.Data().IsEmpty()); | 120 ASSERT(!info.Data().IsEmpty()); |
| 121 v8::Local<v8::Object> environment = args.Data().As<v8::Object>(); | 121 v8::Local<v8::Object> environment = info.Data().As<v8::Object>(); |
| 122 v8::Local<v8::Value> result = v8::Undefined(isolate); | 122 v8::Local<v8::Value> result = v8::Undefined(isolate); |
| 123 if (args.Length() > 0) | 123 if (info.Length() > 0) |
| 124 result = args[0]; | 124 result = info[0]; |
| 125 | 125 |
| 126 v8::Local<v8::Object> promise = environment->GetInternalField(V8PromiseCusto
m::PromiseAllEnvironmentPromiseIndex).As<v8::Object>(); | 126 v8::Local<v8::Object> promise = environment->GetInternalField(V8PromiseCusto
m::PromiseAllEnvironmentPromiseIndex).As<v8::Object>(); |
| 127 v8::Local<v8::Object> countdownWrapper = environment->GetInternalField(V8Pro
miseCustom::PromiseAllEnvironmentCountdownIndex).As<v8::Object>(); | 127 v8::Local<v8::Object> countdownWrapper = environment->GetInternalField(V8Pro
miseCustom::PromiseAllEnvironmentCountdownIndex).As<v8::Object>(); |
| 128 v8::Local<v8::Integer> index = environment->GetInternalField(V8PromiseCustom
::PromiseAllEnvironmentIndexIndex).As<v8::Integer>(); | 128 v8::Local<v8::Integer> index = environment->GetInternalField(V8PromiseCustom
::PromiseAllEnvironmentIndexIndex).As<v8::Integer>(); |
| 129 v8::Local<v8::Array> results = environment->GetInternalField(V8PromiseCustom
::PromiseAllEnvironmentResultsIndex).As<v8::Array>(); | 129 v8::Local<v8::Array> results = environment->GetInternalField(V8PromiseCustom
::PromiseAllEnvironmentResultsIndex).As<v8::Array>(); |
| 130 | 130 |
| 131 results->Set(index->Value(), result); | 131 results->Set(index->Value(), result); |
| 132 | 132 |
| 133 v8::Local<v8::Integer> countdown = countdownWrapper->GetInternalField(V8Prom
iseCustom::PrimitiveWrapperPrimitiveIndex).As<v8::Integer>(); | 133 v8::Local<v8::Integer> countdown = countdownWrapper->GetInternalField(V8Prom
iseCustom::PrimitiveWrapperPrimitiveIndex).As<v8::Integer>(); |
| 134 ASSERT(countdown->Value() >= 1); | 134 ASSERT(countdown->Value() >= 1); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 void CallHandlerTask::performTask(ExecutionContext* context) | 216 void CallHandlerTask::performTask(ExecutionContext* context) |
| 217 { | 217 { |
| 218 ASSERT(context); | 218 ASSERT(context); |
| 219 if (context->activeDOMObjectsAreStopped()) | 219 if (context->activeDOMObjectsAreStopped()) |
| 220 return; | 220 return; |
| 221 | 221 |
| 222 DOMRequestState::Scope scope(m_requestState); | 222 DOMRequestState::Scope scope(m_requestState); |
| 223 v8::Isolate* isolate = m_requestState.isolate(); | 223 v8::Isolate* isolate = m_requestState.isolate(); |
| 224 v8::Handle<v8::Value> args[] = { m_argument.newLocal(isolate) }; | 224 v8::Handle<v8::Value> info[] = { m_argument.newLocal(isolate) }; |
| 225 v8::TryCatch trycatch; | 225 v8::TryCatch trycatch; |
| 226 v8::Local<v8::Value> value = V8ScriptRunner::callFunction(m_handler.newLocal
(isolate), context, v8::Undefined(isolate), WTF_ARRAY_LENGTH(args), args, isolat
e); | 226 v8::Local<v8::Value> value = V8ScriptRunner::callFunction(m_handler.newLocal
(isolate), context, v8::Undefined(isolate), WTF_ARRAY_LENGTH(info), info, isolat
e); |
| 227 if (value.IsEmpty()) { | 227 if (value.IsEmpty()) { |
| 228 V8PromiseCustom::reject(m_promise.newLocal(isolate), trycatch.Exception(
), isolate); | 228 V8PromiseCustom::reject(m_promise.newLocal(isolate), trycatch.Exception(
), isolate); |
| 229 } else { | 229 } else { |
| 230 V8PromiseCustom::resolve(m_promise.newLocal(isolate), value, isolate); | 230 V8PromiseCustom::resolve(m_promise.newLocal(isolate), value, isolate); |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 class UpdateDerivedTask : public ExecutionContextTask { | 234 class UpdateDerivedTask : public ExecutionContextTask { |
| 235 public: | 235 public: |
| 236 UpdateDerivedTask(v8::Handle<v8::Object> promise, v8::Handle<v8::Function> o
nFulfilled, v8::Handle<v8::Function> onRejected, v8::Handle<v8::Object> originat
orValueObject, v8::Isolate* isolate, ExecutionContext* context) | 236 UpdateDerivedTask(v8::Handle<v8::Object> promise, v8::Handle<v8::Function> o
nFulfilled, v8::Handle<v8::Function> onRejected, v8::Handle<v8::Object> originat
orValueObject, v8::Isolate* isolate, ExecutionContext* context) |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 V8PromiseCustom::PromiseState state = V8PromiseCustom::getState(internal); | 453 V8PromiseCustom::PromiseState state = V8PromiseCustom::getState(internal); |
| 454 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejecte
d) { | 454 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejecte
d) { |
| 455 updateDerived(derivedPromise, onFulfilled, onRejected, promise, isolate)
; | 455 updateDerived(derivedPromise, onFulfilled, onRejected, promise, isolate)
; |
| 456 } else { | 456 } else { |
| 457 addToDerived(internal, derivedPromise, onFulfilled, onRejected, isolate)
; | 457 addToDerived(internal, derivedPromise, onFulfilled, onRejected, isolate)
; |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 | 460 |
| 461 } // namespace | 461 } // namespace |
| 462 | 462 |
| 463 void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& arg
s) | 463 void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
o) |
| 464 { | 464 { |
| 465 v8SetReturnValue(args, v8::Local<v8::Value>()); | 465 v8SetReturnValue(info, v8::Local<v8::Value>()); |
| 466 v8::Isolate* isolate = args.GetIsolate(); | 466 v8::Isolate* isolate = info.GetIsolate(); |
| 467 if (!args.Length() || !args[0]->IsFunction()) { | 467 if (!info.Length() || !info[0]->IsFunction()) { |
| 468 throwTypeError("Promise constructor takes a function argument", isolate)
; | 468 throwTypeError("Promise constructor takes a function argument", isolate)
; |
| 469 return; | 469 return; |
| 470 } | 470 } |
| 471 v8::Local<v8::Function> init = args[0].As<v8::Function>(); | 471 v8::Local<v8::Function> init = info[0].As<v8::Function>(); |
| 472 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(args.Holder()
, isolate); | 472 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); |
| 473 v8::Handle<v8::Value> argv[] = { | 473 v8::Handle<v8::Value> argv[] = { |
| 474 createClosure(promiseResolveCallback, promise, isolate), | 474 createClosure(promiseResolveCallback, promise, isolate), |
| 475 createClosure(promiseRejectCallback, promise, isolate) | 475 createClosure(promiseRejectCallback, promise, isolate) |
| 476 }; | 476 }; |
| 477 v8::TryCatch trycatch; | 477 v8::TryCatch trycatch; |
| 478 if (V8ScriptRunner::callFunction(init, getExecutionContext(), v8::Undefined(
isolate), WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) { | 478 if (V8ScriptRunner::callFunction(init, getExecutionContext(), v8::Undefined(
isolate), WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) { |
| 479 // An exception is thrown. Reject the promise if its resolved flag is un
set. | 479 // An exception is thrown. Reject the promise if its resolved flag is un
set. |
| 480 V8PromiseCustom::reject(promise, trycatch.Exception(), isolate); | 480 V8PromiseCustom::reject(promise, trycatch.Exception(), isolate); |
| 481 } | 481 } |
| 482 v8SetReturnValue(args, promise); | 482 v8SetReturnValue(info, promise); |
| 483 return; | 483 return; |
| 484 } | 484 } |
| 485 | 485 |
| 486 void V8Promise::thenMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args
) | 486 void V8Promise::thenMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info
) |
| 487 { | 487 { |
| 488 v8::Isolate* isolate = args.GetIsolate(); | 488 v8::Isolate* isolate = info.GetIsolate(); |
| 489 v8::Local<v8::Function> onFulfilled, onRejected; | 489 v8::Local<v8::Function> onFulfilled, onRejected; |
| 490 if (args.Length() > 0 && !args[0]->IsUndefined()) { | 490 if (info.Length() > 0 && !info[0]->IsUndefined()) { |
| 491 if (!args[0]->IsFunction()) { | 491 if (!info[0]->IsFunction()) { |
| 492 v8SetReturnValue(args, throwTypeError("onFulfilled must be a functio
n or undefined", isolate)); | 492 v8SetReturnValue(info, throwTypeError("onFulfilled must be a functio
n or undefined", isolate)); |
| 493 return; | 493 return; |
| 494 } | 494 } |
| 495 onFulfilled = args[0].As<v8::Function>(); | 495 onFulfilled = info[0].As<v8::Function>(); |
| 496 } | 496 } |
| 497 if (args.Length() > 1 && !args[1]->IsUndefined()) { | 497 if (info.Length() > 1 && !info[1]->IsUndefined()) { |
| 498 if (!args[1]->IsFunction()) { | 498 if (!info[1]->IsFunction()) { |
| 499 v8SetReturnValue(args, throwTypeError("onRejected must be a function
or undefined", isolate)); | 499 v8SetReturnValue(info, throwTypeError("onRejected must be a function
or undefined", isolate)); |
| 500 return; | 500 return; |
| 501 } | 501 } |
| 502 onRejected = args[1].As<v8::Function>(); | 502 onRejected = info[1].As<v8::Function>(); |
| 503 } | 503 } |
| 504 v8SetReturnValue(args, V8PromiseCustom::then(args.Holder(), onFulfilled, onR
ejected, isolate)); | 504 v8SetReturnValue(info, V8PromiseCustom::then(info.Holder(), onFulfilled, onR
ejected, isolate)); |
| 505 } | 505 } |
| 506 | 506 |
| 507 void V8Promise::castMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args
) | 507 void V8Promise::castMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info
) |
| 508 { | 508 { |
| 509 v8::Isolate* isolate = args.GetIsolate(); | 509 v8::Isolate* isolate = info.GetIsolate(); |
| 510 v8::Local<v8::Value> result = v8::Undefined(isolate); | 510 v8::Local<v8::Value> result = v8::Undefined(isolate); |
| 511 if (args.Length() > 0) | 511 if (info.Length() > 0) |
| 512 result = args[0]; | 512 result = info[0]; |
| 513 | 513 |
| 514 v8SetReturnValue(args, V8PromiseCustom::toPromise(result, isolate)); | 514 v8SetReturnValue(info, V8PromiseCustom::toPromise(result, isolate)); |
| 515 } | 515 } |
| 516 | 516 |
| 517 void V8Promise::catchMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& arg
s) | 517 void V8Promise::catchMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
o) |
| 518 { | 518 { |
| 519 v8::Isolate* isolate = args.GetIsolate(); | 519 v8::Isolate* isolate = info.GetIsolate(); |
| 520 v8::Local<v8::Function> onFulfilled, onRejected; | 520 v8::Local<v8::Function> onFulfilled, onRejected; |
| 521 | 521 |
| 522 if (args.Length() > 0 && !args[0]->IsUndefined()) { | 522 if (info.Length() > 0 && !info[0]->IsUndefined()) { |
| 523 if (!args[0]->IsFunction()) { | 523 if (!info[0]->IsFunction()) { |
| 524 v8SetReturnValue(args, throwTypeError("onRejected must be a function
or undefined", isolate)); | 524 v8SetReturnValue(info, throwTypeError("onRejected must be a function
or undefined", isolate)); |
| 525 return; | 525 return; |
| 526 } | 526 } |
| 527 onRejected = args[0].As<v8::Function>(); | 527 onRejected = info[0].As<v8::Function>(); |
| 528 } | 528 } |
| 529 v8SetReturnValue(args, V8PromiseCustom::then(args.Holder(), onFulfilled, onR
ejected, isolate)); | 529 v8SetReturnValue(info, V8PromiseCustom::then(info.Holder(), onFulfilled, onR
ejected, isolate)); |
| 530 } | 530 } |
| 531 | 531 |
| 532 void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& a
rgs) | 532 void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
nfo) |
| 533 { | 533 { |
| 534 v8::Isolate* isolate = args.GetIsolate(); | 534 v8::Isolate* isolate = info.GetIsolate(); |
| 535 v8::Local<v8::Value> result = v8::Undefined(isolate); | 535 v8::Local<v8::Value> result = v8::Undefined(isolate); |
| 536 if (args.Length() > 0) | 536 if (info.Length() > 0) |
| 537 result = args[0]; | 537 result = info[0]; |
| 538 | 538 |
| 539 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(args.Holder()
, isolate); | 539 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); |
| 540 V8PromiseCustom::resolve(promise, result, isolate); | 540 V8PromiseCustom::resolve(promise, result, isolate); |
| 541 v8SetReturnValue(args, promise); | 541 v8SetReturnValue(info, promise); |
| 542 } | 542 } |
| 543 | 543 |
| 544 void V8Promise::rejectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& ar
gs) | 544 void V8Promise::rejectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& in
fo) |
| 545 { | 545 { |
| 546 v8::Isolate* isolate = args.GetIsolate(); | 546 v8::Isolate* isolate = info.GetIsolate(); |
| 547 v8::Local<v8::Value> result = v8::Undefined(isolate); | 547 v8::Local<v8::Value> result = v8::Undefined(isolate); |
| 548 if (args.Length() > 0) | 548 if (info.Length() > 0) |
| 549 result = args[0]; | 549 result = info[0]; |
| 550 | 550 |
| 551 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(args.Holder()
, isolate); | 551 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); |
| 552 V8PromiseCustom::reject(promise, result, isolate); | 552 V8PromiseCustom::reject(promise, result, isolate); |
| 553 v8SetReturnValue(args, promise); | 553 v8SetReturnValue(info, promise); |
| 554 } | 554 } |
| 555 | 555 |
| 556 void V8Promise::raceMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args
) | 556 void V8Promise::raceMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info
) |
| 557 { | 557 { |
| 558 v8::Isolate* isolate = args.GetIsolate(); | 558 v8::Isolate* isolate = info.GetIsolate(); |
| 559 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(args.Holder()
, isolate); | 559 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); |
| 560 | 560 |
| 561 if (!args.Length() || !args[0]->IsArray()) { | 561 if (!info.Length() || !info[0]->IsArray()) { |
| 562 v8SetReturnValue(args, promise); | 562 v8SetReturnValue(info, promise); |
| 563 return; | 563 return; |
| 564 } | 564 } |
| 565 | 565 |
| 566 // FIXME: Now we limit the iterable type to the Array type. | 566 // FIXME: Now we limit the iterable type to the Array type. |
| 567 v8::Local<v8::Array> iterable = args[0].As<v8::Array>(); | 567 v8::Local<v8::Array> iterable = info[0].As<v8::Array>(); |
| 568 v8::Local<v8::Function> onFulfilled = createClosure(promiseResolveCallback,
promise, isolate); | 568 v8::Local<v8::Function> onFulfilled = createClosure(promiseResolveCallback,
promise, isolate); |
| 569 v8::Local<v8::Function> onRejected = createClosure(promiseRejectCallback, pr
omise, isolate); | 569 v8::Local<v8::Function> onRejected = createClosure(promiseRejectCallback, pr
omise, isolate); |
| 570 | 570 |
| 571 for (unsigned i = 0, length = iterable->Length(); i < length; ++i) { | 571 for (unsigned i = 0, length = iterable->Length(); i < length; ++i) { |
| 572 // Array-holes should not be skipped by for-of iteration semantics. | 572 // Array-holes should not be skipped by for-of iteration semantics. |
| 573 V8TRYCATCH_VOID(v8::Local<v8::Value>, nextValue, iterable->Get(i)); | 573 V8TRYCATCH_VOID(v8::Local<v8::Value>, nextValue, iterable->Get(i)); |
| 574 v8::Local<v8::Object> nextPromise = V8PromiseCustom::toPromise(nextValue
, isolate); | 574 v8::Local<v8::Object> nextPromise = V8PromiseCustom::toPromise(nextValue
, isolate); |
| 575 V8PromiseCustom::then(nextPromise, onFulfilled, onRejected, isolate); | 575 V8PromiseCustom::then(nextPromise, onFulfilled, onRejected, isolate); |
| 576 } | 576 } |
| 577 v8SetReturnValue(args, promise); | 577 v8SetReturnValue(info, promise); |
| 578 } | 578 } |
| 579 | 579 |
| 580 void V8Promise::allMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) | 580 void V8Promise::allMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 581 { | 581 { |
| 582 v8::Isolate* isolate = args.GetIsolate(); | 582 v8::Isolate* isolate = info.GetIsolate(); |
| 583 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(args.Holder()
, isolate); | 583 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); |
| 584 v8::Local<v8::Array> results = v8::Array::New(); | 584 v8::Local<v8::Array> results = v8::Array::New(); |
| 585 | 585 |
| 586 if (!args.Length() || !args[0]->IsArray()) { | 586 if (!info.Length() || !info[0]->IsArray()) { |
| 587 V8PromiseCustom::resolve(promise, results, isolate); | 587 V8PromiseCustom::resolve(promise, results, isolate); |
| 588 v8SetReturnValue(args, promise); | 588 v8SetReturnValue(info, promise); |
| 589 return; | 589 return; |
| 590 } | 590 } |
| 591 | 591 |
| 592 // FIXME: Now we limit the iterable type to the Array type. | 592 // FIXME: Now we limit the iterable type to the Array type. |
| 593 v8::Local<v8::Array> iterable = args[0].As<v8::Array>(); | 593 v8::Local<v8::Array> iterable = info[0].As<v8::Array>(); |
| 594 | 594 |
| 595 if (!iterable->Length()) { | 595 if (!iterable->Length()) { |
| 596 V8PromiseCustom::resolve(promise, results, isolate); | 596 V8PromiseCustom::resolve(promise, results, isolate); |
| 597 v8SetReturnValue(args, promise); | 597 v8SetReturnValue(info, promise); |
| 598 return; | 598 return; |
| 599 } | 599 } |
| 600 | 600 |
| 601 v8::Local<v8::ObjectTemplate> objectTemplate = primitiveWrapperObjectTemplat
e(isolate); | 601 v8::Local<v8::ObjectTemplate> objectTemplate = primitiveWrapperObjectTemplat
e(isolate); |
| 602 v8::Local<v8::Object> countdownWrapper = objectTemplate->NewInstance(); | 602 v8::Local<v8::Object> countdownWrapper = objectTemplate->NewInstance(); |
| 603 countdownWrapper->SetInternalField(V8PromiseCustom::PrimitiveWrapperPrimitiv
eIndex, v8::Integer::New(iterable->Length(), isolate)); | 603 countdownWrapper->SetInternalField(V8PromiseCustom::PrimitiveWrapperPrimitiv
eIndex, v8::Integer::New(iterable->Length(), isolate)); |
| 604 | 604 |
| 605 v8::Local<v8::Function> onRejected = createClosure(promiseRejectCallback, pr
omise, isolate); | 605 v8::Local<v8::Function> onRejected = createClosure(promiseRejectCallback, pr
omise, isolate); |
| 606 for (unsigned i = 0, length = iterable->Length(); i < length; ++i) { | 606 for (unsigned i = 0, length = iterable->Length(); i < length; ++i) { |
| 607 // Array-holes should not be skipped by for-of iteration semantics. | 607 // Array-holes should not be skipped by for-of iteration semantics. |
| 608 v8::Local<v8::Object> environment = promiseAllEnvironment(promise, count
downWrapper, i, results, isolate); | 608 v8::Local<v8::Object> environment = promiseAllEnvironment(promise, count
downWrapper, i, results, isolate); |
| 609 v8::Local<v8::Function> onFulfilled = createClosure(promiseAllFulfillCal
lback, environment, isolate); | 609 v8::Local<v8::Function> onFulfilled = createClosure(promiseAllFulfillCal
lback, environment, isolate); |
| 610 V8TRYCATCH_VOID(v8::Local<v8::Value>, nextValue, iterable->Get(i)); | 610 V8TRYCATCH_VOID(v8::Local<v8::Value>, nextValue, iterable->Get(i)); |
| 611 v8::Local<v8::Object> nextPromise = V8PromiseCustom::toPromise(nextValue
, isolate); | 611 v8::Local<v8::Object> nextPromise = V8PromiseCustom::toPromise(nextValue
, isolate); |
| 612 V8PromiseCustom::then(nextPromise, onFulfilled, onRejected, isolate); | 612 V8PromiseCustom::then(nextPromise, onFulfilled, onRejected, isolate); |
| 613 } | 613 } |
| 614 v8SetReturnValue(args, promise); | 614 v8SetReturnValue(info, promise); |
| 615 } | 615 } |
| 616 | 616 |
| 617 // | 617 // |
| 618 // -- V8PromiseCustom -- | 618 // -- V8PromiseCustom -- |
| 619 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea
tionContext, v8::Isolate* isolate) | 619 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea
tionContext, v8::Isolate* isolate) |
| 620 { | 620 { |
| 621 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol
ate); | 621 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol
ate); |
| 622 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); | 622 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); |
| 623 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext,
&V8Promise::wrapperTypeInfo, 0, isolate); | 623 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext,
&V8Promise::wrapperTypeInfo, 0, isolate); |
| 624 | 624 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 } | 795 } |
| 796 | 796 |
| 797 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8:
:Function> handler, v8::Handle<v8::Value> argument, v8::Isolate* isolate) | 797 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8:
:Function> handler, v8::Handle<v8::Value> argument, v8::Isolate* isolate) |
| 798 { | 798 { |
| 799 ExecutionContext* executionContext = getExecutionContext(); | 799 ExecutionContext* executionContext = getExecutionContext(); |
| 800 ASSERT(executionContext && executionContext->isContextThread()); | 800 ASSERT(executionContext && executionContext->isContextThread()); |
| 801 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar
gument, isolate, executionContext))); | 801 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar
gument, isolate, executionContext))); |
| 802 } | 802 } |
| 803 | 803 |
| 804 } // namespace WebCore | 804 } // namespace WebCore |
| OLD | NEW |