本文整理汇总了C++中js::Value::isBoolean方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::isBoolean方法的具体用法?C++ Value::isBoolean怎么用?C++ Value::isBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::Value
的用法示例。
在下文中一共展示了Value::isBoolean方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dataStr
void
nsGeolocationService::HandleMozsettingChanged(const PRUnichar* aData)
{
// The string that we're interested in will be a JSON string that looks like:
// {"key":"gelocation.enabled","value":true}
SafeAutoJSContext cx;
nsDependentString dataStr(aData);
JS::Value val;
if (!JS_ParseJSON(cx, dataStr.get(), dataStr.Length(), &val) || !val.isObject()) {
return;
}
JSObject &obj(val.toObject());
JS::Value key;
if (!JS_GetProperty(cx, &obj, "key", &key) || !key.isString()) {
return;
}
JSBool match;
if (!JS_StringEqualsAscii(cx, key.toString(), GEO_SETINGS_ENABLED, &match) || (match != JS_TRUE)) {
return;
}
JS::Value value;
if (!JS_GetProperty(cx, &obj, "value", &value) || !value.isBoolean()) {
return;
}
HandleMozsettingValue(value.toBoolean());
}
示例2:
void
nsGeolocationSettings::HandleGeolocationAlaEnabledChange(const JS::Value& aVal)
{
if (!aVal.isBoolean()) {
return;
}
mAlaEnabled = aVal.toBoolean();
}
示例3: Handle
NS_IMETHOD Handle(const nsAString& aName, const JS::Value& aResult)
{
MOZ_ASSERT(NS_IsMainThread());
// The geolocation is enabled by default:
bool value = true;
if (aResult.isBoolean()) {
value = aResult.toBoolean();
}
MozSettingValue(value);
return NS_OK;
}
示例4:
NS_IMETHODIMP
SmsFilter::SetRead(JSContext* aCx, const JS::Value& aRead)
{
if (aRead == JSVAL_NULL) {
mData.read() = eReadState_Unknown;
return NS_OK;
}
if (!aRead.isBoolean()) {
return NS_ERROR_INVALID_ARG;
}
mData.read() = aRead.toBoolean() ? eReadState_Read : eReadState_Unread;
return NS_OK;
}
示例5: return
std::string
gjs_debug_value(JS::Value v)
{
std::ostringstream out;
if (v.isNull())
return "null";
if (v.isUndefined())
return "undefined";
if (v.isInt32()) {
out << v.toInt32();
return out.str();
}
if (v.isDouble()) {
out << v.toDouble();
return out.str();
}
if (v.isString()) {
out << gjs_debug_string(v.toString());
return out.str();
}
if (v.isSymbol()) {
out << gjs_debug_symbol(v.toSymbol());
return out.str();
}
if (v.isObject() && js::IsFunctionObject(&v.toObject())) {
JSFunction* fun = JS_GetObjectFunction(&v.toObject());
JSString *display_name = JS_GetFunctionDisplayId(fun);
if (display_name)
out << "<function " << gjs_debug_string(display_name);
else
out << "<unnamed function";
out << " at " << fun << '>';
return out.str();
}
if (v.isObject()) {
out << gjs_debug_object(&v.toObject());
return out.str();
}
if (v.isBoolean())
return (v.toBoolean() ? "true" : "false");
if (v.isMagic())
return "<magic>";
return "unexpected value";
}
示例6: Handle
NS_DECL_ISUPPORTS
NS_IMETHOD Handle(const nsAString& aName, const JS::Value& aResult)
{
MOZ_ASSERT(NS_IsMainThread());
if (!aResult.isBoolean()) {
NS_WARNING("Setting for '" BLUETOOTH_ENABLED_SETTING "' is not a boolean!");
return NS_OK;
}
// It is theoretically possible to shut down before the first settings check
// has completed (though extremely unlikely).
if (gBluetoothService) {
return gBluetoothService->HandleStartupSettingsCheck(aResult.toBoolean());
}
return NS_OK;
}
示例7: JS_ReportPendingException
nsresult
BluetoothService::HandleSettingsChanged(const nsAString& aData)
{
MOZ_ASSERT(NS_IsMainThread());
// The string that we're interested in will be a JSON string that looks like:
// {"key":"bluetooth.enabled","value":true}
JSContext* cx = nsContentUtils::GetSafeJSContext();
if (!cx) {
return NS_OK;
}
JS::Value val;
if (!JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val)) {
return JS_ReportPendingException(cx) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
if (!val.isObject()) {
return NS_OK;
}
JSObject& obj(val.toObject());
JS::Value key;
if (!JS_GetProperty(cx, &obj, "key", &key)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!key.isString()) {
return NS_OK;
}
JSBool match;
if (!JS_StringEqualsAscii(cx, key.toString(), BLUETOOTH_ENABLED_SETTING,
&match)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!match) {
return NS_OK;
}
JS::Value value;
if (!JS_GetProperty(cx, &obj, "value", &value)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!value.isBoolean()) {
MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.enabled'!");
return NS_ERROR_UNEXPECTED;
}
if (value.toBoolean() == IsEnabled()) {
// Nothing to do here.
return NS_OK;
}
nsresult rv;
if (IsEnabled()) {
rv = Stop();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
rv = Start();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
示例8: asRootedValue
/*! @brief Fill a bottle with the contents of an object.
@param[in] jct The %JavaScript engine context.
@param[in,out] aBottle The bottle to be filled.
@param[in] theData The value to be sent.
@param[in] topLevel @c true if this is the outermost list of an object. */
static void
fillBottleFromValue(JSContext * jct,
yarp::os::Bottle & aBottle,
JS::Value theData,
const bool topLevel)
{
ODL_ENTER(); //####
ODL_P2("jct = ", jct, "aBottle = ", &aBottle); //####
ODL_B1("topLevel = ", topLevel); //####
JS::RootedValue asRootedValue(jct);
asRootedValue = theData;
if (theData.isBoolean())
{
aBottle.addInt(JS::ToBoolean(asRootedValue) ? 1 : 0);
}
else if (theData.isDouble())
{
double aValue;
if (JS::ToNumber(jct, asRootedValue, &aValue))
{
aBottle.addDouble(aValue);
}
}
else if (theData.isInt32())
{
int32_t aValue;
if (JS::ToInt32(jct, asRootedValue, &aValue))
{
aBottle.addInt(aValue);
}
}
else if (theData.isString())
{
JSString * asString = theData.toString();
char * asChars = JS_EncodeString(jct, asString);
aBottle.addString(asChars);
JS_free(jct, asChars);
}
else if (theData.isObject())
{
JS::RootedObject asObject(jct);
if (JS_ValueToObject(jct, asRootedValue, &asObject))
{
bool processed = false;
#if (47 <= MOZJS_MAJOR_VERSION)
bool isArray;
#endif // 47 <= MOZJS_MAJOR_VERSION
#if (47 <= MOZJS_MAJOR_VERSION)
if (JS_IsArrayObject(jct, asObject, &isArray))
#else // 47 > MOZJS_MAJOR_VERSION
if (JS_IsArrayObject(jct, asObject))
#endif // 47 > MOZJS_MAJOR_VERSION
{
uint32_t arrayLength;
if (JS_GetArrayLength(jct, asObject, &arrayLength))
{
// Treat as a list
if (topLevel)
{
for (uint32_t ii = 0; arrayLength > ii; ++ii)
{
JS::RootedValue anElement(jct);
if (JS_GetElement(jct, asObject, ii, &anElement))
{
fillBottleFromValue(jct, aBottle, anElement, false);
}
}
}
else
{
yarp::os::Bottle & innerList(aBottle.addList());
for (uint32_t ii = 0; arrayLength > ii; ++ii)
{
JS::RootedValue anElement(jct);
if (JS_GetElement(jct, asObject, ii, &anElement))
{
fillBottleFromValue(jct, innerList, anElement, false);
}
}
}
processed = true;
}
}
if (! processed)
//.........这里部分代码省略.........
示例9: dataStr
nsresult
BluetoothManager::HandleMozsettingChanged(const PRUnichar* aData)
{
// The string that we're interested in will be a JSON string that looks like:
// {"key":"bluetooth.enabled","value":true}
nsresult rv;
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
if (NS_FAILED(rv)) {
return NS_ERROR_UNEXPECTED;
}
JSContext *cx = sc->GetNativeContext();
if (!cx) {
return NS_OK;
}
// In the following [if] blocks, NS_OK will be returned even if JS_* functions
// return false. That's because this function gets called whenever mozSettings
// changes, so that we'll receive signals we're not interested in and it would
// be one of the reasons for making JS_* functions return false.
nsDependentString dataStr(aData);
JS::Value val;
if (!JS_ParseJSON(cx, dataStr.get(), dataStr.Length(), &val)) {
return NS_OK;
}
if (!val.isObject()) {
return NS_OK;
}
JSObject &obj(val.toObject());
JS::Value key;
if (!JS_GetProperty(cx, &obj, "key", &key)) {
return NS_OK;
}
if (!key.isString()) {
return NS_OK;
}
JSBool match;
if (!JS_StringEqualsAscii(cx, key.toString(), "bluetooth.enabled", &match)) {
return NS_OK;
}
if (!match) {
return NS_OK;
}
JS::Value value;
if (!JS_GetProperty(cx, &obj, "value", &value)) {
return NS_OK;
}
if (!value.isBoolean()) {
return NS_OK;
}
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
NS_WARNING("BluetoothService not available!");
return NS_ERROR_FAILURE;
}
bool enabled = value.toBoolean();
nsCOMPtr<nsIRunnable> resultTask = new ToggleBtResultTask(this, enabled);
if (enabled) {
if (NS_FAILED(bs->Start(resultTask))) {
return NS_ERROR_FAILURE;
}
} else {
if (NS_FAILED(bs->Stop(resultTask))) {
return NS_ERROR_FAILURE;
}
}
return NS_OK;
}