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

Side by Side Diff: Source/bindings/v8/custom/V8PromiseCustom.cpp

Issue 166173002: Count Promise constructor callings. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 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) 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
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
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 ASSERT(executionContext);
haraken 2014/02/14 07:21:39 Remove this ASSERT. This should be always non NULL
yhirano 2014/02/14 07:37:55 Done.
492 String consoleMessage("Promise API is changing and this function might be af fected.");
493 executionContext->addConsoleMessage(JSMessageSource, WarningMessageLevel, co nsoleMessage);
494 UseCounter::count(executionContext, UseCounter::PromiseConstructor);
489 if (!info.Length() || !info[0]->IsFunction()) { 495 if (!info.Length() || !info[0]->IsFunction()) {
490 throwTypeError("Promise constructor takes a function argument", isolate) ; 496 throwTypeError("Promise constructor takes a function argument", isolate) ;
491 return; 497 return;
492 } 498 }
493 v8::Local<v8::Function> init = info[0].As<v8::Function>(); 499 v8::Local<v8::Function> init = info[0].As<v8::Function>();
494 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate); 500 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate);
495 v8::Handle<v8::Value> argv[] = { 501 v8::Handle<v8::Value> argv[] = {
496 createClosure(promiseResolveCallback, promise, isolate), 502 createClosure(promiseResolveCallback, promise, isolate),
497 createClosure(promiseRejectCallback, promise, isolate) 503 createClosure(promiseRejectCallback, promise, isolate)
498 }; 504 };
(...skipping 13 matching lines...) Expand all
512 if (info.Length() > 0 && info[0]->IsFunction()) 518 if (info.Length() > 0 && info[0]->IsFunction())
513 onFulfilled = info[0].As<v8::Function>(); 519 onFulfilled = info[0].As<v8::Function>();
514 if (info.Length() > 1 && info[1]->IsFunction()) 520 if (info.Length() > 1 && info[1]->IsFunction())
515 onRejected = info[1].As<v8::Function>(); 521 onRejected = info[1].As<v8::Function>();
516 v8SetReturnValue(info, V8PromiseCustom::then(info.Holder(), onFulfilled, onR ejected, isolate)); 522 v8SetReturnValue(info, V8PromiseCustom::then(info.Holder(), onFulfilled, onR ejected, isolate));
517 } 523 }
518 524
519 void V8Promise::castMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info ) 525 void V8Promise::castMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info )
520 { 526 {
521 v8::Isolate* isolate = info.GetIsolate(); 527 v8::Isolate* isolate = info.GetIsolate();
528 ExecutionContext* executionContext = activeExecutionContext(isolate);
529 ASSERT(executionContext);
530 String consoleMessage("Promise API is changing and this function might be af fected.");
531 executionContext->addConsoleMessage(JSMessageSource, WarningMessageLevel, co nsoleMessage);
532 UseCounter::count(executionContext, UseCounter::PromiseCast);
522 v8::Local<v8::Value> result = v8::Undefined(isolate); 533 v8::Local<v8::Value> result = v8::Undefined(isolate);
523 if (info.Length() > 0) 534 if (info.Length() > 0)
524 result = info[0]; 535 result = info[0];
525 536
526 v8SetReturnValue(info, V8PromiseCustom::toPromise(result, isolate)); 537 v8SetReturnValue(info, V8PromiseCustom::toPromise(result, isolate));
527 } 538 }
528 539
529 void V8Promise::catchMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& inf o) 540 void V8Promise::catchMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& inf o)
530 { 541 {
531 v8::Isolate* isolate = info.GetIsolate(); 542 v8::Isolate* isolate = info.GetIsolate();
532 v8::Local<v8::Function> onFulfilled, onRejected; 543 v8::Local<v8::Function> onFulfilled, onRejected;
533 544
534 if (info.Length() > 0 && !info[0]->IsUndefined()) { 545 if (info.Length() > 0 && !info[0]->IsUndefined()) {
535 if (!info[0]->IsFunction()) { 546 if (!info[0]->IsFunction()) {
536 v8SetReturnValue(info, throwTypeError("onRejected must be a function or undefined", isolate)); 547 v8SetReturnValue(info, throwTypeError("onRejected must be a function or undefined", isolate));
537 return; 548 return;
538 } 549 }
539 onRejected = info[0].As<v8::Function>(); 550 onRejected = info[0].As<v8::Function>();
540 } 551 }
541 v8SetReturnValue(info, V8PromiseCustom::then(info.Holder(), onFulfilled, onR ejected, isolate)); 552 v8SetReturnValue(info, V8PromiseCustom::then(info.Holder(), onFulfilled, onR ejected, isolate));
542 } 553 }
543 554
544 void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i nfo) 555 void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i nfo)
545 { 556 {
546 v8::Isolate* isolate = info.GetIsolate(); 557 v8::Isolate* isolate = info.GetIsolate();
558 ExecutionContext* executionContext = activeExecutionContext(isolate);
559 ASSERT(executionContext);
560 String consoleMessage("Promise API is changing and this function might be af fected.");
561 executionContext->addConsoleMessage(JSMessageSource, WarningMessageLevel, co nsoleMessage);
562 UseCounter::count(executionContext, UseCounter::PromiseResolve);
547 v8::Local<v8::Value> result = v8::Undefined(isolate); 563 v8::Local<v8::Value> result = v8::Undefined(isolate);
548 if (info.Length() > 0) 564 if (info.Length() > 0)
549 result = info[0]; 565 result = info[0];
550 566
551 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate); 567 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate);
552 V8PromiseCustom::resolve(promise, result, isolate); 568 V8PromiseCustom::resolve(promise, result, isolate);
553 v8SetReturnValue(info, promise); 569 v8SetReturnValue(info, promise);
554 } 570 }
555 571
556 void V8Promise::rejectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& in fo) 572 void V8Promise::rejectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& in fo)
557 { 573 {
558 v8::Isolate* isolate = info.GetIsolate(); 574 v8::Isolate* isolate = info.GetIsolate();
575 ExecutionContext* executionContext = activeExecutionContext(isolate);
576 ASSERT(executionContext);
577 String consoleMessage("Promise API is changing and this function might be af fected.");
578 executionContext->addConsoleMessage(JSMessageSource, WarningMessageLevel, co nsoleMessage);
579 UseCounter::count(executionContext, UseCounter::PromiseReject);
559 v8::Local<v8::Value> result = v8::Undefined(isolate); 580 v8::Local<v8::Value> result = v8::Undefined(isolate);
560 if (info.Length() > 0) 581 if (info.Length() > 0)
561 result = info[0]; 582 result = info[0];
562 583
563 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate); 584 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate);
564 V8PromiseCustom::reject(promise, result, isolate); 585 V8PromiseCustom::reject(promise, result, isolate);
565 v8SetReturnValue(info, promise); 586 v8SetReturnValue(info, promise);
566 } 587 }
567 588
568 void V8Promise::raceMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info ) 589 void V8Promise::raceMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info )
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 828
808 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8: :Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState , v8::Isolate* isolate) 829 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8: :Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState , v8::Isolate* isolate)
809 { 830 {
810 ASSERT(originatorState == Fulfilled || originatorState == Rejected); 831 ASSERT(originatorState == Fulfilled || originatorState == Rejected);
811 ExecutionContext* executionContext = currentExecutionContext(isolate); 832 ExecutionContext* executionContext = currentExecutionContext(isolate);
812 ASSERT(executionContext && executionContext->isContextThread()); 833 ASSERT(executionContext && executionContext->isContextThread());
813 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar gument, originatorState, isolate, executionContext))); 834 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar gument, originatorState, isolate, executionContext)));
814 } 835 }
815 836
816 } // namespace WebCore 837 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/fast/js/Promise-then-without-callbacks-in-workers-expected.txt ('k') | Source/core/frame/UseCounter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698