MethodToInCa for method returning a reference

0 views
Skip to first unread message

avasilev

unread,
Sep 20, 2011, 10:45:08 AM9/20/11
to v8-juice-js-dev
Hi all,

I am trying to bind a method via MethodToInCa, where the method is
with the signature
'std::string&()'
I get an error from the compiler. When I try to bind a method that
returns just a std::string the code compiles. Is it possibleto bind a
method that returns a reference?

Thanks
Alex

Stephan Beal

unread,
Sep 20, 2011, 10:56:51 AM9/20/11
to v8-juice-js-dev
On Sep 20, 4:45 pm, avasilev <alxvasi...@gmail.com> wrote:
> 'std::string&()'
> I get an error from the compiler. When I try to bind a method that
> returns just a std::string the code compiles. Is it possibleto bind a
> method that returns a reference?

Yes and no. Yes, it can be done for most bound client types, but
std::string is a special case. It is very rare to pass a std::string
by pointer, so std::string is treated like a POD data type for
purposes of the bindings. Because of that, binding by reference won't
work in this particular case. Client-specified types are always passed
around by pointer, but std::string is simply treated as a "temporary"
v8::String proxy. In order to be able to pass it around by reference/
pointer, we would need somewhere to actually store the native string
object, which means we would have to dynamically allocate it and store
it somewhere in a v8::External.

JS won't allow us to change string data - we have to create a new
string - so a function returning a (string &) is not semantically
legal vis-a-vis JS.
Reply all
Reply to author
Forward
0 new messages