cocos2d/cocos2d-x — pull request #3169 by colesbury (2013-07-16 23:43:10+00:00)
Title: Add JSFunctionWrapper in preparation for bindings-generator changes.

This adds an implementation of JSFunctionWrapper, which is used by this bindings-generator PR:

https://github.com/cocos2d/bindings-generator/pull/16

The JSFunctionWrapper adds roots to a JSObject and jsval for the lifetime of the wrappers. The intended use is something like this:

std::shared_ptr func(new JSFunctionWrapper(cx, jsthis, jsfunc));
auto lambda = [=]() -> { func.invoke(...) }

The lambda captures the shared_ptr by value, so the lifetime of the wrapper (and JS root) is tied to the lifetime of the lambda.