Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Foreign objects
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Pablo Sole  
View profile  
 More options Oct 5 2012, 1:05 pm
From: Pablo Sole <pablo.s...@gmail.com>
Date: Fri, 05 Oct 2012 14:04:57 -0300
Local: Fri, Oct 5 2012 1:04 pm
Subject: Foreign objects
I found that the Foreign Class is actually a subclass of HeapObject and
the only difference is that it has some extra size to store a pointer
inside.

So, Can I use a Foreign instance to store a pointer from some C function
and pass it back and forth from/to JS?

From the code of SetPointerInInternalField I see that's what V8 does if
the pointer cannot be encoded as a SMI. But for the purpose of *just*
sending pointers back and forth, creating an object with an internal
field that ends up having another object on it that actually stores the
address seems overkill, if a Foreign object is a valid JS object, I'd
use that directly.

Thanks,

pablo.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matthias Ernst  
View profile  
 More options Oct 6 2012, 5:21 am
From: Matthias Ernst <matth...@mernst.org>
Date: Sat, 6 Oct 2012 11:21:36 +0200
Local: Sat, Oct 6 2012 5:21 am
Subject: Re: [v8-users] Foreign objects

On Fri, Oct 5, 2012 at 7:04 PM, Pablo Sole <pablo.s...@gmail.com> wrote:
> I found that the Foreign Class is actually a subclass of HeapObject and
> the only difference is that it has some extra size to store a pointer
> inside.

> So, Can I use a Foreign instance to store a pointer from some C function
> and pass it back and forth from/to JS?

Have you looked at External::Wrap (and Unwrap)? It returns an
v8::Value than can be passed through the embedding api. It states
(literally) "The Wrap function V8 will return the most optimal Value
object wrapping the C++ void*. "


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sven Panne  
View profile  
 More options Oct 6 2012, 1:49 pm
From: Sven Panne <svenpa...@chromium.org>
Date: Sat, 6 Oct 2012 19:49:24 +0200
Local: Sat, Oct 6 2012 1:49 pm
Subject: Re: [v8-users] Foreign objects

A Foreign object is *not* a JavaScript object it is intended to be used
only internally. Furthermore, v8's GC needs to distinguish the objects
under its control from the external ones, so we can't simply put any void*
into an internal field. Currently this part of the API is in a poor and
slightly broken state and there have been some discusssions how to fix it.
The probable future API looks like this:

   * A SetAlignedPointerInInternalField/GetAlignedPointerFromInternalField
will be added, allowing highly efficient stores/loads of 2-byte-aligned
void* to/from internal fields.

   * External will be changed back again to provide a real JavaScript
object, namely one with a hidden field containing a Foreign. This way *any*
void* can be wrapped and stored/loaded via
SetInternalField/GetInternalField and IsExternal will work again.

Wrap, Unwrap, SetPointerInInternalField and GetPointerFromInternalField
will probably be deprecated and die in some not-to-far future.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pablo Sole  
View profile  
 More options Oct 6 2012, 2:37 pm
From: Pablo Sole <pablo.s...@gmail.com>
Date: Sat, 06 Oct 2012 15:36:49 -0300
Local: Sat, Oct 6 2012 2:36 pm
Subject: Re: [v8-users] Foreign objects
Thank you for your explanations.

Having an efficient store/load of pointers over an Object would be very
handy indeed, in the meantime I'm using the storage space of a
HeapNumber object to store my pointers as you suggested some time ago (I
didn't check that a Foreign was related to an External before asking).

I suppose that hacking a new "Opaque" type that behaves like a
HeapNumber object from the GC perspective but without any of the number
methods should be doable and very useful for embedders. The whole idea,
after all, is to have an opaque pointer (from a V8 perspective) inside
JS, so I don't need any "services" from V8, just store it and please
don't consider it a pointer that should be handled in any way.

Cheers!

pablo.

On 10/06/2012 02:49 PM, Sven Panne wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »