From: jochen Date: Wed, 15 Apr 2015 07:11:54 +0000 (-0700) Subject: When converting Maybe and MaybeLocal values with a check, always check X-Git-Tag: upstream/4.7.83~3208 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ac23150fd2be43fcda9ad12dc118c6b16d96cdb6;p=platform%2Fupstream%2Fv8.git When converting Maybe and MaybeLocal values with a check, always check An embedder that wants to avoid the check should use MaybeLocal::ToLocal. BUG=none R=dcarney@chromium.org LOG=y Review URL: https://codereview.chromium.org/1083943002 Cr-Commit-Position: refs/heads/master@{#27832} --- diff --git a/include/v8.h b/include/v8.h index cdb23b4..d8ef81e 100644 --- a/include/v8.h +++ b/include/v8.h @@ -439,7 +439,7 @@ class MaybeLocal { return !IsEmpty(); } - // Will crash when checks are enabled if the MaybeLocal<> is empty. + // Will crash if the MaybeLocal<> is empty. V8_INLINE Local ToLocalChecked(); template @@ -6074,7 +6074,7 @@ class V8_EXPORT V8 { int* index); static Local GetEternal(Isolate* isolate, int index); - static void CheckIsJust(bool is_just); + static void FromJustIsNothing(); static void ToLocalEmpty(); static void InternalFieldOutOfBounds(int index); @@ -6109,11 +6109,9 @@ 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. + // Will crash if the Maybe<> is nothing. V8_INLINE T FromJust() const { -#ifdef V8_ENABLE_CHECKS - V8::CheckIsJust(IsJust()); -#endif + if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing(); return value; } @@ -6931,9 +6929,7 @@ Local Eternal::Get(Isolate* isolate) { template Local MaybeLocal::ToLocalChecked() { -#ifdef V8_ENABLE_CHECKS - if (val_ == nullptr) V8::ToLocalEmpty(); -#endif + if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty(); return Local(val_); } diff --git a/src/api.cc b/src/api.cc index 9d4356c..5be9daf 100644 --- a/src/api.cc +++ b/src/api.cc @@ -584,8 +584,8 @@ Local V8::GetEternal(Isolate* v8_isolate, int index) { } -void V8::CheckIsJust(bool is_just) { - Utils::ApiCheck(is_just, "v8::FromJust", "Maybe value is Nothing."); +void V8::FromJustIsNothing() { + Utils::ApiCheck(false, "v8::FromJust", "Maybe value is Nothing."); }