Ah ok -- so that's what the "undefined_value()" referenced in Factory::CopyArrayAndGrow() means I suppose? I wasn't able to find a definition for that function.
Thanks for the answer! - P On Wednesday, June 5, 2019 at 2:01:06 AM UTC-7, Ben Noordhuis wrote: > > On Wed, Jun 5, 2019 at 2:46 AM <[email protected] <javascript:>> 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/7601f32a-5989-4773-9824-7ea80a992ec9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
