V8 bindings: creation_context for wrapper

33 views
Skip to first unread message

Kirill

unread,
Jun 15, 2018, 4:09:44 PM6/15/18
to blink-dev
Hi.
Here is the situation: I created a new HTML Element (with corresponding HTML tag for it), and now I need to have an ability to add/remove different methods and fields of its JS instance dynamically depending on object's attributes.

I overloaded virtual ParseAttribute() call, so I can react to attributes' changing events:
void HTMLNewElement::ParseAttribute(const AttributeModificationParams& params) {
So now I need to get an access to this object's V8 instance.

As I can see in ScriptWrappable.h header, there is the Wrap() method to get V8 wrapper of the object:
virtual v8::Local<v8::Object> Wrap(v8::Isolate*, v8::Local<v8::Object> creation_context);
Everything is clear, except the 'creation_context' argument meaning.
The element's attributes can be set during document parsing process or manually from some scripts.
I can get current context with isolate ->GetCurrentContext();, but it will be v8::Context, not v8::Object.

So what exactly should I pass there?

Thanks,
Kirill.

Ian Kilpatrick

unread,
Jun 15, 2018, 5:02:08 PM6/15/18
to sle...@gmail.com, blink-dev
The direct answer to your question is - the method you are after is "ToV8" e.g.
v8::Local<v8::Value> element_value = ToV8(element, context, isolate);

But depending on what exactly you are trying to do there might be a different solution space which might be better.

Thanks,
Ian

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/a0e594e4-e3d8-43e1-9d16-995093c5bdbe%40chromium.org.

Jeremy Roman

unread,
Jun 18, 2018, 11:04:09 AM6/18/18
to Ian Kilpatrick, sle...@gmail.com, blink-dev
On Fri, Jun 15, 2018 at 5:01 PM, Ian Kilpatrick <ikilp...@chromium.org> wrote:
The direct answer to your question is - the method you are after is "ToV8" e.g.
v8::Local<v8::Value> element_value = ToV8(element, context, isolate);

But depending on what exactly you are trying to do there might be a different solution space which might be better.

Thanks,
Ian

On Fri, Jun 15, 2018 at 1:09 PM Kirill <sle...@gmail.com> wrote:
Hi.
Here is the situation: I created a new HTML Element (with corresponding HTML tag for it), and now I need to have an ability to add/remove different methods and fields of its JS instance dynamically depending on object's attributes.

I overloaded virtual ParseAttribute() call, so I can react to attributes' changing events:
void HTMLNewElement::ParseAttribute(const AttributeModificationParams& params) {
So now I need to get an access to this object's V8 instance.

As I can see in ScriptWrappable.h header, there is the Wrap() method to get V8 wrapper of the object:
virtual v8::Local<v8::Object> Wrap(v8::Isolate*, v8::Local<v8::Object> creation_context);
Everything is clear, except the 'creation_context' argument meaning.
The element's attributes can be set during document parsing process or manually from some scripts.
I can get current context with isolate ->GetCurrentContext();, but it will be v8::Context, not v8::Object.

So what exactly should I pass there? 

We try to avoid doing this dynamically, but if you do need to, you could look at WebIDL named getters, which may be better. Or the plugin stuff for <embed> and <object>, possibly, but that's even hairier.
 
Thanks,
Kirill.

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
Reply all
Reply to author
Forward
0 new messages