On Sat, Jun 25, 2011 at 9:20 AM, Brendan Miller <[email protected]>wrote:
> You can solve the reference and const issues with type traits. > i'm already at the limit of that, i think, and i can't take it another step further without creating duplicate copies of all my forwarding-related templates, one for unlocked and one for locked. While i could do that, it would be lots of overkill. My current workaround is working beautifully: http://code.google.com/p/v8-juice/wiki/V8Convert#Special_Case:_Unlocking_the_v8_Engine > If its a reference, you can remove using remove_reference<T>::type. > Similarly with remove_const<T>::type. This is available in > tr1/C++0x/boost. It's also pretty easy to write these type traits > metafunctions yourself if you don't want to depend on tr1/C++0x/boost. > i can't just remove the reference - the types have to be kept 100% intact for this purpose. i've found a decent workaround, but wish that Unlocker had a method with which we could prematurely descope it. Granted, this is a 1-in-a-million use case, and i've never missed that feature before. > > If you don't want to require T to be default constructable, you can't > create rv on the stack given your scoping requirement. > It's unfortunately a bit more involved in this case. If a user gives me (T &), i need to be able to (and can currently) do: T & t( boundNativeFunction(...) ); but i can't (it's illegal to) do: T & t; Unlocker sentry; t = boundNativeFunction(); So what i've done is create a tiny wrapper which heap-allocates the unlocker, then i: UnlockWrapper unl; T & t( boundNativeFunction(...) ); unl.Dispose(); return CastToJS(t); /// i need t to be in scope when i return. Try reformulating that with a vanilla v8::Unlocker - i don't think it can be syntactically done for that concrete use case.(To be clear: i'm not looking for a solution anymore, but would be interested if one does actually exist.) This file: http://code.google.com/p/v8-juice/source/browse/convert/include/v8/convert/detail/invocable_generated.hpp Is full of examples. -- ----- stephan beal http://wanderinghorse.net/home/stephan/ -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
