本文整理汇总了C++中JSValue::isNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::isNumber方法的具体用法?C++ JSValue::isNumber怎么用?C++ JSValue::isNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::isNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extractSourceInformationFromException
static bool extractSourceInformationFromException(JSC::ExecState* exec, JSObject* exceptionObject, int* lineNumber, int* columnNumber, String* sourceURL)
{
VM& vm = exec->vm();
auto scope = DECLARE_CATCH_SCOPE(vm);
// FIXME: <http://webkit.org/b/115087> Web Inspector: Should not need to evaluate JavaScript handling exceptions
JSValue lineValue = exceptionObject->getDirect(vm, Identifier::fromString(exec, "line"));
JSValue columnValue = exceptionObject->getDirect(vm, Identifier::fromString(exec, "column"));
JSValue sourceURLValue = exceptionObject->getDirect(vm, Identifier::fromString(exec, "sourceURL"));
bool result = false;
if (lineValue && lineValue.isNumber()
&& sourceURLValue && sourceURLValue.isString()) {
*lineNumber = int(lineValue.toNumber(exec));
*columnNumber = columnValue && columnValue.isNumber() ? int(columnValue.toNumber(exec)) : 0;
*sourceURL = sourceURLValue.toWTFString(exec);
result = true;
} else if (ErrorInstance* error = jsDynamicCast<ErrorInstance*>(vm, exceptionObject)) {
unsigned unsignedLine;
unsigned unsignedColumn;
result = getLineColumnAndSource(error->stackTrace(), unsignedLine, unsignedColumn, *sourceURL);
*lineNumber = static_cast<int>(unsignedLine);
*columnNumber = static_cast<int>(unsignedColumn);
}
if (sourceURL->isEmpty())
*sourceURL = "undefined"_s;
scope.clearException();
return result;
}
示例2: create
PassRefPtr<ScriptCallStack> createScriptCallStackFromException(JSC::ExecState* exec, JSC::JSValue& exception, size_t maxStackSize)
{
Vector<ScriptCallFrame> frames;
RefCountedArray<StackFrame> stackTrace = exec->vm().exceptionStack();
for (size_t i = 0; i < stackTrace.size() && i < maxStackSize; i++) {
if (!stackTrace[i].callee && frames.size())
break;
unsigned line;
unsigned column;
stackTrace[i].computeLineAndColumn(line, column);
String functionName = stackTrace[i].friendlyFunctionName(exec);
frames.append(ScriptCallFrame(functionName, stackTrace[i].sourceURL, line, column));
}
// FIXME: <http://webkit.org/b/115087> Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions
// Fallback to getting at least the line and sourceURL from the exception if it has values and the exceptionStack doesn't.
if (frames.size() > 0) {
const ScriptCallFrame& firstCallFrame = frames.first();
JSObject* exceptionObject = exception.toObject(exec);
if (exception.isObject() && firstCallFrame.sourceURL().isEmpty()) {
JSValue lineValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "line"));
int lineNumber = lineValue && lineValue.isNumber() ? int(lineValue.toNumber(exec)) : 0;
JSValue columnValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "column"));
int columnNumber = columnValue && columnValue.isNumber() ? int(columnValue.toNumber(exec)) : 0;
JSValue sourceURLValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "sourceURL"));
String exceptionSourceURL = sourceURLValue && sourceURLValue.isString() ? sourceURLValue.toString(exec)->value(exec) : ASCIILiteral("undefined");
frames[0] = ScriptCallFrame(firstCallFrame.functionName(), exceptionSourceURL, lineNumber, columnNumber);
}
}
return ScriptCallStack::create(frames);
}
示例3: null
static RefPtr<InspectorValue> jsToInspectorValue(ExecState* scriptState, JSValue value, int maxDepth)
{
if (!value) {
ASSERT_NOT_REACHED();
return nullptr;
}
if (!maxDepth)
return nullptr;
maxDepth--;
if (value.isNull() || value.isUndefined())
return InspectorValue::null();
if (value.isBoolean())
return InspectorValue::create(value.asBoolean());
if (value.isNumber() && value.isDouble())
return InspectorValue::create(value.asNumber());
if (value.isNumber() && value.isMachineInt())
return InspectorValue::create(static_cast<int>(value.asMachineInt()));
if (value.isString())
return InspectorValue::create(value.getString(scriptState));
if (value.isObject()) {
if (isJSArray(value)) {
Ref<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 nullptr;
inspectorArray->pushValue(WTFMove(elementValue));
}
return WTFMove(inspectorArray);
}
Ref<InspectorObject> inspectorObject = InspectorObject::create();
JSObject* object = value.getObject();
PropertyNameArray propertyNames(scriptState, PropertyNameMode::Strings);
object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, EnumerationMode());
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 nullptr;
inspectorObject->setValue(name.string(), WTFMove(inspectorValue));
}
return WTFMove(inspectorObject);
}
ASSERT_NOT_REACHED();
return nullptr;
}
示例4: sameValue
// See ES5.1 9.12
bool sameValue(ExecState* exec, JSValue a, JSValue b)
{
if (!a.isNumber())
return JSValue::strictEqual(exec, a, b);
if (!b.isNumber())
return false;
double x = a.asNumber();
double y = b.asNumber();
if (isnan(x))
return isnan(y);
return bitwise_cast<uint64_t>(x) == bitwise_cast<uint64_t>(y);
}
示例5: reportException
void reportException(ExecState* exec, JSValue exception, CachedScript* cachedScript)
{
if (isTerminatedExecutionException(exception))
return;
Interpreter::ErrorHandlingMode mode(exec);
RefPtr<ScriptCallStack> callStack(createScriptCallStackFromException(exec, exception, ScriptCallStack::maxCallStackSizeToCapture));
exec->clearException();
exec->clearSupplementaryExceptionInfo();
JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
if (JSDOMWindow* window = jsDynamicCast<JSDOMWindow*>(globalObject)) {
if (!window->impl()->isCurrentlyDisplayedInFrame())
return;
}
int lineNumber = 0;
int columnNumber = 0;
String exceptionSourceURL;
if (callStack->size()) {
const ScriptCallFrame& frame = callStack->at(0);
lineNumber = frame.lineNumber();
columnNumber = frame.columnNumber();
exceptionSourceURL = frame.sourceURL();
} else {
// There may not be an exceptionStack for a <script> SyntaxError. Fallback to getting at least the line and sourceURL from the exception.
JSObject* exceptionObject = exception.toObject(exec);
JSValue lineValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "line"));
lineNumber = lineValue && lineValue.isNumber() ? int(lineValue.toNumber(exec)) : 0;
JSValue columnValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "column"));
columnNumber = columnValue && columnValue.isNumber() ? int(columnValue.toNumber(exec)) : 0;
JSValue sourceURLValue = exceptionObject->getDirect(exec->vm(), Identifier(exec, "sourceURL"));
exceptionSourceURL = sourceURLValue && sourceURLValue.isString() ? sourceURLValue.toString(exec)->value(exec) : ASCIILiteral("undefined");
}
String errorMessage;
if (ExceptionBase* exceptionBase = toExceptionBase(exception))
errorMessage = exceptionBase->message() + ": " + exceptionBase->description();
else {
// FIXME: <http://webkit.org/b/115087> Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions
// If this is a custon exception object, call toString on it to try and get a nice string representation for the exception.
errorMessage = exception.toString(exec)->value(exec);
exec->clearException();
exec->clearSupplementaryExceptionInfo();
}
ScriptExecutionContext* scriptExecutionContext = globalObject->scriptExecutionContext();
scriptExecutionContext->reportException(errorMessage, lineNumber, columnNumber, exceptionSourceURL, callStack->size() ? callStack : 0, cachedScript);
}
示例6: subtype
JSValue JSInjectedScriptHost::subtype(ExecState* exec)
{
if (exec->argumentCount() < 1)
return jsUndefined();
JSValue value = exec->uncheckedArgument(0);
if (value.isString())
return exec->vm().smallStrings.stringString();
if (value.isBoolean())
return exec->vm().smallStrings.booleanString();
if (value.isNumber())
return exec->vm().smallStrings.numberString();
if (value.isSymbol())
return exec->vm().smallStrings.symbolString();
JSObject* object = asObject(value);
if (object) {
if (object->isErrorInstance())
return jsNontrivialString(exec, ASCIILiteral("error"));
// Consider class constructor functions class objects.
JSFunction* function = jsDynamicCast<JSFunction*>(value);
if (function && function->isClassConstructorFunction())
return jsNontrivialString(exec, ASCIILiteral("class"));
}
if (value.inherits(JSArray::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
if (value.inherits(DirectArguments::info()) || value.inherits(ScopedArguments::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
if (value.inherits(DateInstance::info()))
return jsNontrivialString(exec, ASCIILiteral("date"));
if (value.inherits(RegExpObject::info()))
return jsNontrivialString(exec, ASCIILiteral("regexp"));
if (value.inherits(JSMap::info()))
return jsNontrivialString(exec, ASCIILiteral("map"));
if (value.inherits(JSSet::info()))
return jsNontrivialString(exec, ASCIILiteral("set"));
if (value.inherits(JSWeakMap::info()))
return jsNontrivialString(exec, ASCIILiteral("weakmap"));
if (value.inherits(JSWeakSet::info()))
return jsNontrivialString(exec, ASCIILiteral("weakset"));
if (value.inherits(JSArrayIterator::info())
|| value.inherits(JSMapIterator::info())
|| value.inherits(JSSetIterator::info())
|| value.inherits(JSStringIterator::info()))
return jsNontrivialString(exec, ASCIILiteral("iterator"));
if (value.inherits(JSInt8Array::info()) || value.inherits(JSInt16Array::info()) || value.inherits(JSInt32Array::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
if (value.inherits(JSUint8Array::info()) || value.inherits(JSUint16Array::info()) || value.inherits(JSUint32Array::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
if (value.inherits(JSFloat32Array::info()) || value.inherits(JSFloat64Array::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
return impl().subtype(exec, value);
}
示例7: runtimeTypeForValue
RuntimeType runtimeTypeForValue(JSValue value)
{
if (UNLIKELY(!value))
return TypeNothing;
if (value.isUndefined())
return TypeUndefined;
if (value.isNull())
return TypeNull;
if (value.isAnyInt())
return TypeAnyInt;
if (value.isNumber())
return TypeNumber;
if (value.isString())
return TypeString;
if (value.isBoolean())
return TypeBoolean;
if (value.isObject())
return TypeObject;
if (value.isFunction())
return TypeFunction;
if (value.isSymbol())
return TypeSymbol;
return TypeNothing;
}
示例8: dumpImmediate
void dumpImmediate(JSValue value)
{
if (value.isNull())
write(NullTag);
else if (value.isUndefined())
write(UndefinedTag);
else if (value.isNumber()) {
if (value.isInt32()) {
if (!value.asInt32())
write(ZeroTag);
else if (value.asInt32() == 1)
write(OneTag);
else {
write(IntTag);
write(static_cast<uint32_t>(value.asInt32()));
}
} else {
write(DoubleTag);
write(value.asDouble());
}
} else if (value.isBoolean()) {
if (value.isTrue())
write(TrueTag);
else
write(FalseTag);
}
}
示例9: updateResultProfileForBinaryArithOp
static void updateResultProfileForBinaryArithOp(ExecState* exec, Instruction* pc, JSValue result, JSValue left, JSValue right)
{
CodeBlock* codeBlock = exec->codeBlock();
unsigned bytecodeOffset = codeBlock->bytecodeOffset(pc);
ResultProfile* profile = codeBlock->ensureResultProfile(bytecodeOffset);
if (result.isNumber()) {
if (!result.isInt32()) {
if (left.isInt32() && right.isInt32())
profile->setObservedInt32Overflow();
double doubleVal = result.asNumber();
if (!doubleVal && std::signbit(doubleVal))
profile->setObservedNegZeroDouble();
else {
profile->setObservedNonNegZeroDouble();
// The Int52 overflow check here intentionally omits 1ll << 51 as a valid negative Int52 value.
// Therefore, we will get a false positive if the result is that value. This is intentionally
// done to simplify the checking algorithm.
static const int64_t int52OverflowPoint = (1ll << 51);
int64_t int64Val = static_cast<int64_t>(std::abs(doubleVal));
if (int64Val >= int52OverflowPoint)
profile->setObservedInt52Overflow();
}
}
} else
profile->setObservedNonNumber();
}
示例10: if
static inline UString gap(ExecState* exec, JSValue space)
{
const unsigned maxGapLength = 10;
space = unwrapBoxedPrimitive(exec, space);
// If the space value is a number, create a gap string with that number of spaces.
if (space.isNumber()) {
double spaceCount = space.asNumber();
int count;
if (spaceCount > maxGapLength)
count = maxGapLength;
else if (!(spaceCount > 0))
count = 0;
else
count = static_cast<int>(spaceCount);
UChar spaces[maxGapLength];
for (int i = 0; i < count; ++i)
spaces[i] = ' ';
return UString(spaces, count);
}
// If the space value is a string, use it as the gap string, otherwise use no gap string.
UString spaces = space.getString(exec);
if (spaces.length() > maxGapLength) {
spaces = spaces.substringSharingImpl(0, maxGapLength);
}
return spaces;
}
示例11: putByVal
static inline void putByVal(ExecState* exec, JSValue baseValue, uint32_t index, JSValue value)
{
JSGlobalData* globalData = &exec->globalData();
if (isJSArray(baseValue)) {
JSArray* array = asArray(baseValue);
if (array->canSetIndex(index)) {
array->setIndex(*globalData, index, value);
return;
}
JSArray::putByIndex(array, exec, index, value, strict);
return;
}
if (isJSByteArray(baseValue) && asByteArray(baseValue)->canAccessIndex(index)) {
JSByteArray* byteArray = asByteArray(baseValue);
// FIXME: the JITstub used to relink this to an optimized form!
if (value.isInt32()) {
byteArray->setIndex(index, value.asInt32());
return;
}
if (value.isNumber()) {
byteArray->setIndex(index, value.asNumber());
return;
}
}
baseValue.putByIndex(exec, index, value, strict);
}
示例12: updateArithProfileForUnaryArithOp
static void updateArithProfileForUnaryArithOp(Instruction* pc, JSValue result, JSValue operand)
{
ArithProfile& profile = *bitwise_cast<ArithProfile*>(&pc[3].u.operand);
profile.observeLHS(operand);
ASSERT(result.isNumber());
if (!result.isInt32()) {
if (operand.isInt32())
profile.setObservedInt32Overflow();
double doubleVal = result.asNumber();
if (!doubleVal && std::signbit(doubleVal))
profile.setObservedNegZeroDouble();
else {
profile.setObservedNonNegZeroDouble();
// The Int52 overflow check here intentionally omits 1ll << 51 as a valid negative Int52 value.
// Therefore, we will get a false positive if the result is that value. This is intentionally
// done to simplify the checking algorithm.
static const int64_t int52OverflowPoint = (1ll << 51);
int64_t int64Val = static_cast<int64_t>(std::abs(doubleVal));
if (int64Val >= int52OverflowPoint)
profile.setObservedInt52Overflow();
}
}
}
示例13: type
JSValue JSInjectedScriptHost::type(ExecState* exec)
{
if (exec->argumentCount() < 1)
return jsUndefined();
JSValue value = exec->argument(0);
if (value.isString())
return jsString(exec, String("string"));
if (value.inherits(&JSArray::s_info))
return jsString(exec, String("array"));
if (value.isBoolean())
return jsString(exec, String("boolean"));
if (value.isNumber())
return jsString(exec, String("number"));
if (value.inherits(&DateInstance::s_info))
return jsString(exec, String("date"));
if (value.inherits(&RegExpObject::s_info))
return jsString(exec, String("regexp"));
if (value.inherits(&JSNode::s_info))
return jsString(exec, String("node"));
if (value.inherits(&JSNodeList::s_info))
return jsString(exec, String("array"));
if (value.inherits(&JSHTMLCollection::s_info))
return jsString(exec, String("array"));
if (value.inherits(&JSInt8Array::s_info) || value.inherits(&JSInt16Array::s_info) || value.inherits(&JSInt32Array::s_info))
return jsString(exec, String("array"));
if (value.inherits(&JSUint8Array::s_info) || value.inherits(&JSUint16Array::s_info) || value.inherits(&JSUint32Array::s_info))
return jsString(exec, String("array"));
if (value.inherits(&JSFloat32Array::s_info) || value.inherits(&JSFloat64Array::s_info))
return jsString(exec, String("array"));
return jsUndefined();
}
示例14: jsTypeStringForValue
JSValue jsTypeStringForValue(VM& vm, JSGlobalObject* globalObject, JSValue v)
{
if (v.isUndefined())
return vm.smallStrings.undefinedString();
if (v.isBoolean())
return vm.smallStrings.booleanString();
if (v.isNumber())
return vm.smallStrings.numberString();
if (v.isString())
return vm.smallStrings.stringString();
if (v.isSymbol())
return vm.smallStrings.symbolString();
if (v.isObject()) {
JSObject* object = asObject(v);
// Return "undefined" for objects that should be treated
// as null when doing comparisons.
if (object->structure(vm)->masqueradesAsUndefined(globalObject))
return vm.smallStrings.undefinedString();
if (object->type() == JSFunctionType)
return vm.smallStrings.functionString();
if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
CallData callData;
JSObject* object = asObject(v);
if (object->methodTable(vm)->getCallData(object, callData) != CallTypeNone)
return vm.smallStrings.functionString();
}
}
return vm.smallStrings.objectString();
}
示例15: getRuntimeTypeForValue
RuntimeType TypeSet::getRuntimeTypeForValue(JSValue v)
{
RuntimeType ret;
if (v.isFunction())
ret = TypeFunction;
else if (v.isUndefined())
ret = TypeUndefined;
else if (v.isNull())
ret = TypeNull;
else if (v.isBoolean())
ret = TypeBoolean;
else if (v.isMachineInt())
ret = TypeMachineInt;
else if (v.isNumber())
ret = TypeNumber;
else if (v.isString())
ret = TypeString;
else if (v.isPrimitive())
ret = TypePrimitive;
else if (v.isObject())
ret = TypeObject;
else
CRASH();
return ret;
}