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

Side by Side Diff: include/v8.h

Issue 962983002: Convert v8::Value::To* to use MaybeLocal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | include/v8config.h » ('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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** \mainpage V8 API Reference Guide 5 /** \mainpage V8 API Reference Guide
6 * 6 *
7 * V8 is Google's open source JavaScript engine. 7 * V8 is Google's open source JavaScript engine.
8 * 8 *
9 * This set of documents provides reference material generated from the 9 * This set of documents provides reference material generated from the
10 * V8 header file, include/v8.h. 10 * V8 header file, include/v8.h.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 class String; 99 class String;
100 class StringObject; 100 class StringObject;
101 class Symbol; 101 class Symbol;
102 class SymbolObject; 102 class SymbolObject;
103 class Private; 103 class Private;
104 class Uint32; 104 class Uint32;
105 class Utils; 105 class Utils;
106 class Value; 106 class Value;
107 template <class T> class Handle; 107 template <class T> class Handle;
108 template <class T> class Local; 108 template <class T> class Local;
109 template <class T>
110 class MaybeLocal;
109 template <class T> class Eternal; 111 template <class T> class Eternal;
110 template<class T> class NonCopyablePersistentTraits; 112 template<class T> class NonCopyablePersistentTraits;
111 template<class T> class PersistentBase; 113 template<class T> class PersistentBase;
112 template<class T, 114 template<class T,
113 class M = NonCopyablePersistentTraits<T> > class Persistent; 115 class M = NonCopyablePersistentTraits<T> > class Persistent;
114 template<class T> class UniquePersistent; 116 template<class T> class UniquePersistent;
115 template<class K, class V, class T> class PersistentValueMap; 117 template<class K, class V, class T> class PersistentValueMap;
116 template <class K, class V, class T> 118 template <class K, class V, class T>
117 class PersistentValueMapBase; 119 class PersistentValueMapBase;
118 template <class K, class V, class T> 120 template <class K, class V, class T>
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 const PersistentBase<T>& that) { 317 const PersistentBase<T>& that) {
316 return New(isolate, that.val_); 318 return New(isolate, that.val_);
317 } 319 }
318 320
319 private: 321 private:
320 friend class Utils; 322 friend class Utils;
321 template<class F, class M> friend class Persistent; 323 template<class F, class M> friend class Persistent;
322 template<class F> friend class PersistentBase; 324 template<class F> friend class PersistentBase;
323 template<class F> friend class Handle; 325 template<class F> friend class Handle;
324 template<class F> friend class Local; 326 template<class F> friend class Local;
327 template <class F>
328 friend class MaybeLocal;
325 template<class F> friend class FunctionCallbackInfo; 329 template<class F> friend class FunctionCallbackInfo;
326 template<class F> friend class PropertyCallbackInfo; 330 template<class F> friend class PropertyCallbackInfo;
327 template<class F> friend class internal::CustomArguments; 331 template<class F> friend class internal::CustomArguments;
328 friend Handle<Primitive> Undefined(Isolate* isolate); 332 friend Handle<Primitive> Undefined(Isolate* isolate);
329 friend Handle<Primitive> Null(Isolate* isolate); 333 friend Handle<Primitive> Null(Isolate* isolate);
330 friend Handle<Boolean> True(Isolate* isolate); 334 friend Handle<Boolean> True(Isolate* isolate);
331 friend Handle<Boolean> False(Isolate* isolate); 335 friend Handle<Boolean> False(Isolate* isolate);
332 friend class Context; 336 friend class Context;
333 friend class HandleScope; 337 friend class HandleScope;
334 friend class Object; 338 friend class Object;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 V8_INLINE static Local<T> New(Isolate* isolate, 396 V8_INLINE static Local<T> New(Isolate* isolate,
393 const PersistentBase<T>& that); 397 const PersistentBase<T>& that);
394 398
395 private: 399 private:
396 friend class Utils; 400 friend class Utils;
397 template<class F> friend class Eternal; 401 template<class F> friend class Eternal;
398 template<class F> friend class PersistentBase; 402 template<class F> friend class PersistentBase;
399 template<class F, class M> friend class Persistent; 403 template<class F, class M> friend class Persistent;
400 template<class F> friend class Handle; 404 template<class F> friend class Handle;
401 template<class F> friend class Local; 405 template<class F> friend class Local;
406 template <class F>
407 friend class MaybeLocal;
402 template<class F> friend class FunctionCallbackInfo; 408 template<class F> friend class FunctionCallbackInfo;
403 template<class F> friend class PropertyCallbackInfo; 409 template<class F> friend class PropertyCallbackInfo;
404 friend class String; 410 friend class String;
405 friend class Object; 411 friend class Object;
406 friend class Context; 412 friend class Context;
407 template<class F> friend class internal::CustomArguments; 413 template<class F> friend class internal::CustomArguments;
408 friend class HandleScope; 414 friend class HandleScope;
409 friend class EscapableHandleScope; 415 friend class EscapableHandleScope;
410 template <class F1, class F2, class F3> 416 template <class F1, class F2, class F3>
411 friend class PersistentValueMapBase; 417 friend class PersistentValueMapBase;
412 template<class F1, class F2> friend class PersistentValueVector; 418 template<class F1, class F2> friend class PersistentValueVector;
413 419
414 template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { } 420 template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { }
415 V8_INLINE static Local<T> New(Isolate* isolate, T* that); 421 V8_INLINE static Local<T> New(Isolate* isolate, T* that);
416 }; 422 };
417 423
418 424
425 template <class T>
426 class MaybeLocal {
427 public:
428 V8_INLINE MaybeLocal() : val_(nullptr) {}
429 template <class S>
430 V8_INLINE MaybeLocal(Local<S> that)
431 : val_(reinterpret_cast<T*>(*that)) {
432 TYPE_CHECK(T, S);
433 }
434
435 V8_INLINE bool IsEmpty() { return val_ == nullptr; }
436
437 template <class S>
438 V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
439 if (val_ == NULL) {
440 out->val_ = nullptr;
441 return false;
442 } else {
443 out->val_ = this->val_;
444 return true;
445 }
446 }
447
448 V8_INLINE Local<T> ToLocalChecked() {
449 // TODO(dcarney): add DCHECK.
450 return Local<T>(val_);
451 }
452
453 private:
454 T* val_;
455 };
456
457
419 // Eternal handles are set-once handles that live for the life of the isolate. 458 // Eternal handles are set-once handles that live for the life of the isolate.
420 template <class T> class Eternal { 459 template <class T> class Eternal {
421 public: 460 public:
422 V8_INLINE Eternal() : index_(kInitialValue) { } 461 V8_INLINE Eternal() : index_(kInitialValue) { }
423 template<class S> 462 template<class S>
424 V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) { 463 V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) {
425 Set(isolate, handle); 464 Set(isolate, handle);
426 } 465 }
427 // Can only be safely called if already set. 466 // Can only be safely called if already set.
428 V8_INLINE Local<T> Get(Isolate* isolate); 467 V8_INLINE Local<T> Get(Isolate* isolate);
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 * This is an experimental feature. 1879 * This is an experimental feature.
1841 */ 1880 */
1842 bool IsFloat64Array() const; 1881 bool IsFloat64Array() const;
1843 1882
1844 /** 1883 /**
1845 * Returns true if this value is a DataView. 1884 * Returns true if this value is a DataView.
1846 * This is an experimental feature. 1885 * This is an experimental feature.
1847 */ 1886 */
1848 bool IsDataView() const; 1887 bool IsDataView() const;
1849 1888
1889 MaybeLocal<Boolean> ToBoolean(Local<Context> context) const;
1890 MaybeLocal<Number> ToNumber(Local<Context> context) const;
1891 MaybeLocal<String> ToString(Local<Context> context) const;
1892 MaybeLocal<String> ToDetailString(Local<Context> context) const;
1893 MaybeLocal<Object> ToObject(Local<Context> context) const;
1894 MaybeLocal<Integer> ToInteger(Local<Context> context) const;
1895 MaybeLocal<Uint32> ToUint32(Local<Context> context) const;
1896 MaybeLocal<Int32> ToInt32(Local<Context> context) const;
1897
1898 // TODO(dcarney): deprecate all these.
1850 Local<Boolean> ToBoolean(Isolate* isolate) const; 1899 Local<Boolean> ToBoolean(Isolate* isolate) const;
1851 Local<Number> ToNumber(Isolate* isolate) const; 1900 Local<Number> ToNumber(Isolate* isolate) const;
1852 Local<String> ToString(Isolate* isolate) const; 1901 Local<String> ToString(Isolate* isolate) const;
1853 Local<String> ToDetailString(Isolate* isolate) const; 1902 Local<String> ToDetailString(Isolate* isolate) const;
1854 Local<Object> ToObject(Isolate* isolate) const; 1903 Local<Object> ToObject(Isolate* isolate) const;
1855 Local<Integer> ToInteger(Isolate* isolate) const; 1904 Local<Integer> ToInteger(Isolate* isolate) const;
1856 Local<Uint32> ToUint32(Isolate* isolate) const; 1905 Local<Uint32> ToUint32(Isolate* isolate) const;
1857 Local<Int32> ToInt32(Isolate* isolate) const; 1906 Local<Int32> ToInt32(Isolate* isolate) const;
1858 1907
1859 // TODO(dcarney): deprecate all these. 1908 // TODO(dcarney): deprecate all these as well.
1860 inline Local<Boolean> ToBoolean() const; 1909 inline Local<Boolean> ToBoolean() const;
1861 inline Local<Number> ToNumber() const; 1910 inline Local<Number> ToNumber() const;
1862 inline Local<String> ToString() const; 1911 inline Local<String> ToString() const;
1863 inline Local<String> ToDetailString() const; 1912 inline Local<String> ToDetailString() const;
1864 inline Local<Object> ToObject() const; 1913 inline Local<Object> ToObject() const;
1865 inline Local<Integer> ToInteger() const; 1914 inline Local<Integer> ToInteger() const;
1866 inline Local<Uint32> ToUint32() const; 1915 inline Local<Uint32> ToUint32() const;
1867 inline Local<Int32> ToInt32() const; 1916 inline Local<Int32> ToInt32() const;
1868 1917
1869 /** 1918 /**
(...skipping 5686 matching lines...) Expand 10 before | Expand all | Expand 10 after
7556 */ 7605 */
7557 7606
7558 7607
7559 } // namespace v8 7608 } // namespace v8
7560 7609
7561 7610
7562 #undef TYPE_CHECK 7611 #undef TYPE_CHECK
7563 7612
7564 7613
7565 #endif // V8_H_ 7614 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | include/v8config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698