Behavior of GetEmbedderData() for unset fields (how to check if SetEmbedderData() already called)
12 views
Skip to first unread message
ytp...@gmail.com
unread,
Jun 4, 2019, 8:46:22 PM6/4/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to v8-dev
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.
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
Ben Noordhuis
unread,
Jun 5, 2019, 5:01:06 AM6/5/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to v8-...@googlegroups.com
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.
ytp...@gmail.com
unread,
Jun 5, 2019, 6:58:47 PM6/5/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to v8-dev
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.