本文整理汇总了C++中JSValue::isBoolean方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::isBoolean方法的具体用法?C++ JSValue::isBoolean怎么用?C++ JSValue::isBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::isBoolean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JSValueIsBoolean
bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value)
{
if (!ctx) {
ASSERT_NOT_REACHED();
return false;
}
ExecState* exec = toJS(ctx);
JSLockHolder locker(exec);
JSValue jsValue = toJS(exec, value);
return jsValue.isBoolean();
}
示例2: null
static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value, int maxDepth)
{
if (!value) {
ASSERT_NOT_REACHED();
return 0;
}
if (!maxDepth)
return 0;
maxDepth--;
if (value.isNull() || value.isUndefined())
return InspectorValue::null();
if (value.isBoolean())
return InspectorBasicValue::create(value.asBoolean());
if (value.isNumber())
return InspectorBasicValue::create(value.asNumber());
if (value.isString()) {
String s = value.getString(scriptState);
return InspectorString::create(String(s.characters(), s.length()));
}
if (value.isObject()) {
if (isJSArray(value)) {
RefPtr<InspectorArray> inspectorArray = InspectorArray::create();
JSArray* array = asArray(value);
unsigned length = array->length();
for (unsigned i = 0; i < length; i++) {
JSValue element = array->getIndex(scriptState, i);
RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element, maxDepth);
if (!elementValue)
return 0;
inspectorArray->pushValue(elementValue);
}
return inspectorArray;
}
RefPtr<InspectorObject> inspectorObject = InspectorObject::create();
JSObject* object = value.getObject();
PropertyNameArray propertyNames(scriptState);
object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, ExcludeDontEnumProperties);
for (size_t i = 0; i < propertyNames.size(); i++) {
const Identifier& name = propertyNames[i];
JSValue propertyValue = object->get(scriptState, name);
RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue, maxDepth);
if (!inspectorValue)
return 0;
inspectorObject->setValue(String(name.characters(), name.length()), inspectorValue);
}
return inspectorObject;
}
ASSERT_NOT_REACHED();
return 0;
}
示例3: predictionFromValue
PredictedType predictionFromValue(JSValue value)
{
if (value.isInt32())
return PredictInt32;
if (value.isDouble())
return PredictDouble;
if (value.isCell())
return predictionFromCell(value.asCell());
if (value.isBoolean())
return PredictBoolean;
ASSERT(value.isUndefinedOrNull());
return PredictOther;
}
示例4: null
static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value)
{
if (!value) {
ASSERT_NOT_REACHED();
return 0;
}
if (value.isNull() || value.isUndefined())
return InspectorValue::null();
if (value.isBoolean())
return InspectorBasicValue::create(value.getBoolean());
if (value.isNumber())
return InspectorBasicValue::create(value.uncheckedGetNumber());
if (value.isString()) {
UString s = value.getString(scriptState);
return InspectorString::create(String(s.characters(), s.length()));
}
if (value.isObject()) {
if (isJSArray(&scriptState->globalData(), value)) {
RefPtr<InspectorArray> inspectorArray = InspectorArray::create();
JSArray* array = asArray(value);
unsigned length = array->length();
for (unsigned i = 0; i < length; i++) {
JSValue element = array->getIndex(i);
RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element);
if (!elementValue) {
ASSERT_NOT_REACHED();
elementValue = InspectorValue::null();
}
inspectorArray->pushValue(elementValue);
}
return inspectorArray;
}
RefPtr<InspectorObject> inspectorObject = InspectorObject::create();
JSObject* object = value.getObject();
PropertyNameArray propertyNames(scriptState);
object->getOwnPropertyNames(scriptState, propertyNames);
for (size_t i = 0; i < propertyNames.size(); i++) {
const Identifier& name = propertyNames[i];
JSValue propertyValue = object->get(scriptState, name);
RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue);
if (!inspectorValue) {
ASSERT_NOT_REACHED();
inspectorValue = InspectorValue::null();
}
inspectorObject->setValue(String(name.characters(), name.length()), inspectorValue);
}
return inspectorObject;
}
ASSERT_NOT_REACHED();
return 0;
}
示例5: predictionIsValid
inline bool predictionIsValid(JSGlobalData* globalData, JSValue value, PredictedType type)
{
// this takes into account only local variable predictions that get enforced
// on SetLocal.
if (isInt32Prediction(type))
return value.isInt32();
if (isArrayPrediction(type))
return isJSArray(globalData, value);
if (isBooleanPrediction(type))
return value.isBoolean();
return true;
}
示例6: predictionFromValue
PredictedType predictionFromValue(JSValue value)
{
if (value.isInt32())
return PredictInt32;
if (value.isDouble()) {
double number = value.asNumber();
if (number == number)
return PredictDoubleReal;
return PredictDoubleNaN;
}
if (value.isCell())
return predictionFromCell(value.asCell());
if (value.isBoolean())
return PredictBoolean;
ASSERT(value.isUndefinedOrNull());
return PredictOther;
}
示例7: convertJSValueToNPVariant
void NPRuntimeObjectMap::convertJSValueToNPVariant(ExecState* exec, JSValue value, NPVariant& variant)
{
JSLock lock(SilenceAssertionsOnly);
VOID_TO_NPVARIANT(variant);
if (value.isNull()) {
NULL_TO_NPVARIANT(variant);
return;
}
if (value.isUndefined()) {
VOID_TO_NPVARIANT(variant);
return;
}
if (value.isBoolean()) {
BOOLEAN_TO_NPVARIANT(value.toBoolean(exec), variant);
return;
}
if (value.isNumber()) {
DOUBLE_TO_NPVARIANT(value.toNumber(exec), variant);
return;
}
if (value.isString()) {
CString utf8String = value.toString(exec).utf8();
// This should use NPN_MemAlloc, but we know that it uses malloc under the hood.
char* utf8Characters = static_cast<char*>(malloc(utf8String.length()));
memcpy(utf8Characters, utf8String.data(), utf8String.length());
STRINGN_TO_NPVARIANT(utf8Characters, utf8String.length(), variant);
return;
}
if (value.isObject()) {
NPObject* npObject = getOrCreateNPObject(asObject(value));
OBJECT_TO_NPVARIANT(npObject, variant);
return;
}
ASSERT_NOT_REACHED();
}
示例8: getBooleanFromJSON
static bool getBooleanFromJSON(ExecState* exec, JSObject* json, const char* key, bool& result)
{
Identifier identifier(exec, key);
PropertySlot slot(json);
if (!json->getPropertySlot(exec, identifier, slot))
return false;
JSValue jsValue = slot.getValue(exec, identifier);
ASSERT(!exec->hadException());
if (!jsValue.isBoolean()) {
throwTypeError(exec, String::format("Expected a boolean value for \"%s\" JSON key", key));
return false;
}
result = jsValue.asBoolean();
return true;
}
示例9: convertValueToNPVariant
// Variant value must be released with NPReleaseVariantValue()
void convertValueToNPVariant(ExecState* exec, JSValue value, NPVariant* result)
{
JSLock lock(SilenceAssertionsOnly);
VOID_TO_NPVARIANT(*result);
if (value.isString()) {
UString ustring = value.toString(exec);
CString cstring = ustring.utf8();
NPString string = { (const NPUTF8*)cstring.data(), static_cast<uint32_t>(cstring.length()) };
NPN_InitializeVariantWithStringCopy(result, &string);
} else if (value.isNumber()) {
DOUBLE_TO_NPVARIANT(value.toNumber(exec), *result);
} else if (value.isBoolean()) {
BOOLEAN_TO_NPVARIANT(value.toBoolean(exec), *result);
} else if (value.isNull()) {
NULL_TO_NPVARIANT(*result);
} else if (value.isObject()) {
JSObject* object = asObject(value);
if (object->classInfo() == &CRuntimeObject::s_info) {
CRuntimeObject* runtimeObject = static_cast<CRuntimeObject*>(object);
CInstance* instance = runtimeObject->getInternalCInstance();
if (instance) {
NPObject* obj = instance->getObject();
_NPN_RetainObject(obj);
OBJECT_TO_NPVARIANT(obj, *result);
}
} else {
#ifdef ANDROID
RootObject* rootObject = findRootObject(exec->dynamicGlobalObject());
if (!rootObject)
rootObject = findRootObject(exec->lexicalGlobalObject());
#else
JSGlobalObject* globalObject = exec->dynamicGlobalObject();
RootObject* rootObject = findRootObject(globalObject);
#endif
if (rootObject) {
NPObject* npObject = _NPN_CreateScriptObject(0, object, rootObject);
OBJECT_TO_NPVARIANT(npObject, *result);
}
}
}
}
示例10: computeStatistics
void ValueProfile::computeStatistics(Statistics& statistics) const
{
for (unsigned i = 0; i < numberOfBuckets; ++i) {
JSValue value = JSValue::decode(m_buckets[i]);
if (!value)
continue;
statistics.samples++;
if (value.isInt32())
statistics.int32s++;
else if (value.isDouble())
statistics.doubles++;
else if (value.isCell())
computeStatistics(value.asCell()->structure()->classInfo(), statistics);
else if (value.isBoolean())
statistics.booleans++;
}
}
示例11: JSTryConvertToBooleans
JSLR_API bool _cdecl JSTryConvertToBooleans(JSContextRef ctx, JSValueRef** value, size_t length, int** indices, bool** result)
{
auto values = *value;
auto res = *result;
auto ind = *indices;
ExecState* exec = toJS(ctx);
for (unsigned int i = 0; i < length; i++)
{
auto ptr = values[ind[i]];
JSValueRef js_value = *&ptr;
JSValue jsValue = toJS(exec, js_value);
if (!jsValue.isBoolean())
{
return false;
}
*&res[i] = jsValue.toBoolean(exec);
}
return true;
}
示例12: entryShim
::JSType JSValueGetType(JSContextRef ctx, JSValueRef value)
{
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
JSValue jsValue = toJS(exec, value);
if (jsValue.isUndefined())
return kJSTypeUndefined;
if (jsValue.isNull())
return kJSTypeNull;
if (jsValue.isBoolean())
return kJSTypeBoolean;
if (jsValue.isNumber())
return kJSTypeNumber;
if (jsValue.isString())
return kJSTypeString;
ASSERT(jsValue.isObject());
return kJSTypeObject;
}
示例13: entryShim
::JSType JSValueGetType(JSContextRef ctx, JSValueRef value)
{
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
JSValue jsValue = toJS(exec, value);
if (jsValue.isUndefined())
return UndefinedType;
if (jsValue.isNull())
return NullType;
if (jsValue.isBoolean())
return BooleanType;
if (jsValue.isNumber())
return NumberType;
if (jsValue.isString())
return StringType;
Q_ASSERT(jsValue.isObject());
return ObjectType;
}
示例14: speculationFromValue
SpeculatedType speculationFromValue(JSValue value)
{
if (value.isEmpty())
return SpecEmpty;
if (value.isInt32())
return SpecInt32;
if (value.isDouble()) {
double number = value.asNumber();
if (number != number)
return SpecDoubleNaN;
if (value.isMachineInt())
return SpecInt52AsDouble;
return SpecNonIntAsDouble;
}
if (value.isCell())
return speculationFromCell(value.asCell());
if (value.isBoolean())
return SpecBoolean;
ASSERT(value.isUndefinedOrNull());
return SpecOther;
}
示例15: jsTypeStringForValue
JSValue jsTypeStringForValue(CallFrame* callFrame, JSValue v)
{
if (v.isUndefined())
return jsNontrivialString(callFrame, "undefined");
if (v.isBoolean())
return jsNontrivialString(callFrame, "boolean");
if (v.isNumber())
return jsNontrivialString(callFrame, "number");
if (v.isString())
return jsNontrivialString(callFrame, "string");
if (v.isObject()) {
// Return "undefined" for objects that should be treated
// as null when doing comparisons.
if (asObject(v)->structure()->typeInfo().masqueradesAsUndefined())
return jsNontrivialString(callFrame, "undefined");
CallData callData;
if (asObject(v)->getCallData(callData) != CallTypeNone)
return jsNontrivialString(callFrame, "function");
}
return jsNontrivialString(callFrame, "object");
}