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

Side by Side Diff: include/v8.h

Issue 971693002: convert object::* to return maybe values (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 | src/api.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 // 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 template <class T> 427 template <class T>
428 class MaybeLocal { 428 class MaybeLocal {
429 public: 429 public:
430 V8_INLINE MaybeLocal() : val_(nullptr) {} 430 V8_INLINE MaybeLocal() : val_(nullptr) {}
431 template <class S> 431 template <class S>
432 V8_INLINE MaybeLocal(Local<S> that) 432 V8_INLINE MaybeLocal(Local<S> that)
433 : val_(reinterpret_cast<T*>(*that)) { 433 : val_(reinterpret_cast<T*>(*that)) {
434 TYPE_CHECK(T, S); 434 TYPE_CHECK(T, S);
435 } 435 }
436 436
437 V8_INLINE bool IsEmpty() { return val_ == nullptr; } 437 V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
438 438
439 template <class S> 439 template <class S>
440 V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const { 440 V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
441 if (val_ == NULL) { 441 out->val_ = IsEmpty() ? nullptr : this->val_;
442 out->val_ = nullptr; 442 return IsEmpty();
443 return false;
444 } else {
445 out->val_ = this->val_;
446 return true;
447 }
448 } 443 }
449 444
450 V8_INLINE Local<T> ToLocalChecked() { 445 V8_INLINE Local<T> ToLocalChecked() {
451 // TODO(dcarney): add DCHECK. 446 // TODO(dcarney): add DCHECK.
452 return Local<T>(val_); 447 return Local<T>(val_);
453 } 448 }
454 449
450 template <class S>
451 V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
452 return IsEmpty() ? default_value : Local<S>(val_);
453 }
454
455 private: 455 private:
456 T* val_; 456 T* val_;
457 }; 457 };
458 458
459 459
460 // Eternal handles are set-once handles that live for the life of the isolate. 460 // Eternal handles are set-once handles that live for the life of the isolate.
461 template <class T> class Eternal { 461 template <class T> class Eternal {
462 public: 462 public:
463 V8_INLINE Eternal() : index_(kInitialValue) { } 463 V8_INLINE Eternal() : index_(kInitialValue) { }
464 template<class S> 464 template<class S>
(...skipping 2018 matching lines...) Expand 10 before | Expand all | Expand 10 after
2483 ALL_CAN_WRITE = 1 << 1, 2483 ALL_CAN_WRITE = 1 << 1,
2484 PROHIBITS_OVERWRITING = 1 << 2 2484 PROHIBITS_OVERWRITING = 1 << 2
2485 }; 2485 };
2486 2486
2487 2487
2488 /** 2488 /**
2489 * A JavaScript object (ECMA-262, 4.3.3) 2489 * A JavaScript object (ECMA-262, 4.3.3)
2490 */ 2490 */
2491 class V8_EXPORT Object : public Value { 2491 class V8_EXPORT Object : public Value {
2492 public: 2492 public:
2493 // TODO(dcarney): deprecate
2493 bool Set(Handle<Value> key, Handle<Value> value); 2494 bool Set(Handle<Value> key, Handle<Value> value);
2495 Maybe<bool> Set(Local<Context> context, Local<Value> key, Local<Value> value);
2494 2496
2497 // TODO(dcarney): deprecate
2495 bool Set(uint32_t index, Handle<Value> value); 2498 bool Set(uint32_t index, Handle<Value> value);
2499 Maybe<bool> Set(Local<Context> context, uint32_t index, Local<Value> value);
2496 2500
2497 // Sets an own property on this object bypassing interceptors and 2501 // Sets an own property on this object bypassing interceptors and
2498 // overriding accessors or read-only properties. 2502 // overriding accessors or read-only properties.
2499 // 2503 //
2500 // Note that if the object has an interceptor the property will be set 2504 // Note that if the object has an interceptor the property will be set
2501 // locally, but since the interceptor takes precedence the local property 2505 // locally, but since the interceptor takes precedence the local property
2502 // will only be returned if the interceptor doesn't return a value. 2506 // will only be returned if the interceptor doesn't return a value.
2503 // 2507 //
2504 // Note also that this only works for named properties. 2508 // Note also that this only works for named properties.
2509 // TODO(dcarney): deprecate
2505 bool ForceSet(Handle<Value> key, 2510 bool ForceSet(Handle<Value> key,
2506 Handle<Value> value, 2511 Handle<Value> value,
2507 PropertyAttribute attribs = None); 2512 PropertyAttribute attribs = None);
2513 Maybe<bool> ForceSet(Local<Context> context, Local<Value> key,
2514 Local<Value> value, PropertyAttribute attribs = None);
2508 2515
2516 // TODO(dcarney): deprecate
2509 Local<Value> Get(Handle<Value> key); 2517 Local<Value> Get(Handle<Value> key);
2518 MaybeLocal<Value> Get(Local<Context> context, Local<Value> key);
2510 2519
2520 // TODO(dcarney): deprecate
2511 Local<Value> Get(uint32_t index); 2521 Local<Value> Get(uint32_t index);
2522 MaybeLocal<Value> Get(Local<Context> context, uint32_t index);
2512 2523
2513 /** 2524 /**
2514 * Gets the property attributes of a property which can be None or 2525 * Gets the property attributes of a property which can be None or
2515 * any combination of ReadOnly, DontEnum and DontDelete. Returns 2526 * any combination of ReadOnly, DontEnum and DontDelete. Returns
2516 * None when the property doesn't exist. 2527 * None when the property doesn't exist.
2517 */ 2528 */
2529 // TODO(dcarney): deprecate
2518 PropertyAttribute GetPropertyAttributes(Handle<Value> key); 2530 PropertyAttribute GetPropertyAttributes(Handle<Value> key);
2531 Maybe<PropertyAttribute> GetPropertyAttributes(Local<Context> context,
2532 Local<Value> key);
2519 2533
2520 /** 2534 /**
2521 * Returns Object.getOwnPropertyDescriptor as per ES5 section 15.2.3.3. 2535 * Returns Object.getOwnPropertyDescriptor as per ES5 section 15.2.3.3.
2522 */ 2536 */
2537 // TODO(dcarney): deprecate
2523 Local<Value> GetOwnPropertyDescriptor(Local<String> key); 2538 Local<Value> GetOwnPropertyDescriptor(Local<String> key);
2539 MaybeLocal<Value> GetOwnPropertyDescriptor(Local<Context> context,
2540 Local<String> key);
2524 2541
2542 // TODO(dcarney): deprecate
2525 bool Has(Handle<Value> key); 2543 bool Has(Handle<Value> key);
2544 Maybe<bool> Has(Local<Context> context, Local<Value> key);
2526 2545
2546 // TODO(dcarney): deprecate
2527 bool Delete(Handle<Value> key); 2547 bool Delete(Handle<Value> key);
2548 Maybe<bool> Delete(Local<Context> context, Local<Value> key);
2528 2549
2550 // TODO(dcarney): deprecate
2529 bool Has(uint32_t index); 2551 bool Has(uint32_t index);
2552 Maybe<bool> Has(Local<Context> context, uint32_t index);
2530 2553
2554 // TODO(dcarney): deprecate
2531 bool Delete(uint32_t index); 2555 bool Delete(uint32_t index);
2556 Maybe<bool> Delete(Local<Context> context, uint32_t index);
2532 2557
2558 // TODO(dcarney): deprecate
2533 bool SetAccessor(Handle<String> name, 2559 bool SetAccessor(Handle<String> name,
2534 AccessorGetterCallback getter, 2560 AccessorGetterCallback getter,
2535 AccessorSetterCallback setter = 0, 2561 AccessorSetterCallback setter = 0,
2536 Handle<Value> data = Handle<Value>(), 2562 Handle<Value> data = Handle<Value>(),
2537 AccessControl settings = DEFAULT, 2563 AccessControl settings = DEFAULT,
2538 PropertyAttribute attribute = None); 2564 PropertyAttribute attribute = None);
2539 bool SetAccessor(Handle<Name> name, 2565 // TODO(dcarney): deprecate
2540 AccessorNameGetterCallback getter, 2566 bool SetAccessor(Handle<Name> name, AccessorNameGetterCallback getter,
2541 AccessorNameSetterCallback setter = 0, 2567 AccessorNameSetterCallback setter = 0,
2542 Handle<Value> data = Handle<Value>(), 2568 Handle<Value> data = Handle<Value>(),
2543 AccessControl settings = DEFAULT, 2569 AccessControl settings = DEFAULT,
2544 PropertyAttribute attribute = None); 2570 PropertyAttribute attribute = None);
2571 Maybe<bool> SetAccessor(Local<Context> context, Local<Name> name,
2572 AccessorNameGetterCallback getter,
2573 AccessorNameSetterCallback setter = 0,
2574 MaybeLocal<Value> data = MaybeLocal<Value>(),
2575 AccessControl settings = DEFAULT,
2576 PropertyAttribute attribute = None);
2545 2577
2546 void SetAccessorProperty(Local<Name> name, 2578 void SetAccessorProperty(Local<Name> name,
2547 Local<Function> getter, 2579 Local<Function> getter,
2548 Handle<Function> setter = Handle<Function>(), 2580 Handle<Function> setter = Handle<Function>(),
2549 PropertyAttribute attribute = None, 2581 PropertyAttribute attribute = None,
2550 AccessControl settings = DEFAULT); 2582 AccessControl settings = DEFAULT);
2551 2583
2552 /** 2584 /**
2553 * Functionality for private properties. 2585 * Functionality for private properties.
2554 * This is an experimental feature, use at your own risk. 2586 * This is an experimental feature, use at your own risk.
(...skipping 3169 matching lines...) Expand 10 before | Expand all | Expand 10 after
5724 }; 5756 };
5725 5757
5726 5758
5727 /** 5759 /**
5728 * A simple Maybe type, representing an object which may or may not have a 5760 * A simple Maybe type, representing an object which may or may not have a
5729 * value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html. 5761 * value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html.
5730 */ 5762 */
5731 template <class T> 5763 template <class T>
5732 class Maybe { 5764 class Maybe {
5733 public: 5765 public:
5766 V8_INLINE bool IsNothing() const { return !has_value; }
5734 V8_INLINE bool IsJust() const { return has_value; } 5767 V8_INLINE bool IsJust() const { return has_value; }
5735 5768
5736 V8_INLINE T FromJust() const { 5769 V8_INLINE T FromJust() const {
5737 #ifdef V8_ENABLE_CHECKS 5770 #ifdef V8_ENABLE_CHECKS
5738 V8::CheckIsJust(IsJust()); 5771 V8::CheckIsJust(IsJust());
5739 #endif 5772 #endif
5740 return value; 5773 return value;
5741 } 5774 }
5742 5775
5743 V8_INLINE T FromMaybe(const T& default_value) const { 5776 V8_INLINE T FromMaybe(const T& default_value) const {
(...skipping 1907 matching lines...) Expand 10 before | Expand all | Expand 10 after
7651 */ 7684 */
7652 7685
7653 7686
7654 } // namespace v8 7687 } // namespace v8
7655 7688
7656 7689
7657 #undef TYPE_CHECK 7690 #undef TYPE_CHECK
7658 7691
7659 7692
7660 #endif // V8_H_ 7693 #endif // V8_H_
OLDNEW
« 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