How do I get the value of a JSObject property from C?

﹥>﹥吖頭↗ 提交于 2019-12-10 12:23:19

问题


In SpiderMonkey, how do I get the value of a property of a JSObject from within my C code?

static JSBool
JSD_getter(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    jsval js_id;
    JS_GetProperty(cx, obj, "id", &js_id); // js_id has JavaScript type
    int c_id;
    JS_ValueToInt32(cx, js_id, &c_id); // Now, c_id contains the actual value
}                                      // of obj.id, as a C native type

回答1:


JS_GetProperty()



来源:https://stackoverflow.com/questions/107317/how-do-i-get-the-value-of-a-jsobject-property-from-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!