I can see where you are coming from even if I don't agree, but that doesn't
seem to preclude adding the `explicit operator bool`, does it?  Just that
alone would get me 95% of what I want.

I'd suggest adding it to maybe, as well, I think.

--Zac


On Mon, Mar 5, 2018 at 4:03 PM, Jakob Kummerow <[email protected]>
wrote:

> 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 a topic in the
> Google Groups "v8-dev" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/v8-dev/sw1rs5U6UNg/unsubscribe.
> To unsubscribe from this group and all its topics, 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