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:

   1. 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 
   <https://v8.paulfryzel.com/docs/master/api_8cc_source.html#l01276>).  
   But we can check for this case via GetNumberOfEmbedderDataFields() as seen 
   above.
   2. 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?*
   3. 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

-- 
-- 
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/c0677ba0-3a77-4ffb-aadb-fe07ed22f535%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to