Pre-development patch feasibility/acceptance question for making v8::Object::New take a prototype and property object like Object.create() does

9 views
Skip to first unread message

xax...@gmail.com

unread,
Feb 15, 2016, 3:19:27 AM2/15/16
to v8-dev
I've been frustrated by v8::Object::New not accepting a prototype object as a parameter and it's been hinted strongly that using v8::Object::SetPrototype after object creation is a bad idea.  Now I'm left wondering if it would be reasonable to implement (and if it would be accepted if it worked) to add that functionality to v8::Object::New

Specifically:

static Local<Object> New(Isolate *isolate, Local<Object> prototype = Local<Object>, Local<Object>() propertiesObject=Local<Object>());

To line up with:  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create and not change the functionality of existing calls.

Also, while asking related questions earlier in the week, I was pointed at ObjectCreate in builtins.cc


I looked at it a bit and tried to move the code into v8.h/api.cc but I was quickly stymied by not understanding the relationship between v8::Object and v8::i::Object.  Is the code in builtins.cc the right path for this?  Also, is this a reasonable project for someone not intimately familiar with the v8 codebase and willing to put in a week's worth of time into learning and making the change or is this somehow much harder than it appears?


Thank you.

--Zac

Jakob Kummerow

unread,
Feb 15, 2016, 4:27:29 AM2/15/16
to v8-...@googlegroups.com
On Mon, Feb 15, 2016 at 9:19 AM, <xax...@gmail.com> wrote:
I've been frustrated by v8::Object::New not accepting a prototype object as a parameter and it's been hinted strongly that using v8::Object::SetPrototype after object creation is a bad idea. 

Well, rule #1 of performance optimizations is to start by measuring what you care about. Have you tried simply using SetPrototype? Do you have a performance problem?

Now I'm left wondering if it would be reasonable to implement (and if it would be accepted if it worked) to add that functionality to v8::Object::New

The warning that has you so scared mostly just says that dynamically modifying prototype chains is bad. Adding a new API function with a different name that still changes prototypes under the hood isn't going to change that.

That said, setting up an object's prototype initially is often unavoidable. If the object hasn't been seen/mucked with by other code, it's probably going to be fine. Again, please measure before you obsess about it.

Specifically:

static Local<Object> New(Isolate *isolate, Local<Object> prototype = Local<Object>, Local<Object>() propertiesObject=Local<Object>());

To line up with:  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create and not change the functionality of existing calls.

I'm not the right person to give a final "yes" or "no" to this question, but my gut feeling is that instead of overloading Object::New to have several different behaviors, it's probably better to introduce a new function (maybe "Object::Create"?) that does exactly what JS-side Object.create would do, nothing more, nothing less. That said, I'm not convinced any new API call is required at all, see above.
 
Also, while asking related questions earlier in the week, I was pointed at ObjectCreate in builtins.cc


I looked at it a bit and tried to move the code into v8.h/api.cc but I was quickly stymied by not understanding the relationship between v8::Object and v8::i::Object.  Is the code in builtins.cc the right path for this?  Also, is this a reasonable project for someone not intimately familiar with the v8 codebase and willing to put in a week's worth of time into learning and making the change or is this somehow much harder than it appears?


Thank you.

--Zac

--
--
v8-dev mailing list
v8-...@googlegroups.com
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 v8-dev+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zac Hansen

unread,
Feb 15, 2016, 5:26:47 AM2/15/16
to v8-...@googlegroups.com
Can you give me a hint or two of behaviors to look for for my testing?   The warnings I'm seeing about the performance implications of changing the prototype on an existing object are wide ranging including things that one wouldn't normally think of.

I'm scared that I'll test what I think I want to do, write it, then decide I want to extend it in some fashion and hit performance bottlenecks that I wouldn't have intuitively expected.  The reason I've got a bug up my butt about object.create() isn't necessarily about speed per se, but more about consistency and predictability.

Thank you for all your feedback.

--Zac




You received this message because you are subscribed to a topic in the Google Groups "v8-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-dev/5f9uuEQ5b48/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-dev+un...@googlegroups.com.

Jakob Kummerow

unread,
Feb 15, 2016, 5:58:44 AM2/15/16
to v8-...@googlegroups.com
On Mon, Feb 15, 2016 at 11:26 AM, Zac Hansen <xax...@gmail.com> wrote:
Can you give me a hint or two of behaviors to look for for my testing?  

Unexpected slowness ;-)

Not knowing what it is that you're going to do, it's really hard to be more specific than that.
Reply all
Reply to author
Forward
0 new messages