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

Side by Side Diff: src/api.cc

Issue 196943014: Split Promise API into Promise/Resolver (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2640 matching lines...) Expand 10 before | Expand all | Expand 10 after
2651 } 2651 }
2652 2652
2653 2653
2654 void v8::Promise::CheckCast(Value* that) { 2654 void v8::Promise::CheckCast(Value* that) {
2655 Utils::ApiCheck(that->IsPromise(), 2655 Utils::ApiCheck(that->IsPromise(),
2656 "v8::Promise::Cast()", 2656 "v8::Promise::Cast()",
2657 "Could not convert to promise"); 2657 "Could not convert to promise");
2658 } 2658 }
2659 2659
2660 2660
2661 void v8::Promise::Resolver::CheckCast(Value* that) {
2662 Utils::ApiCheck(that->IsPromise(),
2663 "v8::Promise::Resolver::Cast()",
2664 "Could not convert to promise resolver");
2665 }
2666
2667
2661 void v8::ArrayBuffer::CheckCast(Value* that) { 2668 void v8::ArrayBuffer::CheckCast(Value* that) {
2662 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2669 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2663 Utils::ApiCheck(obj->IsJSArrayBuffer(), 2670 Utils::ApiCheck(obj->IsJSArrayBuffer(),
2664 "v8::ArrayBuffer::Cast()", 2671 "v8::ArrayBuffer::Cast()",
2665 "Could not convert to ArrayBuffer"); 2672 "Could not convert to ArrayBuffer");
2666 } 2673 }
2667 2674
2668 2675
2669 void v8::ArrayBufferView::CheckCast(Value* that) { 2676 void v8::ArrayBufferView::CheckCast(Value* that) {
2670 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2677 i::Handle<i::Object> obj = Utils::OpenHandle(that);
(...skipping 3083 matching lines...) Expand 10 before | Expand all | Expand 10 after
5754 isolate->context()->global_object()->native_context()->is_promise()), 5761 isolate->context()->global_object()->native_context()->is_promise()),
5755 isolate->factory()->undefined_value(), 5762 isolate->factory()->undefined_value(),
5756 ARRAY_SIZE(argv), argv, 5763 ARRAY_SIZE(argv), argv,
5757 &has_pending_exception, 5764 &has_pending_exception,
5758 false); 5765 false);
5759 EXCEPTION_BAILOUT_CHECK(isolate, false); 5766 EXCEPTION_BAILOUT_CHECK(isolate, false);
5760 return b->BooleanValue(); 5767 return b->BooleanValue();
5761 } 5768 }
5762 5769
5763 5770
5764 Local<Promise> Promise::New(Isolate* v8_isolate) { 5771 Local<Promise::Resolver> Promise::Resolver::New(Isolate* v8_isolate) {
5765 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 5772 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
5766 LOG_API(isolate, "Promise::New"); 5773 LOG_API(isolate, "Promise::Resolver::New");
5767 ENTER_V8(isolate); 5774 ENTER_V8(isolate);
5768 EXCEPTION_PREAMBLE(isolate); 5775 EXCEPTION_PREAMBLE(isolate);
5769 i::Handle<i::Object> result = i::Execution::Call( 5776 i::Handle<i::Object> result = i::Execution::Call(
5770 isolate, 5777 isolate,
5771 handle(isolate->context()->global_object()->native_context()-> 5778 handle(isolate->context()->global_object()->native_context()->
5772 promise_create()), 5779 promise_create()),
5773 isolate->factory()->undefined_value(), 5780 isolate->factory()->undefined_value(),
5774 0, NULL, 5781 0, NULL,
5775 &has_pending_exception, 5782 &has_pending_exception,
5776 false); 5783 false);
5777 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>()); 5784 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise::Resolver>());
5778 return Local<Promise>::Cast(Utils::ToLocal(result)); 5785 return Local<Promise::Resolver>::Cast(Utils::ToLocal(result));
5779 } 5786 }
5780 5787
5781 5788
5782 void Promise::Resolve(Handle<Value> value) { 5789 Local<Promise> Promise::Resolver::GetPromise() {
5790 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5791 return Local<Promise>::Cast(Utils::ToLocal(promise));
5792 }
5793
5794
5795 void Promise::Resolver::Resolve(Handle<Value> value) {
5783 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); 5796 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5784 i::Isolate* isolate = promise->GetIsolate(); 5797 i::Isolate* isolate = promise->GetIsolate();
5785 LOG_API(isolate, "Promise::Resolve"); 5798 LOG_API(isolate, "Promise::Resolver::Resolve");
5786 ENTER_V8(isolate); 5799 ENTER_V8(isolate);
5787 EXCEPTION_PREAMBLE(isolate); 5800 EXCEPTION_PREAMBLE(isolate);
5788 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) }; 5801 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
5789 i::Execution::Call( 5802 i::Execution::Call(
5790 isolate, 5803 isolate,
5791 handle(isolate->context()->global_object()->native_context()-> 5804 handle(isolate->context()->global_object()->native_context()->
5792 promise_resolve()), 5805 promise_resolve()),
5793 isolate->factory()->undefined_value(), 5806 isolate->factory()->undefined_value(),
5794 ARRAY_SIZE(argv), argv, 5807 ARRAY_SIZE(argv), argv,
5795 &has_pending_exception, 5808 &has_pending_exception,
5796 false); 5809 false);
5797 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;); 5810 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;);
5798 } 5811 }
5799 5812
5800 5813
5801 void Promise::Reject(Handle<Value> value) { 5814 void Promise::Resolver::Reject(Handle<Value> value) {
5802 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); 5815 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5803 i::Isolate* isolate = promise->GetIsolate(); 5816 i::Isolate* isolate = promise->GetIsolate();
5804 LOG_API(isolate, "Promise::Reject"); 5817 LOG_API(isolate, "Promise::Resolver::Reject");
5805 ENTER_V8(isolate); 5818 ENTER_V8(isolate);
5806 EXCEPTION_PREAMBLE(isolate); 5819 EXCEPTION_PREAMBLE(isolate);
5807 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) }; 5820 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
5808 i::Execution::Call( 5821 i::Execution::Call(
5809 isolate, 5822 isolate,
5810 handle(isolate->context()->global_object()->native_context()-> 5823 handle(isolate->context()->global_object()->native_context()->
5811 promise_reject()), 5824 promise_reject()),
5812 isolate->factory()->undefined_value(), 5825 isolate->factory()->undefined_value(),
5813 ARRAY_SIZE(argv), argv, 5826 ARRAY_SIZE(argv), argv,
5814 &has_pending_exception, 5827 &has_pending_exception,
(...skipping 1651 matching lines...) Expand 10 before | Expand all | Expand 10 after
7466 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7479 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7467 Address callback_address = 7480 Address callback_address =
7468 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7481 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7469 VMState<EXTERNAL> state(isolate); 7482 VMState<EXTERNAL> state(isolate);
7470 ExternalCallbackScope call_scope(isolate, callback_address); 7483 ExternalCallbackScope call_scope(isolate, callback_address);
7471 callback(info); 7484 callback(info);
7472 } 7485 }
7473 7486
7474 7487
7475 } } // namespace v8::internal 7488 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698