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

Unified Diff: include/v8.h

Issue 1022803002: Clarify what APIs return Maybe and MaybeLocal 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 8ed5b8de1a5c0efeae6afed50c184aeab640993a..c827659ffb53009b33b3381e6f3818449b40c27b 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -411,6 +411,16 @@ template <class T> class Local : public Handle<T> {
};
+/**
+ * A MaybeLocal<> is a wrapper around Local<> that enforces a check whether
+ * the Local<> is empty before it can be used.
+ *
+ * If an API method returns a MaybeLocal<>, the API method can potentially fail
+ * either because an exception is thrown, or because an exception is pending,
+ * e.g. because a previous API call threw an exception that hasn't been caught
+ * yet, or because a TerminateExecution exception was thrown. In that case, an
+ * empty MaybeLocal is returned.
+ */
template <class T>
class MaybeLocal {
public:
@@ -429,6 +439,7 @@ class MaybeLocal {
return !IsEmpty();
}
+ // Will crash when checks are enabled if the MaybeLocal<> is empty.
V8_INLINE Local<T> ToLocalChecked();
template <class S>
@@ -5979,6 +5990,12 @@ class V8_EXPORT V8 {
/**
* A simple Maybe type, representing an object which may or may not have a
* value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html.
+ *
+ * If an API method returns a Maybe<>, the API method can potentially fail
+ * either because an exception is thrown, or because an exception is pending,
+ * e.g. because a previous API call threw an exception that hasn't been caught
+ * yet, or because a TerminateExecution exception was thrown. In that case, a
+ * "Nothing" value is returned.
*/
template <class T>
class Maybe {
@@ -5986,6 +6003,7 @@ class Maybe {
V8_INLINE bool IsNothing() const { return !has_value; }
V8_INLINE bool IsJust() const { return has_value; }
+ // Will crash when checks are enabled if the Maybe<> is nothing.
V8_INLINE T FromJust() const {
#ifdef V8_ENABLE_CHECKS
V8::CheckIsJust(IsJust());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698