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

Side by Side Diff: src/api.cc

Issue 194663003: API support for promises (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Sven's comments 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') | src/bootstrapper.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 2633 matching lines...) Expand 10 before | Expand all | Expand 10 after
2644 2644
2645 2645
2646 void v8::Array::CheckCast(Value* that) { 2646 void v8::Array::CheckCast(Value* that) {
2647 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2647 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2648 Utils::ApiCheck(obj->IsJSArray(), 2648 Utils::ApiCheck(obj->IsJSArray(),
2649 "v8::Array::Cast()", 2649 "v8::Array::Cast()",
2650 "Could not convert to array"); 2650 "Could not convert to array");
2651 } 2651 }
2652 2652
2653 2653
2654 void v8::Promise::CheckCast(Value* that) {
2655 Utils::ApiCheck(that->IsPromise(),
2656 "v8::Promise::Cast()",
2657 "Could not convert to promise");
2658 }
2659
2660
2654 void v8::ArrayBuffer::CheckCast(Value* that) { 2661 void v8::ArrayBuffer::CheckCast(Value* that) {
2655 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2662 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2656 Utils::ApiCheck(obj->IsJSArrayBuffer(), 2663 Utils::ApiCheck(obj->IsJSArrayBuffer(),
2657 "v8::ArrayBuffer::Cast()", 2664 "v8::ArrayBuffer::Cast()",
2658 "Could not convert to ArrayBuffer"); 2665 "Could not convert to ArrayBuffer");
2659 } 2666 }
2660 2667
2661 2668
2662 void v8::ArrayBufferView::CheckCast(Value* that) { 2669 void v8::ArrayBufferView::CheckCast(Value* that) {
2663 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2670 i::Handle<i::Object> obj = Utils::OpenHandle(that);
(...skipping 3060 matching lines...) Expand 10 before | Expand all | Expand 10 after
5724 i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); 5731 i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon));
5725 EXCEPTION_PREAMBLE(isolate); 5732 EXCEPTION_PREAMBLE(isolate);
5726 ENTER_V8(isolate); 5733 ENTER_V8(isolate);
5727 i::Handle<i::JSObject> result = i::JSObject::Copy(paragon_handle); 5734 i::Handle<i::JSObject> result = i::JSObject::Copy(paragon_handle);
5728 has_pending_exception = result.is_null(); 5735 has_pending_exception = result.is_null();
5729 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); 5736 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
5730 return Utils::ToLocal(result); 5737 return Utils::ToLocal(result);
5731 } 5738 }
5732 5739
5733 5740
5741 bool Value::IsPromise() const {
5742 i::Handle<i::Object> val = Utils::OpenHandle(this);
5743 if (!i::FLAG_harmony_promises || !val->IsJSObject()) return false;
5744 i::Handle<i::JSObject> obj = i::Handle<i::JSObject>::cast(val);
5745 i::Isolate* isolate = obj->GetIsolate();
5746 LOG_API(isolate, "IsPromise");
5747 ENTER_V8(isolate);
5748 EXCEPTION_PREAMBLE(isolate);
5749 i::Handle<i::Object> argv[] = { obj };
5750 i::Handle<i::Object> b = i::Execution::Call(
5751 isolate,
5752 handle(
5753 isolate->context()->global_object()->native_context()->is_promise()),
5754 isolate->factory()->undefined_value(),
5755 ARRAY_SIZE(argv), argv,
5756 &has_pending_exception,
5757 false);
5758 EXCEPTION_BAILOUT_CHECK(isolate, false);
5759 return b->BooleanValue();
5760 }
5761
5762
5763 Local<Promise> Promise::New(Isolate* v8_isolate) {
5764 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
5765 LOG_API(isolate, "Promise::New");
5766 ENTER_V8(isolate);
5767 EXCEPTION_PREAMBLE(isolate);
5768 i::Handle<i::Object> result = i::Execution::Call(
5769 isolate,
5770 handle(isolate->context()->global_object()->native_context()->
5771 promise_create()),
5772 isolate->factory()->undefined_value(),
5773 0, NULL,
5774 &has_pending_exception,
5775 false);
5776 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>());
5777 return Local<Promise>::Cast(Utils::ToLocal(result));
5778 }
5779
5780
5781 void Promise::Resolve(Handle<Value> value) {
5782 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5783 i::Isolate* isolate = promise->GetIsolate();
5784 LOG_API(isolate, "Promise::Resolve");
5785 ENTER_V8(isolate);
5786 EXCEPTION_PREAMBLE(isolate);
5787 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
5788 i::Execution::Call(
5789 isolate,
5790 handle(isolate->context()->global_object()->native_context()->
5791 promise_resolve()),
5792 isolate->factory()->undefined_value(),
5793 ARRAY_SIZE(argv), argv,
5794 &has_pending_exception,
5795 false);
5796 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;);
5797 }
5798
5799
5800 void Promise::Reject(Handle<Value> value) {
5801 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5802 i::Isolate* isolate = promise->GetIsolate();
5803 LOG_API(isolate, "Promise::Reject");
5804 ENTER_V8(isolate);
5805 EXCEPTION_PREAMBLE(isolate);
5806 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
5807 i::Execution::Call(
5808 isolate,
5809 handle(isolate->context()->global_object()->native_context()->
5810 promise_reject()),
5811 isolate->factory()->undefined_value(),
5812 ARRAY_SIZE(argv), argv,
5813 &has_pending_exception,
5814 false);
5815 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;);
5816 }
5817
5818
5819 Local<Promise> Promise::Chain(Handle<Function> handler) {
5820 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5821 i::Isolate* isolate = promise->GetIsolate();
5822 LOG_API(isolate, "Promise::Chain");
5823 ENTER_V8(isolate);
5824 EXCEPTION_PREAMBLE(isolate);
5825 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
5826 i::Handle<i::Object> result = i::Execution::Call(
5827 isolate,
5828 handle(isolate->context()->global_object()->native_context()->
5829 promise_chain()),
5830 promise,
5831 ARRAY_SIZE(argv), argv,
5832 &has_pending_exception,
5833 false);
5834 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>());
5835 return Local<Promise>::Cast(Utils::ToLocal(result));
5836 }
5837
5838
5839 Local<Promise> Promise::Catch(Handle<Function> handler) {
5840 i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5841 i::Isolate* isolate = promise->GetIsolate();
5842 LOG_API(isolate, "Promise::Catch");
5843 ENTER_V8(isolate);
5844 EXCEPTION_PREAMBLE(isolate);
5845 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
5846 i::Handle<i::Object> result = i::Execution::Call(
5847 isolate,
5848 handle(isolate->context()->global_object()->native_context()->
5849 promise_catch()),
5850 promise,
5851 ARRAY_SIZE(argv), argv,
5852 &has_pending_exception,
5853 false);
5854 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>());
5855 return Local<Promise>::Cast(Utils::ToLocal(result));
5856 }
5857
5858
5734 bool v8::ArrayBuffer::IsExternal() const { 5859 bool v8::ArrayBuffer::IsExternal() const {
5735 return Utils::OpenHandle(this)->is_external(); 5860 return Utils::OpenHandle(this)->is_external();
5736 } 5861 }
5737 5862
5738 5863
5739 v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() { 5864 v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() {
5740 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); 5865 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
5741 Utils::ApiCheck(!obj->is_external(), 5866 Utils::ApiCheck(!obj->is_external(),
5742 "v8::ArrayBuffer::Externalize", 5867 "v8::ArrayBuffer::Externalize",
5743 "ArrayBuffer already externalized"); 5868 "ArrayBuffer already externalized");
(...skipping 1586 matching lines...) Expand 10 before | Expand all | Expand 10 after
7330 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7455 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7331 Address callback_address = 7456 Address callback_address =
7332 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7457 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7333 VMState<EXTERNAL> state(isolate); 7458 VMState<EXTERNAL> state(isolate);
7334 ExternalCallbackScope call_scope(isolate, callback_address); 7459 ExternalCallbackScope call_scope(isolate, callback_address);
7335 callback(info); 7460 callback(info);
7336 } 7461 }
7337 7462
7338 7463
7339 } } // namespace v8::internal 7464 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698