如何从C获取JSObject属性的值?

时间:2008-09-20 05:54:29

标签: javascript spidermonkey accessor

在SpiderMonkey中,如何从C代码中获取JSObject的属性值?

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 个答案:

答案 0 :(得分:1)

JS_GetProperty()