I think this is mostly because the whole point of MaybeLocal is to be
explicit. "ToLocalChecked" should say "this can crash if the MaybeLocal is
empty" loudly in your face, rather than hiding it in a small operator.

There are many ways to make V8's API more concise but less safe/obvious. I
agree that it is unfortunate how verbose the .IsEmpty/.ToLocalChecked
pattern is, but we care more about avoiding bugs than about avoiding a few
extra characters. If you know what you're doing, you can create your own
helpers and abstractions.


On Mon, Mar 5, 2018 at 3:18 PM <[email protected]> wrote:

> Specifically, I'm suggesting adding:
>
> diff --git a/include/v8.h b/include/v8.h
>
> index b96771ed45..5d5685839a 100644
>
> --- a/include/v8.h
>
> +++ b/include/v8.h
>
> @@ -383,6 +383,18 @@ class MaybeLocal {
>
>      return IsEmpty() ? default_value : Local<S>(val_);
>
>    }
>
>
>
> +  explicit operator bool() const {
>
> +      return !this->IsEmpty();
>
> +  }
>
> +
>
> +  Local<T> & operator->() {
>
> +      return this->ToLocalChecked();
>
> +  }
>
> +
>
> +  Local<T> operator*() {
>
> +      return this->ToLocalChecked();
>
> +  }
>
> +
>
>   private:
>
>    T* val_;
>
>  };
>
> On Monday, March 5, 2018 at 3:02:11 PM UTC-8, [email protected] wrote:
>>
>> I'd really like to be able to say:
>>
>> if (auto result = v8::JSON::Parse(...)) {
>>     (*result)->Set(...);
>> }
>>
>> instead of
>>
>> if (auto result =  v8::JSON::Parse(...); !result.IsEmpty()) {
>>     result.ToLocalChecked()->Set(...);
>> }
>>
>> or worse without '17.
>>
>> Is there a technical or policy reason this hasn't/can't be added?  I'd be
>> happy to submit it.
>>
>> Thank you.
>>
>> --Zac
>>
>>
>> --
> --
> v8-dev mailing list
> [email protected]
> http://groups.google.com/group/v8-dev
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to