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

Unified Diff: include/v8.h

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index c7364b43f64a030a3c4468de3d343cfa5e0002db..12a0b2894dd81d6145680dce990ec48821d23792 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -1412,6 +1412,11 @@ class V8_EXPORT Value : public Data {
*/
bool IsRegExp() const;
+ /**
+ * Returns true if this value is a Promise.
+ * This is an experimental feature.
+ */
+ bool IsPromise() const;
/**
* Returns true if this value is an ArrayBuffer.
@@ -2536,6 +2541,42 @@ class V8_EXPORT Function : public Object {
static void CheckCast(Value* obj);
};
+
+/**
+ * An instance of the built-in Promise constructor (ES6 draft).
+ * This API is experimental. Only works with --harmony flag.
+ */
+class V8_EXPORT Promise : public Object {
+ public:
+ /**
+ * Create a new Promise in pending state.
+ */
+ static Local<Promise> New(Isolate* isolate);
+
+ /**
+ * Resolve/reject a promise with a given value.
+ * Ignored if the promise is not unresolved.
+ */
+ void Resolve(Handle<Value> value);
+ void Reject(Handle<Value> value);
+
+ /**
+ * Register a resolution/rejection handler with a promise.
+ * The handler is given the respective resolution/rejection value as
+ * an argument. If the promise is already resolved/rejected, the handler is
+ * invoked at the end of turn.
+ */
+ Local<Promise> Chain(Handle<Function> handler);
+ Local<Promise> Catch(Handle<Function> handler);
+
+ V8_INLINE static Promise* Cast(Value* obj);
+
+ private:
+ Promise();
+ static void CheckCast(Value* obj);
+};
+
+
#ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
// The number of required internal fields can be defined by embedder.
#define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
@@ -6189,6 +6230,14 @@ Array* Array::Cast(v8::Value* value) {
}
+Promise* Promise::Cast(v8::Value* value) {
+#ifdef V8_ENABLE_CHECKS
+ CheckCast(value);
+#endif
+ return static_cast<Promise*>(value);
+}
+
+
ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698