How to access string of Handle<String>?

23 views
Skip to first unread message

Bodo Kaiser

unread,
Jun 6, 2013, 11:20:56 AM6/6/13
to v8-u...@googlegroups.com
Hello,

I am trying to get a "const char *" string out of a v8 String Object.

Unfortunately all access result in a segmentation fault:

    /*
    const char * string;
   
    string = (const char *) malloc(args[0]->ToString()
            ->GetExternalAsciiStringResource()->length());

    string = args[0]->ToString()
        ->GetExternalAsciiStringResource()->data();*/

    printf("%s\n", args[0]->ToString()->GetExternalAsciiStringResource()->data());

Can somebody tell me how to access the string properly?

Bodo

Stephan Beal

unread,
Jun 6, 2013, 11:24:10 AM6/6/13
to v8-u...@googlegroups.com
On Thu, Jun 6, 2013 at 5:20 PM, Bodo Kaiser <i...@bodokaiser.io> wrote:
I am trying to get a "const char *" string out of a v8 String Object.

Unfortunately all access result in a segmentation fault:

Try: (i'm working from memory, but i _think_ this is right:

v8::Utf8Value str( *yourStringHandle );
puts( *str );

            ->GetExternalAsciiStringResource()->length());


"external" strings are a special case of strings which are allocated "elsewhere" (outside of v8), or at least that's my understanding.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/

Bodo Kaiser

unread,
Jun 6, 2013, 11:43:20 AM6/6/13
to v8-u...@googlegroups.com
Hey,

yes this was the right direction:

char * string = (* String::AsciiValue(args[0]->ToString));

--
--
v8-users mailing list
v8-u...@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/Bm1JXY9NY2c/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages