Re: [v8-users] Is it safe to consume v8::Private methods?

2017-07-14 Thread Jakob Kummerow
Gautham, I think you might be misunderstanding how the Maybe<> API is
supposed to be used. When used correctly, it is absolutely safe and will
never crash.

- Maybe::FromJust() / MaybeLocal::ToLocalChecked() are intended for when
you know for sure that the Maybe / MaybeLocal is not empty. Usually, the
only case when you would know that is when you've just checked.
- Maybe::IsNothing() / Maybe::IsJust() / MaybeLocal::IsEmpty() are intended
for doing precisely that check.

Typical usage looks like:

MaybeLocal result = ...;
if (result.IsEmpty()) {
  // Handle error case, e.g. print a warning.
  return false;
} else {
  // .ToLocalChecked is safe to use here :-)
  do_something_with(result.ToLocalChecked());
}

For convenience, there are also the Maybe::FromMaybe() /
MaybeLocal::ToLocal() helpers:

Maybe maybe_x = ...;
int x = maybe_x.FromMaybe(-1);
// same as:
// int x = maybe_x.IsJust() ? maybe_x.FromJust() : -1;

Of course you can also use Private Symbols if you prefer; but there's
really no reason to avoid private fields for stability reasons.

Hope this helps,
Jakob

On Fri, Jul 14, 2017 at 12:00 AM, Ben Noordhuis  wrote:

> On Fri, Jul 14, 2017 at 5:52 AM, Gautham B A
>  wrote:
> > No, .ToLocalChecked() is called by my code, not from V8.
> >
> > I would like to know if the APIs under v8::Private namespace has been
> battle
> > tested.
>
> Node.js uses them and I'm fairly sure Chromium does too, so yes, I
> think you can say it's battle tested.
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [v8-users] Is it safe to consume v8::Private methods?

2017-07-14 Thread Ben Noordhuis
On Fri, Jul 14, 2017 at 5:52 AM, Gautham B A
 wrote:
> No, .ToLocalChecked() is called by my code, not from V8.
>
> I would like to know if the APIs under v8::Private namespace has been battle
> tested.

Node.js uses them and I'm fairly sure Chromium does too, so yes, I
think you can say it's battle tested.

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


Re: [v8-users] Is it safe to consume v8::Private methods?

2017-07-13 Thread Gautham B A
No, .ToLocalChecked() is called by my code, not from V8.

I would like to know if the APIs under v8::Private namespace has been 
battle tested.

On Wednesday, 12 July 2017 14:53:57 UTC+5:30, Ben Noordhuis wrote:
>
> On Wed, Jul 12, 2017 at 11:15 AM, Gautham B A 
>  wrote: 
> > I've observed that the exception thrown is - 
> > # 
> > # Fatal error in v8::ToLocalChecked 
> > # Empty MaybeLocal. 
> > # 
> > 
> > Is it possible to catch that exception to prevent v8 process from 
> crashing? 
>
> Don't call .ToLocalChecked() if .IsEmpty() is true (or use .ToLocal() 
> or .FromMaybe().) 
>
> Or do you mean that the .ToLocalChecked() call comes from inside V8 
> itself?  If so, what is the stack trace?

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


Re: [v8-users] Is it safe to consume v8::Private methods?

2017-07-12 Thread Ben Noordhuis
On Wed, Jul 12, 2017 at 11:15 AM, Gautham B A
 wrote:
> I've observed that the exception thrown is -
> #
> # Fatal error in v8::ToLocalChecked
> # Empty MaybeLocal.
> #
>
> Is it possible to catch that exception to prevent v8 process from crashing?

Don't call .ToLocalChecked() if .IsEmpty() is true (or use .ToLocal()
or .FromMaybe().)

Or do you mean that the .ToLocalChecked() call comes from inside V8
itself?  If so, what is the stack trace?

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


Re: [v8-users] Is it safe to consume v8::Private methods?

2017-07-12 Thread Gautham B A
I've observed that the exception thrown is - 
#
# Fatal error in v8::ToLocalChecked
# Empty MaybeLocal.
#

Is it possible to catch that exception to prevent v8 process from crashing?

On Wednesday, 12 July 2017 12:15:51 UTC+5:30, Ben Noordhuis wrote:
>
> On Wed, Jul 12, 2017 at 7:34 AM, Gautham B A 
>  wrote: 
> > Hi all, 
> > 
> > I'm trying to use the private field of a v8::Object to store some data 
> in it 
> > as shown here - https://github.com/nodejs/nan/issues/587. 
> > I was wondering if it's safe to use because when I try to read the 
> private 
> > field (Using FromJust() in the process), in the documentation it says 
> that 
> > v8 process will crash if Maybe<> is nothing (empty). 
> > It would be really helpful if someone could tell what scenario will 
> cause 
> > Maybe<> to become empty. 
>
> With the introduction of proxies, the answer is "just about any." 
>
> Calls into the VM that raise exceptions result in empty Maybe and 
> MaybeLocal instances.  Since proxies can intercept most operations on 
> JS functions and objects, careful error handling is required. 
>
> > Also, I would like to know if the API under v8::Private namespace is 
> safe to 
> > consume (by 'safe', I mean it shouldn't crash the v8 process, like the 
> one 
> > above). 
>
> No, strictly speaking.  There is always the possibility of a call to 
> v8::Private::New() triggering an out-of-memory condition, for example. 
>

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


Re: [v8-users] Is it safe to consume v8::Private methods?

2017-07-12 Thread Ben Noordhuis
On Wed, Jul 12, 2017 at 7:34 AM, Gautham B A
 wrote:
> Hi all,
>
> I'm trying to use the private field of a v8::Object to store some data in it
> as shown here - https://github.com/nodejs/nan/issues/587.
> I was wondering if it's safe to use because when I try to read the private
> field (Using FromJust() in the process), in the documentation it says that
> v8 process will crash if Maybe<> is nothing (empty).
> It would be really helpful if someone could tell what scenario will cause
> Maybe<> to become empty.

With the introduction of proxies, the answer is "just about any."

Calls into the VM that raise exceptions result in empty Maybe and
MaybeLocal instances.  Since proxies can intercept most operations on
JS functions and objects, careful error handling is required.

> Also, I would like to know if the API under v8::Private namespace is safe to
> consume (by 'safe', I mean it shouldn't crash the v8 process, like the one
> above).

No, strictly speaking.  There is always the possibility of a call to
v8::Private::New() triggering an out-of-memory condition, for example.

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


[v8-users] Is it safe to consume v8::Private methods?

2017-07-11 Thread Gautham B A
Hi all,

I'm trying to use the private field of a v8::Object to store some data in 
it as shown here - https://github.com/nodejs/nan/issues/587.
I was wondering if it's safe to use because when I try to read the private 
field (Using FromJust() in the process), in the documentation 

 it 
says that v8 process will *crash* if *Maybe<> is nothing (empty).*
It would be really helpful if someone could tell what scenario will cause 
Maybe<> to become empty.

Also, I would like to know if the API under v8::Private namespace is safe 
to consume (by 'safe', I mean it shouldn't crash the v8 process, like the 
one above).

Thanks,
--Gautham

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