Handles

58 views
Skip to first unread message

Deepak Subramanian

unread,
Sep 24, 2015, 12:29:04 PM9/24/15
to v8-users
Hi,

I am looking to know the relation between Handle<String> and String*

If I have a String*, how do I make it into a Handle<String> and vice-versa.

Thanks.

Best regards,
Deepak

Ben Noordhuis

unread,
Sep 25, 2015, 7:03:24 AM9/25/15
to v8-u...@googlegroups.com
On Thu, Sep 24, 2015 at 6:29 PM, Deepak Subramanian
<subud...@gmail.com> wrote:
> If I have a String*, how do I make it into a Handle<String> and vice-versa.

The short answer is "you don't" because you should never have to deal
with raw String pointers, it's unsafe. Can you tell more about what
you are doing?

Deepak Subramanian

unread,
Sep 25, 2015, 10:56:52 AM9/25/15
to v8-users
I don't understand.. I cannot get String* from a handle and process it ? 

After that if I needed to call some v8 code that needs handle<object> as an input, can I not create a string with the handle to satisfy it ? 

What exactly is unsafe about it ? [I am a noob]]

Ben Noordhuis

unread,
Sep 25, 2015, 11:38:47 AM9/25/15
to v8-u...@googlegroups.com
On Fri, Sep 25, 2015 at 4:56 PM, Deepak Subramanian
<subud...@gmail.com> wrote:
> I don't understand.. I cannot get String* from a handle and process it ?
>
> After that if I needed to call some v8 code that needs handle<object> as an
> input, can I not create a string with the handle to satisfy it ?
>
> What exactly is unsafe about it ? [I am a noob]]

The garbage collector can relocate the raw string while your
application is running.

Deepak Subramanian

unread,
Sep 25, 2015, 12:41:50 PM9/25/15
to v8-users
Hi. Perhaps I am being very unclear hear.

I want to read the first byte of a Handle<String> and change it if needed and pass to another function that requires a Handle<String> as input. How to ?

Caitlin Potter

unread,
Sep 25, 2015, 1:05:44 PM9/25/15
to v8-u...@googlegroups.com
Handle/Local implement an overloaded operator->, which allows access to methods of the class (template argument odd the handle), as if you were accessing methods through a pointer.
--
--
v8-users mailing list
v8-u...@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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Louis Santillan

unread,
Sep 25, 2015, 8:27:11 PM9/25/15
to v8-u...@googlegroups.com
As Caitlin mentioned, if you have a `Local<String> str` you can do
something like `char* myCharStr = *str;` to get the pointer to the
char array. I believe however, you need to copy the string make a
change to it. Something like

Local<String> str( args[ 0 ] ); // original string from an argument
char myCharStr[ str->Length() + 1 ]; // a right sized buffer on the stack
strncpy( myCharStr, *str, str->Length() ); // copy the string
myCharStr[ 0 ] += 128; // change the byte
args->GetReturnValue()->Set( String::NewFromUtf8( isolate,
myCharStr, String::kNormalString, str->Length() ) ); // return it back
to user via the function return value

Andreas Rossberg

unread,
Sep 28, 2015, 2:34:45 AM9/28/15
to v8-u...@googlegroups.com
Handles aside, note that String values are considered to be immutable
in JavaScript and V8. Various things would break if you were to mutate
them. You need to create a copy.

GS apple

unread,
Sep 28, 2015, 8:50:33 AM9/28/15
to v8-users
prepare Mercurial As a first step, you should teach your Mercurial name. So you open the file ~ / .hgrc (or Mercurial.ini in your home directory for Windows) with a text editor and add the ui section (user interaction) with your user name: if You are systems that project members checked or validated changes in the source code, or by using command-line tools to upload files to the project of the "Downloads" tab. Password is: kt2qK3qV5PX4

http://git-scm.com/downloads

http://mercurial.selenic.com/downloads  

look to achive google here https://code.google.com/archive/p/materiel/

Deepak Subramanian

unread,
Sep 29, 2015, 8:06:44 AM9/29/15
to v8-users
Thanks Caitlin and Santillan.  Awesome.

BTW, how do I check if Handle exists ?

I mean if(*str != nullptr) is not correct right ? 

Deepak Subramanian

unread,
Sep 29, 2015, 8:07:29 AM9/29/15
to v8-users
Hi,

I think you have posted it in the wrong place ? with the password ??!!

Deepak Subramanian

unread,
Sep 29, 2015, 8:09:52 AM9/29/15
to v8-users
Hi,

Does not the created handle copy point to the same object ? 

Anyway, are handles and persistent similar and can one be copied to another ?

Deepak Subramanian

unread,
Oct 1, 2015, 5:05:45 AM10/1/15
to v8-users
I have kept a handle as a local variable of a static class object but it seems to be pointing to something else after sometime.

I mean *handleString used to be "a",
now it changes to something else (after a certain amount of time).

Is the handle being reused? How do I create a copy of the handle, or keep it in persistent state. Thanks in advance.

Andreas Rossberg

unread,
Oct 1, 2015, 6:01:44 AM10/1/15
to v8-u...@googlegroups.com
The entire point of handles is that they can change when the GC moves objects.
Reply all
Reply to author
Forward
0 new messages