Comments (3)
bool js_gaf_GAFAsset_create(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
bool ok = true;
if (argc == 2) {
std::string arg0;
std::function<void (std::basic_string<char> *)> arg1;
ok &= jsval_to_std_string(cx, argv[0], &arg0);
do {
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1]));
auto lambda = [=](std::basic_string<char>* larg0) -> void {
jsval largv[1];
do {
if (larg0) {
js_proxy_t *jsProxy = js_get_or_create_proxy<std::basic_string<char>>(cx, (std::basic_string<char>*)larg0);
largv[0] = OBJECT_TO_JSVAL(jsProxy->obj);
} else {
largv[0] = JSVAL_NULL;
}
} while (0);
jsval rval;
bool ok = func->invoke(1, &largv[0], rval);
if (!ok && JS_IsExceptionPending(cx)) {
JS_ReportPendingException(cx);
}
};
arg1 = lambda;
} while(0)
;
JSB_PRECONDITION2(ok, cx, false, "js_gaf_GAFAsset_create : Error processing arguments");
gaf::GAFAsset* ret = gaf::GAFAsset::create(arg0, arg1);
jsval jsret = JSVAL_NULL;
do {
if (ret) {
js_proxy_t *jsProxy = js_get_or_create_proxy<gaf::GAFAsset>(cx, (gaf::GAFAsset*)ret);
jsret = OBJECT_TO_JSVAL(jsProxy->obj);
} else {
jsret = JSVAL_NULL;
}
} while (0);
JS_SET_RVAL(cx, vp, jsret);
return true;
}
JS_ReportError(cx, "js_gaf_GAFAsset_create : wrong number of arguments");
return false;
}
where
typedef std::function<void(std::string*)> Delegate_t;
GAFAsset* GAFAsset::create(const std::string& gafFilePath, Delegate_t delegate)
{
std::string path;
...
if(delegate)
{
delegate(&path)
}
...
}
After calling delegate
the following line in generated binding will produce crash:
largv[0] = OBJECT_TO_JSVAL(jsProxy->obj);
as jsProxy
is a null pointer;
from bindings-generator.
How about enclosing lambda in
do {
if (!JSVAL_IS_NULL(argv[1]))
{
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1]));
auto lambda = [=](std::basic_string<char>* larg0) -> void {
...
};
arg1 = lambda;
}
else
{
arg1 = nullptr;
}
} while(0);
from bindings-generator.
Hi, @Teivaz Thanks for your suggestions and your pull request, I agree with the general idea and I have commented on your PR, please take a look.
from bindings-generator.
Related Issues (10)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bindings-generator.