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 <jkumme...@chromium.org>
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 <xax...@gmail.com> 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()
>> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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.

Reply via email to