Subj : Re: How to pass boolean value from C++ back to script? (jsapi) To : netscape.public.mozilla.jseng From : Jens Bannmann Date : Mon Jan 03 2005 03:11 pm Okay, with a little help from biesi on IRC I figured it out. I'll post the simplified code below, don't forget to add some feedback in case of invalid parameters. And make sure you don't pass the boolean back when the user supplied null instead of a JS object - that will crash mozilla... For a full working example, see mozilla/xpinstall/src/nsJSInstall.cpp (or bug 216399), search for confirmEx. Best regards, Jens Reading the boolean parameter (argv[7] here): | | JSObject* jsObject; | jsval jsCheckState; | PRBool checkState = PR_FALSE; | | if (!JSVAL_IS_NULL(argv[7]) | && JSVAL_IS_OBJECT(argv[7])) | jsObject = JSVAL_TO_OBJECT(argv[7]); | if (JS_GetProperty(cx, jsObject, "value", &jsCheckState) | && JSVAL_IS_BOOLEAN(jsCheckState)) | { | JS_ValueToBoolean(cx, jsCheckState, &checkState); | } | } Passing it back: | | jsCheckState = BOOLEAN_TO_JSVAL(checkState); | JS_SetProperty(cx, jsObject, "value", &jsCheckState); .