[api] Add Check method to Maybe
This new method returns no value and just verifies that the Maybe is not Empty. This is intended to be used for functions like Object::Set that return a Maybe<bool> but only use "emptiness" to indicate its result and where ToLocalChecked() appears to be discarding information. Also comments Object::Set to indicate that Check() is the preferred way of asserting that the Set should always succeed. R=yangguo Bug: v8:8562 Change-Id: Ic3b45e42fa9ba0b53f1a764660a56041e64f087b Reviewed-on: https://chromium-review.googlesource.com/c/1414912 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Dan Elphick <delphick@chromium.org> Cr-Commit-Position: refs/heads/master@{#58852}
This commit is contained in:
parent
4f261e9a59
commit
b121cde901
12
include/v8.h
12
include/v8.h
@ -3217,6 +3217,10 @@ class V8_EXPORT Object : public Value {
|
||||
public:
|
||||
V8_DEPRECATE_SOON("Use maybe version",
|
||||
bool Set(Local<Value> key, Local<Value> value));
|
||||
/**
|
||||
* Set only return Just(true) or Empty(), so if it should never fail, use
|
||||
* result.Check().
|
||||
*/
|
||||
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
|
||||
Local<Value> key, Local<Value> value);
|
||||
|
||||
@ -8716,6 +8720,14 @@ class Maybe {
|
||||
*/
|
||||
V8_INLINE T ToChecked() const { return FromJust(); }
|
||||
|
||||
/**
|
||||
* Short-hand for ToChecked(), which doesn't return a value. To be used, where
|
||||
* the actual value of the Maybe is not needed like Object::Set.
|
||||
*/
|
||||
V8_INLINE void Check() const {
|
||||
if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this Maybe<> to a value of type T. If this Maybe<> is
|
||||
* nothing (empty), |false| is returned and |out| is left untouched.
|
||||
|
Loading…
Reference in New Issue
Block a user