I think the expected pattern is more along the lines of:

>
> Local<...> result;
> if (v8::JSON::Parse(...).ToLocal(&result)) {
>     result->Set(...);
> }


Would that be succinct enough for you, or is it the lack of type deduction
of result that is the problem? That could be avoided with some
macro+decltype hackery.

- Leszek

On Tue, Mar 6, 2018 at 12:11 AM, Zac Hansen <xax...@gmail.com> wrote:

> 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 <jkumme...@chromium.org>
> 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 <xax...@gmail.com> 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, xax...@gmail.com 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
>>> v8-dev@googlegroups.com
>>> 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 v8-dev+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> --
>> v8-dev mailing list
>> v8-dev@googlegroups.com
>> 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/to
>> pic/v8-dev/sw1rs5U6UNg/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> v8-dev+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> --
> v8-dev mailing list
> v8-dev@googlegroups.com
> 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 v8-dev+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-dev mailing list
v8-dev@googlegroups.com
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 v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to