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 26 matching lines...) Expand all Loading... |
37 #include "bindings/v8/ScopedPersistent.h" | 37 #include "bindings/v8/ScopedPersistent.h" |
38 #include "bindings/v8/ScriptFunctionCall.h" | 38 #include "bindings/v8/ScriptFunctionCall.h" |
39 #include "bindings/v8/ScriptState.h" | 39 #include "bindings/v8/ScriptState.h" |
40 #include "bindings/v8/V8Binding.h" | 40 #include "bindings/v8/V8Binding.h" |
41 #include "bindings/v8/V8PerIsolateData.h" | 41 #include "bindings/v8/V8PerIsolateData.h" |
42 #include "bindings/v8/V8ScriptRunner.h" | 42 #include "bindings/v8/V8ScriptRunner.h" |
43 #include "bindings/v8/WrapperTypeInfo.h" | 43 #include "bindings/v8/WrapperTypeInfo.h" |
44 #include "core/dom/Document.h" | 44 #include "core/dom/Document.h" |
45 #include "core/dom/ExecutionContextTask.h" | 45 #include "core/dom/ExecutionContextTask.h" |
46 #include "core/frame/DOMWindow.h" | 46 #include "core/frame/DOMWindow.h" |
47 #include "core/frame/UseCounter.h" | |
48 #include "core/inspector/InspectorInstrumentation.h" | 47 #include "core/inspector/InspectorInstrumentation.h" |
49 #include "core/workers/WorkerGlobalScope.h" | 48 #include "core/workers/WorkerGlobalScope.h" |
50 #include "platform/Task.h" | 49 #include "platform/Task.h" |
51 #include "wtf/Deque.h" | 50 #include "wtf/Deque.h" |
52 #include "wtf/Functional.h" | 51 #include "wtf/Functional.h" |
53 #include "wtf/Noncopyable.h" | 52 #include "wtf/Noncopyable.h" |
54 #include "wtf/PassOwnPtr.h" | 53 #include "wtf/PassOwnPtr.h" |
55 | 54 |
56 namespace WebCore { | 55 namespace WebCore { |
57 | 56 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 addToDerived(internal, derivedPromise, onFulfilled, onRejected, isolate)
; | 479 addToDerived(internal, derivedPromise, onFulfilled, onRejected, isolate)
; |
481 } | 480 } |
482 } | 481 } |
483 | 482 |
484 } // namespace | 483 } // namespace |
485 | 484 |
486 void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
o) | 485 void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
o) |
487 { | 486 { |
488 v8SetReturnValue(info, v8::Local<v8::Value>()); | 487 v8SetReturnValue(info, v8::Local<v8::Value>()); |
489 v8::Isolate* isolate = info.GetIsolate(); | 488 v8::Isolate* isolate = info.GetIsolate(); |
490 ExecutionContext* executionContext = activeExecutionContext(isolate); | |
491 UseCounter::count(executionContext, UseCounter::PromiseConstructor); | |
492 if (!info.Length() || !info[0]->IsFunction()) { | 489 if (!info.Length() || !info[0]->IsFunction()) { |
493 throwTypeError("Promise constructor takes a function argument", isolate)
; | 490 throwTypeError("Promise constructor takes a function argument", isolate)
; |
494 return; | 491 return; |
495 } | 492 } |
496 v8::Local<v8::Function> init = info[0].As<v8::Function>(); | 493 v8::Local<v8::Function> init = info[0].As<v8::Function>(); |
497 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); | 494 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); |
498 v8::Handle<v8::Value> argv[] = { | 495 v8::Handle<v8::Value> argv[] = { |
499 createClosure(promiseResolveCallback, promise, isolate), | 496 createClosure(promiseResolveCallback, promise, isolate), |
500 createClosure(promiseRejectCallback, promise, isolate) | 497 createClosure(promiseRejectCallback, promise, isolate) |
501 }; | 498 }; |
(...skipping 13 matching lines...) Expand all Loading... |
515 if (info.Length() > 0 && info[0]->IsFunction()) | 512 if (info.Length() > 0 && info[0]->IsFunction()) |
516 onFulfilled = info[0].As<v8::Function>(); | 513 onFulfilled = info[0].As<v8::Function>(); |
517 if (info.Length() > 1 && info[1]->IsFunction()) | 514 if (info.Length() > 1 && info[1]->IsFunction()) |
518 onRejected = info[1].As<v8::Function>(); | 515 onRejected = info[1].As<v8::Function>(); |
519 v8SetReturnValue(info, V8PromiseCustom::then(info.Holder(), onFulfilled, onR
ejected, isolate)); | 516 v8SetReturnValue(info, V8PromiseCustom::then(info.Holder(), onFulfilled, onR
ejected, isolate)); |
520 } | 517 } |
521 | 518 |
522 void V8Promise::castMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info
) | 519 void V8Promise::castMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info
) |
523 { | 520 { |
524 v8::Isolate* isolate = info.GetIsolate(); | 521 v8::Isolate* isolate = info.GetIsolate(); |
525 ExecutionContext* executionContext = activeExecutionContext(isolate); | |
526 UseCounter::count(executionContext, UseCounter::PromiseCast); | |
527 v8::Local<v8::Value> result = v8::Undefined(isolate); | 522 v8::Local<v8::Value> result = v8::Undefined(isolate); |
528 if (info.Length() > 0) | 523 if (info.Length() > 0) |
529 result = info[0]; | 524 result = info[0]; |
530 | 525 |
531 v8SetReturnValue(info, V8PromiseCustom::toPromise(result, isolate)); | 526 v8SetReturnValue(info, V8PromiseCustom::toPromise(result, isolate)); |
532 } | 527 } |
533 | 528 |
534 void V8Promise::catchMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
o) | 529 void V8Promise::catchMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
o) |
535 { | 530 { |
536 v8::Isolate* isolate = info.GetIsolate(); | 531 v8::Isolate* isolate = info.GetIsolate(); |
537 v8::Local<v8::Function> onFulfilled, onRejected; | 532 v8::Local<v8::Function> onFulfilled, onRejected; |
538 | 533 |
539 if (info.Length() > 0 && !info[0]->IsUndefined()) { | 534 if (info.Length() > 0 && !info[0]->IsUndefined()) { |
540 if (!info[0]->IsFunction()) { | 535 if (!info[0]->IsFunction()) { |
541 v8SetReturnValue(info, throwTypeError("onRejected must be a function
or undefined", isolate)); | 536 v8SetReturnValue(info, throwTypeError("onRejected must be a function
or undefined", isolate)); |
542 return; | 537 return; |
543 } | 538 } |
544 onRejected = info[0].As<v8::Function>(); | 539 onRejected = info[0].As<v8::Function>(); |
545 } | 540 } |
546 v8SetReturnValue(info, V8PromiseCustom::then(info.Holder(), onFulfilled, onR
ejected, isolate)); | 541 v8SetReturnValue(info, V8PromiseCustom::then(info.Holder(), onFulfilled, onR
ejected, isolate)); |
547 } | 542 } |
548 | 543 |
549 void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
nfo) | 544 void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
nfo) |
550 { | 545 { |
551 v8::Isolate* isolate = info.GetIsolate(); | 546 v8::Isolate* isolate = info.GetIsolate(); |
552 ExecutionContext* executionContext = activeExecutionContext(isolate); | |
553 UseCounter::count(executionContext, UseCounter::PromiseResolve); | |
554 v8::Local<v8::Value> result = v8::Undefined(isolate); | 547 v8::Local<v8::Value> result = v8::Undefined(isolate); |
555 if (info.Length() > 0) | 548 if (info.Length() > 0) |
556 result = info[0]; | 549 result = info[0]; |
557 | 550 |
558 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); | 551 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); |
559 V8PromiseCustom::resolve(promise, result, isolate); | 552 V8PromiseCustom::resolve(promise, result, isolate); |
560 v8SetReturnValue(info, promise); | 553 v8SetReturnValue(info, promise); |
561 } | 554 } |
562 | 555 |
563 void V8Promise::rejectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& in
fo) | 556 void V8Promise::rejectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& in
fo) |
564 { | 557 { |
565 v8::Isolate* isolate = info.GetIsolate(); | 558 v8::Isolate* isolate = info.GetIsolate(); |
566 ExecutionContext* executionContext = activeExecutionContext(isolate); | |
567 UseCounter::count(executionContext, UseCounter::PromiseReject); | |
568 v8::Local<v8::Value> result = v8::Undefined(isolate); | 559 v8::Local<v8::Value> result = v8::Undefined(isolate); |
569 if (info.Length() > 0) | 560 if (info.Length() > 0) |
570 result = info[0]; | 561 result = info[0]; |
571 | 562 |
572 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); | 563 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder()
, isolate); |
573 V8PromiseCustom::reject(promise, result, isolate); | 564 V8PromiseCustom::reject(promise, result, isolate); |
574 v8SetReturnValue(info, promise); | 565 v8SetReturnValue(info, promise); |
575 } | 566 } |
576 | 567 |
577 void V8Promise::raceMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info
) | 568 void V8Promise::raceMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info
) |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 | 807 |
817 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8:
:Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState
, v8::Isolate* isolate) | 808 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8:
:Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState
, v8::Isolate* isolate) |
818 { | 809 { |
819 ASSERT(originatorState == Fulfilled || originatorState == Rejected); | 810 ASSERT(originatorState == Fulfilled || originatorState == Rejected); |
820 ExecutionContext* executionContext = currentExecutionContext(isolate); | 811 ExecutionContext* executionContext = currentExecutionContext(isolate); |
821 ASSERT(executionContext && executionContext->isContextThread()); | 812 ASSERT(executionContext && executionContext->isContextThread()); |
822 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar
gument, originatorState, isolate, executionContext))); | 813 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar
gument, originatorState, isolate, executionContext))); |
823 } | 814 } |
824 | 815 |
825 } // namespace WebCore | 816 } // namespace WebCore |
OLD | NEW |