Subj : Re: How to pass boolean value from C++ back to script? (jsapi) To : Jens Bannmann From : Brendan Eich Date : Mon Jan 03 2005 04:48 pm Jens Bannmann wrote: > 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])) Combine these into one !JSVAL_IS_PRIMITIVE(argv[7]) test. > | jsObject = JSVAL_TO_OBJECT(argv[7]); > | if (JS_GetProperty(cx, jsObject, "value", &jsCheckState) If JS_GetProperty fails, you want to fail too. It means an error was reported or an exception thrown. > | && JSVAL_IS_BOOLEAN(jsCheckState)) > | { > | JS_ValueToBoolean(cx, jsCheckState, &checkState); You might want to check for failure here, too, and propagate any false return value. > | } > | } > > > Passing it back: > | > | jsCheckState = BOOLEAN_TO_JSVAL(checkState); > | JS_SetProperty(cx, jsObject, "value", &jsCheckState); Another JS API call whose return value should be checked. /be .