Re: [v8-users] Is it "okay" to use v8::Object::SetPrototype? Scary warnings about using Object.setPrototypeOf()..

2016-02-12 Thread Jakob Kummerow
Whether an object's prototype is changed from JavaScript or from C++
doesn't make a difference. (Why would it?)

The preferred way to set a newly allocated object's prototype is to use the
FunctionTemplate's PrototypeTemplate. See the large comment for class
FunctionTemplate in v8.h.


On Fri, Feb 12, 2016 at 5:44 AM, Zac Hansen  wrote:

> I want to do the equivalent of Object.create() in javascript from C++, but
> I don't see any way to specify the prototype of a new v8::Object from the
> API.
>
> I was planning on creating the object with v8::Object::New and then
> calling v8::Object::SetPrototype() on it, until I saw this:
>
>
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
>
> Warning: Changing the [[Prototype]] of an object is, by the nature of how
> modern JavaScript engines optimize property accesses, a very slow
> operation, in *every* browser and JavaScript engine. The effects on
> performance of altering inheritance are subtle and far-flung, and are not
> limited to simply the time spent in obj.__proto__ = ... statement, but
> may extend to *any* code that has access to *any* object whose
> [[Prototype]] has been altered. If you care about performance you should
> avoid setting the [[Prototype]] of an object. Instead, create a new
> object with the desired [[Prototype]] using Object.create()
> 
> .
>
>
> That's a pretty terrifying situation, so I want to make sure that using
> SetPrototype() doesn't incur that kind of penalty - at least on a newly
> created and unused object.
>
> Thank you.
>
> --Zac
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] Is it "okay" to use v8::Object::SetPrototype? Scary warnings about using Object.setPrototypeOf()..

2016-02-12 Thread Zac Hansen
When you say:

> The preferred way to set a newly allocated object's prototype is to use
the FunctionTemplate's PrototypeTemplate. See the large comment for class
FunctionTemplate in v8.h.


What does "preferred" mean?  Is it because of the type of thing in the
warning I put in my original post?  Or  some other reason why that method
is "preferred"?

--Zac


On Fri, Feb 12, 2016 at 1:34 AM, Jakob Kummerow 
wrote:

> Whether an object's prototype is changed from JavaScript or from C++
> doesn't make a difference. (Why would it?)
>
> The preferred way to set a newly allocated object's prototype is to use
> the FunctionTemplate's PrototypeTemplate. See the large comment for class
> FunctionTemplate in v8.h.
>
>
> On Fri, Feb 12, 2016 at 5:44 AM, Zac Hansen  wrote:
>
>> I want to do the equivalent of Object.create() in javascript from C++,
>> but I don't see any way to specify the prototype of a new v8::Object from
>> the API.
>>
>> I was planning on creating the object with v8::Object::New and then
>> calling v8::Object::SetPrototype() on it, until I saw this:
>>
>>
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
>>
>> Warning: Changing the [[Prototype]] of an object is, by the nature of
>> how modern JavaScript engines optimize property accesses, a very slow
>> operation, in *every* browser and JavaScript engine. The effects on
>> performance of altering inheritance are subtle and far-flung, and are not
>> limited to simply the time spent in obj.__proto__ = ... statement, but
>> may extend to *any* code that has access to *any* object whose
>> [[Prototype]] has been altered. If you care about performance you should
>> avoid setting the [[Prototype]] of an object. Instead, create a new
>> object with the desired [[Prototype]] using Object.create()
>> 
>> .
>>
>>
>> That's a pretty terrifying situation, so I want to make sure that using
>> SetPrototype() doesn't incur that kind of penalty - at least on a newly
>> created and unused object.
>>
>> Thank you.
>>
>> --Zac
>>
>> --
>> --
>> v8-users mailing list
>> v8-users@googlegroups.com
>> http://groups.google.com/group/v8-users
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to v8-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "v8-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/v8-users/L9e3eHyjE4A/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] Is it "okay" to use v8::Object::SetPrototype? Scary warnings about using Object.setPrototypeOf()..

2016-02-12 Thread Jakob Kummerow
It avoids having to change the prototype.

(That warning on MDN is awesome, strong +1 to that. Being able to modify
prototypes at all is a mis-feature IMHO.)

On Fri, Feb 12, 2016 at 10:47 AM, Zac Hansen  wrote:

>
> When you say:
>
> > The preferred way to set a newly allocated object's prototype is to use
> the FunctionTemplate's PrototypeTemplate. See the large comment for class
> FunctionTemplate in v8.h.
>
>
> What does "preferred" mean?  Is it because of the type of thing in the
> warning I put in my original post?  Or  some other reason why that method
> is "preferred"?
>
> --Zac
>
>
> On Fri, Feb 12, 2016 at 1:34 AM, Jakob Kummerow 
> wrote:
>
>> Whether an object's prototype is changed from JavaScript or from C++
>> doesn't make a difference. (Why would it?)
>>
>> The preferred way to set a newly allocated object's prototype is to use
>> the FunctionTemplate's PrototypeTemplate. See the large comment for class
>> FunctionTemplate in v8.h.
>>
>>
>> On Fri, Feb 12, 2016 at 5:44 AM, Zac Hansen  wrote:
>>
>>> I want to do the equivalent of Object.create() in javascript from C++,
>>> but I don't see any way to specify the prototype of a new v8::Object from
>>> the API.
>>>
>>> I was planning on creating the object with v8::Object::New and then
>>> calling v8::Object::SetPrototype() on it, until I saw this:
>>>
>>>
>>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
>>>
>>> Warning: Changing the [[Prototype]] of an object is, by the nature of
>>> how modern JavaScript engines optimize property accesses, a very slow
>>> operation, in *every* browser and JavaScript engine. The effects on
>>> performance of altering inheritance are subtle and far-flung, and are not
>>> limited to simply the time spent in obj.__proto__ = ... statement, but
>>> may extend to *any* code that has access to *any* object whose
>>> [[Prototype]] has been altered. If you care about performance you
>>> should avoid setting the [[Prototype]] of an object. Instead, create a
>>> new object with the desired [[Prototype]] using Object.create()
>>> 
>>> .
>>>
>>>
>>> That's a pretty terrifying situation, so I want to make sure that using
>>> SetPrototype() doesn't incur that kind of penalty - at least on a newly
>>> created and unused object.
>>>
>>> Thank you.
>>>
>>> --Zac
>>>
>>> --
>>> --
>>> v8-users mailing list
>>> v8-users@googlegroups.com
>>> http://groups.google.com/group/v8-users
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "v8-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to v8-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> --
>> v8-users mailing list
>> v8-users@googlegroups.com
>> http://groups.google.com/group/v8-users
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "v8-users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/v8-users/L9e3eHyjE4A/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> v8-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] Is it "okay" to use v8::Object::SetPrototype? Scary warnings about using Object.setPrototypeOf()..

2016-02-12 Thread Zac Hansen
If I wanted to re-implement Object.create(prototype,
properties_object) using the API with the same performance
characteristics as the built-in Object.create(), what API calls would I use
in the callback from my FunctionTemplate?



On Fri, Feb 12, 2016 at 2:58 AM, Jakob Kummerow 
wrote:

> On Fri, Feb 12, 2016 at 11:45 AM, Zac Hansen  wrote:
>
>> Ok, so there is no ongoing performance penalty if I change the prototype
>> of an object?
>>
>
> Who said that?
>
>
>> Is there a reason there's no API call for setting the prototype of a
>> javascript object created in C++ to a javascript-created object?  In other
>> words, why does v8::Object::New() not have an option to take a v8::Object?
>>
>
> Sounds like you *want* to muck with dynamically created/modified prototype
> chains. That'll probably end up being slow either way. Maybe you don't
> care. So maybe just do whatever seems easiest to you, and see if it works
> out OK?
>
>
> On Fri, Feb 12, 2016 at 2:41 AM, Jakob Kummerow 
>> wrote:
>>
>>> It avoids having to change the prototype.
>>>
>>> (That warning on MDN is awesome, strong +1 to that. Being able to modify
>>> prototypes at all is a mis-feature IMHO.)
>>>
>>> On Fri, Feb 12, 2016 at 10:47 AM, Zac Hansen  wrote:
>>>

 When you say:

 > The preferred way to set a newly allocated object's prototype is to
 use the FunctionTemplate's PrototypeTemplate. See the large comment for
 class FunctionTemplate in v8.h.


 What does "preferred" mean?  Is it because of the type of thing in the
 warning I put in my original post?  Or  some other reason why that method
 is "preferred"?

 --Zac


 On Fri, Feb 12, 2016 at 1:34 AM, Jakob Kummerow  wrote:

> Whether an object's prototype is changed from JavaScript or from C++
> doesn't make a difference. (Why would it?)
>
> The preferred way to set a newly allocated object's prototype is to
> use the FunctionTemplate's PrototypeTemplate. See the large comment for
> class FunctionTemplate in v8.h.
>
>
> On Fri, Feb 12, 2016 at 5:44 AM, Zac Hansen  wrote:
>
>> I want to do the equivalent of Object.create() in javascript from
>> C++, but I don't see any way to specify the prototype of a new v8::Object
>> from the API.
>>
>> I was planning on creating the object with v8::Object::New and then
>> calling v8::Object::SetPrototype() on it, until I saw this:
>>
>>
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
>>
>> Warning: Changing the [[Prototype]] of an object is, by the nature
>> of how modern JavaScript engines optimize property accesses, a very slow
>> operation, in *every* browser and JavaScript engine. The effects on
>> performance of altering inheritance are subtle and far-flung, and are not
>> limited to simply the time spent in obj.__proto__ = ... statement,
>> but may extend to *any* code that has access to *any* object whose
>> [[Prototype]] has been altered. If you care about performance you
>> should avoid setting the [[Prototype]] of an object. Instead, create
>> a new object with the desired [[Prototype]] using Object.create()
>> 
>> .
>>
>>
>> That's a pretty terrifying situation, so I want to make sure that
>> using SetPrototype() doesn't incur that kind of penalty - at least on a
>> newly created and unused object.
>>
>> Thank you.
>>
>> --Zac
>>
>> --
>> --
>> v8-users mailing list
>> v8-users@googlegroups.com
>> http://groups.google.com/group/v8-users
>> ---
>> You received this message because you are subscribed to the Google
>> Groups "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to v8-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "v8-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/v8-users/L9e3eHyjE4A/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

 --
 --
 v8-users mailing list
 v8-users@googlegroups.com
 http://groups.google.com/group/v8-users
 ---
 You received this message because you are subscribed to the Google

Re: [v8-users] Is it "okay" to use v8::Object::SetPrototype? Scary warnings about using Object.setPrototypeOf()..

2016-02-12 Thread Zac Hansen
Ok, so there is no ongoing performance penalty if I change the prototype of
an object?

Is there a reason there's no API call for setting the prototype of a
javascript object created in C++ to a javascript-created object?  In other
words, why does v8::Object::New() not have an option to take a v8::Object?

On Fri, Feb 12, 2016 at 2:41 AM, Jakob Kummerow 
wrote:

> It avoids having to change the prototype.
>
> (That warning on MDN is awesome, strong +1 to that. Being able to modify
> prototypes at all is a mis-feature IMHO.)
>
> On Fri, Feb 12, 2016 at 10:47 AM, Zac Hansen  wrote:
>
>>
>> When you say:
>>
>> > The preferred way to set a newly allocated object's prototype is to
>> use the FunctionTemplate's PrototypeTemplate. See the large comment for
>> class FunctionTemplate in v8.h.
>>
>>
>> What does "preferred" mean?  Is it because of the type of thing in the
>> warning I put in my original post?  Or  some other reason why that method
>> is "preferred"?
>>
>> --Zac
>>
>>
>> On Fri, Feb 12, 2016 at 1:34 AM, Jakob Kummerow 
>> wrote:
>>
>>> Whether an object's prototype is changed from JavaScript or from C++
>>> doesn't make a difference. (Why would it?)
>>>
>>> The preferred way to set a newly allocated object's prototype is to use
>>> the FunctionTemplate's PrototypeTemplate. See the large comment for class
>>> FunctionTemplate in v8.h.
>>>
>>>
>>> On Fri, Feb 12, 2016 at 5:44 AM, Zac Hansen  wrote:
>>>
 I want to do the equivalent of Object.create() in javascript from C++,
 but I don't see any way to specify the prototype of a new v8::Object from
 the API.

 I was planning on creating the object with v8::Object::New and then
 calling v8::Object::SetPrototype() on it, until I saw this:


 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf

 Warning: Changing the [[Prototype]] of an object is, by the nature of
 how modern JavaScript engines optimize property accesses, a very slow
 operation, in *every* browser and JavaScript engine. The effects on
 performance of altering inheritance are subtle and far-flung, and are not
 limited to simply the time spent in obj.__proto__ = ... statement, but
 may extend to *any* code that has access to *any* object whose
 [[Prototype]] has been altered. If you care about performance you
 should avoid setting the [[Prototype]] of an object. Instead, create a
 new object with the desired [[Prototype]] using Object.create()
 
 .


 That's a pretty terrifying situation, so I want to make sure that using
 SetPrototype() doesn't incur that kind of penalty - at least on a newly
 created and unused object.

 Thank you.

 --Zac

 --
 --
 v8-users mailing list
 v8-users@googlegroups.com
 http://groups.google.com/group/v8-users
 ---
 You received this message because you are subscribed to the Google
 Groups "v8-users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to v8-users+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

>>>
>>> --
>>> --
>>> v8-users mailing list
>>> v8-users@googlegroups.com
>>> http://groups.google.com/group/v8-users
>>> ---
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "v8-users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/v8-users/L9e3eHyjE4A/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> v8-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> --
>> v8-users mailing list
>> v8-users@googlegroups.com
>> http://groups.google.com/group/v8-users
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to v8-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "v8-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/v8-users/L9e3eHyjE4A/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to 

Re: [v8-users] Is it "okay" to use v8::Object::SetPrototype? Scary warnings about using Object.setPrototypeOf()..

2016-02-12 Thread Jakob Kummerow
On Fri, Feb 12, 2016 at 11:45 AM, Zac Hansen  wrote:

> Ok, so there is no ongoing performance penalty if I change the prototype
> of an object?
>

Who said that?


> Is there a reason there's no API call for setting the prototype of a
> javascript object created in C++ to a javascript-created object?  In other
> words, why does v8::Object::New() not have an option to take a v8::Object?
>

Sounds like you *want* to muck with dynamically created/modified prototype
chains. That'll probably end up being slow either way. Maybe you don't
care. So maybe just do whatever seems easiest to you, and see if it works
out OK?


On Fri, Feb 12, 2016 at 2:41 AM, Jakob Kummerow 
> wrote:
>
>> It avoids having to change the prototype.
>>
>> (That warning on MDN is awesome, strong +1 to that. Being able to modify
>> prototypes at all is a mis-feature IMHO.)
>>
>> On Fri, Feb 12, 2016 at 10:47 AM, Zac Hansen  wrote:
>>
>>>
>>> When you say:
>>>
>>> > The preferred way to set a newly allocated object's prototype is to
>>> use the FunctionTemplate's PrototypeTemplate. See the large comment for
>>> class FunctionTemplate in v8.h.
>>>
>>>
>>> What does "preferred" mean?  Is it because of the type of thing in the
>>> warning I put in my original post?  Or  some other reason why that method
>>> is "preferred"?
>>>
>>> --Zac
>>>
>>>
>>> On Fri, Feb 12, 2016 at 1:34 AM, Jakob Kummerow 
>>> wrote:
>>>
 Whether an object's prototype is changed from JavaScript or from C++
 doesn't make a difference. (Why would it?)

 The preferred way to set a newly allocated object's prototype is to use
 the FunctionTemplate's PrototypeTemplate. See the large comment for class
 FunctionTemplate in v8.h.


 On Fri, Feb 12, 2016 at 5:44 AM, Zac Hansen  wrote:

> I want to do the equivalent of Object.create() in javascript from C++,
> but I don't see any way to specify the prototype of a new v8::Object from
> the API.
>
> I was planning on creating the object with v8::Object::New and then
> calling v8::Object::SetPrototype() on it, until I saw this:
>
>
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
>
> Warning: Changing the [[Prototype]] of an object is, by the nature of
> how modern JavaScript engines optimize property accesses, a very slow
> operation, in *every* browser and JavaScript engine. The effects on
> performance of altering inheritance are subtle and far-flung, and are not
> limited to simply the time spent in obj.__proto__ = ... statement,
> but may extend to *any* code that has access to *any* object whose
> [[Prototype]] has been altered. If you care about performance you
> should avoid setting the [[Prototype]] of an object. Instead, create
> a new object with the desired [[Prototype]] using Object.create()
> 
> .
>
>
> That's a pretty terrifying situation, so I want to make sure that
> using SetPrototype() doesn't incur that kind of penalty - at least on a
> newly created and unused object.
>
> Thank you.
>
> --Zac
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google
> Groups "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

 --
 --
 v8-users mailing list
 v8-users@googlegroups.com
 http://groups.google.com/group/v8-users
 ---
 You received this message because you are subscribed to a topic in the
 Google Groups "v8-users" group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/v8-users/L9e3eHyjE4A/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 v8-users+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

>>>
>>> --
>>> --
>>> v8-users mailing list
>>> v8-users@googlegroups.com
>>> http://groups.google.com/group/v8-users
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "v8-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to v8-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> --
>> v8-users mailing list
>> v8-users@googlegroups.com
>> http://groups.google.com/group/v8-users
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "v8-users"