On Wed, Jun 5, 2019 at 2:46 AM <[email protected]> wrote:
>
> I have some code that sets data using Context::SetEmbedderData().  I'd like 
> to have an assert verifying that this is only done once on a given V8 
> Context, i.e. assert that the embedder data field at a given index is 
> currently unset.
>
> Is it safe to do something like this?
> ASSERT( context->GetNumberOfEmbedderDataFields() <= kMyDataIndex || 
> context->GetEmbedderData(kMyDataIndex).isEmpty() );
>
> Seems like there are three cases here and I'm unsure of the behavior of the 
> 2nd one:
>
> SetEmbedderData() has never been called with an index >= kMyDataIndex -- it's 
> illegal to call GetEmbedderData() with this index since it would read from 
> past the end of the storage array (or fail in a debug build, on this line).  
> But we can check for this case via GetNumberOfEmbedderDataFields() as seen 
> above.
> SetEmbedderData() has been called with an index > kMyDataIndex, but has not 
> been called with index == kMyDataIndex -- is calling 
> GetEmbedderData(kMyDataIndex) going to return an empty Handle, or is it going 
> to read from uninitialized memory?
> SetEmbedderData() has already been called with index == kMyDataIndex -- so 
> GetEmbedderData(kMyDataIndex) is safe and will return the value stored before 
> (failing the assert as desired).
>
> Thanks in advance!
>
> - Peter

It should return a handle for which handle->IsUndefined() is true.

You should probably not try that with
context->GetAlignedPointerFromEmbedderData(), I expect that to hit an
assert in debug builds and return a bogus value in release builds.

-- 
-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CAHQurc8pLVzvmAxLmZKCZLAgYn8FLzcVGdxpaiT4mW0_300ndA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to