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