Chromium Code Reviews| Index: include/v8.h |
| diff --git a/include/v8.h b/include/v8.h |
| index eb6ed211353b446a073cdbb26ce10baae1205e61..dd0047dcf61ade4d244378e9736c8f64c7ad8bfe 100644 |
| --- a/include/v8.h |
| +++ b/include/v8.h |
| @@ -106,6 +106,8 @@ class Utils; |
| class Value; |
| template <class T> class Handle; |
| template <class T> class Local; |
| +template <class T> |
| +class MaybeLocal; |
| template <class T> class Eternal; |
| template<class T> class NonCopyablePersistentTraits; |
| template<class T> class PersistentBase; |
| @@ -322,6 +324,8 @@ template <class T> class Handle { |
| template<class F> friend class PersistentBase; |
| template<class F> friend class Handle; |
| template<class F> friend class Local; |
| + template <class F> |
| + friend class MaybeLocal; |
| template<class F> friend class FunctionCallbackInfo; |
| template<class F> friend class PropertyCallbackInfo; |
| template<class F> friend class internal::CustomArguments; |
| @@ -399,6 +403,8 @@ template <class T> class Local : public Handle<T> { |
| template<class F, class M> friend class Persistent; |
| template<class F> friend class Handle; |
| template<class F> friend class Local; |
| + template <class F> |
| + friend class MaybeLocal; |
| template<class F> friend class FunctionCallbackInfo; |
| template<class F> friend class PropertyCallbackInfo; |
| friend class String; |
| @@ -416,6 +422,39 @@ template <class T> class Local : public Handle<T> { |
| }; |
| +template <class T> |
| +class MaybeLocal { |
| + public: |
| + V8_INLINE MaybeLocal() : val_(nullptr) {} |
| + template <class S> |
| + V8_INLINE MaybeLocal(Local<S> that) |
| + : val_(reinterpret_cast<T*>(*that)) { |
| + TYPE_CHECK(T, S); |
| + } |
| + |
| + V8_INLINE bool IsEmpty() { return val_ == nullptr; } |
| + |
| + template <class S> |
| + V8_INLINE bool ToLocal(Local<S>* out) const { |
|
jochen (gone - plz use gerrit)
2015/02/27 09:42:49
can we mark this as must use result?
dcarney
2015/02/27 09:49:50
Done.
|
| + if (val_ == NULL) { |
| + out->val_ = nullptr; |
| + return false; |
| + } else { |
| + out->val_ = this->val_; |
| + return true; |
| + } |
| + } |
| + |
| + V8_INLINE Local<T> ToLocalChecked() { |
| + // TODO(dcarney): add DCHECK. |
| + return Local<T>(val_); |
| + } |
| + |
| + private: |
| + T* val_; |
| +}; |
| + |
| + |
| // Eternal handles are set-once handles that live for the life of the isolate. |
| template <class T> class Eternal { |
| public: |
| @@ -1847,6 +1886,16 @@ class V8_EXPORT Value : public Data { |
| */ |
| bool IsDataView() const; |
| + MaybeLocal<Boolean> ToBoolean(Local<Context> context) const; |
| + MaybeLocal<Number> ToNumber(Local<Context> context) const; |
| + MaybeLocal<String> ToString(Local<Context> context) const; |
| + MaybeLocal<String> ToDetailString(Local<Context> context) const; |
| + MaybeLocal<Object> ToObject(Local<Context> context) const; |
| + MaybeLocal<Integer> ToInteger(Local<Context> context) const; |
| + MaybeLocal<Uint32> ToUint32(Local<Context> context) const; |
| + MaybeLocal<Int32> ToInt32(Local<Context> context) const; |
| + |
| + // TODO(dcarney): deprecate all these. |
| Local<Boolean> ToBoolean(Isolate* isolate) const; |
| Local<Number> ToNumber(Isolate* isolate) const; |
| Local<String> ToString(Isolate* isolate) const; |
| @@ -1856,7 +1905,7 @@ class V8_EXPORT Value : public Data { |
| Local<Uint32> ToUint32(Isolate* isolate) const; |
| Local<Int32> ToInt32(Isolate* isolate) const; |
| - // TODO(dcarney): deprecate all these. |
| + // TODO(dcarney): deprecate all these as well. |
| inline Local<Boolean> ToBoolean() const; |
| inline Local<Number> ToNumber() const; |
| inline Local<String> ToString() const; |