Chromium Code Reviews| Index: include/v8.h |
| diff --git a/include/v8.h b/include/v8.h |
| index c7364b43f64a030a3c4468de3d343cfa5e0002db..c277719a1da475d121b1204a454a94d5c10ea08b 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. Only works with --harmony flag. |
|
Sven Panne
2014/03/11 11:44:05
Hopefully this works without --harmony, too (and r
rossberg
2014/03/11 16:08:40
Done.
|
| + */ |
| + 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); |
| + |
|
yhirano
2014/03/11 11:46:42
Can we have Then, too?
rossberg
2014/03/11 16:08:40
Will that actually be useful on the API side? (I'm
|
| + /** |
| + * 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); |