本文整理汇总了C++中JSValue::isString方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::isString方法的具体用法?C++ JSValue::isString怎么用?C++ JSValue::isString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::isString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: errorProtoFuncToString
// ECMA-262 5.1, 15.11.4.4
EncodedJSValue JSC_HOST_CALL errorProtoFuncToString(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Let O be the this value.
JSValue thisValue = exec->thisValue();
// 2. If Type(O) is not Object, throw a TypeError exception.
if (!thisValue.isObject())
return throwVMTypeError(exec, scope);
JSObject* thisObj = asObject(thisValue);
// Guard against recursion!
StringRecursionChecker checker(exec, thisObj);
ASSERT(!scope.exception() || checker.earlyReturnValue());
if (JSValue earlyReturnValue = checker.earlyReturnValue())
return JSValue::encode(earlyReturnValue);
// 3. Let name be the result of calling the [[Get]] internal method of O with argument "name".
JSValue name = thisObj->get(exec, exec->propertyNames().name);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
// 4. If name is undefined, then let name be "Error"; else let name be ToString(name).
String nameString;
if (name.isUndefined())
nameString = ASCIILiteral("Error");
else {
nameString = name.toWTFString(exec);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
}
// 5. Let msg be the result of calling the [[Get]] internal method of O with argument "message".
JSValue message = thisObj->get(exec, exec->propertyNames().message);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
// (sic)
// 6. If msg is undefined, then let msg be the empty String; else let msg be ToString(msg).
// 7. If msg is undefined, then let msg be the empty String; else let msg be ToString(msg).
String messageString;
if (message.isUndefined())
messageString = String();
else {
messageString = message.toWTFString(exec);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
}
// 8. If name is the empty String, return msg.
if (!nameString.length())
return JSValue::encode(message.isString() ? message : jsString(exec, messageString));
// 9. If msg is the empty String, return name.
if (!messageString.length())
return JSValue::encode(name.isString() ? name : jsString(exec, nameString));
// 10. Return the result of concatenating name, ":", a single space character, and msg.
scope.release();
return JSValue::encode(jsMakeNontrivialString(exec, nameString, ": ", messageString));
}
示例2: getDomainList
static std::error_code getDomainList(ExecState& exec, const JSObject* arrayObject, Vector<String>& vector)
{
VM& vm = exec.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
ASSERT(vector.isEmpty());
if (!arrayObject || !isJSArray(arrayObject))
return ContentExtensionError::JSONInvalidDomainList;
const JSArray* array = jsCast<const JSArray*>(arrayObject);
unsigned length = array->length();
for (unsigned i = 0; i < length; ++i) {
const JSValue value = array->getIndex(&exec, i);
if (scope.exception() || !value.isString())
return ContentExtensionError::JSONInvalidDomainList;
// Domains should be punycode encoded lower case.
const String& domain = jsCast<JSString*>(value)->value(&exec);
if (domain.isEmpty())
return ContentExtensionError::JSONInvalidDomainList;
if (!containsOnlyASCIIWithNoUppercase(domain))
return ContentExtensionError::JSONDomainNotLowerCaseASCII;
vector.append(domain);
}
return { };
}
示例3: 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;
}
示例4: 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;
}
示例5: operationGetByValCell
EncodedJSValue JIT_OPERATION operationGetByValCell(ExecState* exec, JSCell* base, EncodedJSValue encodedProperty)
{
VM& vm = exec->vm();
NativeCallFrameTracer tracer(&vm, exec);
JSValue property = JSValue::decode(encodedProperty);
if (property.isUInt32())
return getByVal(exec, base, property.asUInt32());
if (property.isDouble()) {
double propertyAsDouble = property.asDouble();
uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
if (propertyAsUInt32 == propertyAsDouble)
return getByVal(exec, base, propertyAsUInt32);
} else if (property.isString()) {
Structure& structure = *base->structure(vm);
if (JSCell::canUseFastGetOwnProperty(structure)) {
if (AtomicStringImpl* existingAtomicString = asString(property)->toExistingAtomicString(exec)) {
if (JSValue result = base->fastGetOwnProperty(vm, structure, existingAtomicString))
return JSValue::encode(result);
}
}
}
PropertyName propertyName = property.toPropertyKey(exec);
return JSValue::encode(JSValue(base).get(exec, propertyName));
}
示例6: operationGetByVal
EncodedJSValue DFG_OPERATION operationGetByVal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty)
{
JSGlobalData* globalData = &exec->globalData();
NativeCallFrameTracer tracer(globalData, exec);
JSValue baseValue = JSValue::decode(encodedBase);
JSValue property = JSValue::decode(encodedProperty);
if (LIKELY(baseValue.isCell())) {
JSCell* base = baseValue.asCell();
if (property.isUInt32()) {
return getByVal(exec, base, property.asUInt32());
} else if (property.isDouble()) {
double propertyAsDouble = property.asDouble();
uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
if (propertyAsUInt32 == propertyAsDouble)
return getByVal(exec, base, propertyAsUInt32);
} else if (property.isString()) {
if (JSValue result = base->fastGetOwnProperty(exec, asString(property)->value(exec)))
return JSValue::encode(result);
}
}
Identifier ident(exec, property.toString(exec)->value(exec));
return JSValue::encode(baseValue.get(exec, ident));
}
示例7: objectProtoFuncToString
EncodedJSValue JSC_HOST_CALL objectProtoFuncToString(ExecState* exec)
{
VM& vm = exec->vm();
JSValue thisValue = exec->thisValue().toThis(exec, StrictMode);
if (thisValue.isUndefinedOrNull())
return JSValue::encode(thisValue.isUndefined() ? vm.smallStrings.undefinedObjectString() : vm.smallStrings.nullObjectString());
JSObject* thisObject = thisValue.toObject(exec);
JSValue stringTag = thisObject->get(exec, exec->propertyNames().toStringTagSymbol);
if (stringTag.isString()) {
JSRopeString::RopeBuilder<RecordOverflow> ropeBuilder(vm);
ropeBuilder.append(vm.smallStrings.objectStringStart());
ropeBuilder.append(jsCast<JSString*>(stringTag));
ropeBuilder.append(vm.smallStrings.singleCharacterString(']'));
if(ropeBuilder.hasOverflowed())
return JSValue::encode(throwOutOfMemoryError(exec));
return JSValue::encode(ropeBuilder.release());
}
JSString* result = thisObject->structure(vm)->objectToStringValue();
if (!result) {
RefPtr<StringImpl> newString = WTF::tryMakeString("[object ", thisObject->methodTable(exec->vm())->className(thisObject), "]");
if (!newString)
return JSValue::encode(throwOutOfMemoryError(exec));
result = jsNontrivialString(&vm, newString.release());
thisObject->structure(vm)->setObjectToStringValue(vm, result);
}
return JSValue::encode(result);
}
示例8: constructDate
// ECMA 15.9.3
JSObject* constructDate(ExecState* exec, JSGlobalObject* globalObject, JSValue newTarget, const ArgList& args)
{
VM& vm = exec->vm();
int numArgs = args.size();
double value;
if (numArgs == 0) // new Date() ECMA 15.9.3.3
value = NORMAL_OR_DETERMINISTIC_FUNCTION(jsCurrentTime(), deterministicCurrentTime(globalObject));
else if (numArgs == 1) {
if (args.at(0).inherits(DateInstance::info()))
value = asDateInstance(args.at(0))->internalNumber();
else {
JSValue primitive = args.at(0).toPrimitive(exec);
if (primitive.isString())
value = parseDate(vm, primitive.getString(exec));
else
value = primitive.toNumber(exec);
}
} else
value = millisecondsFromComponents(exec, args, WTF::LocalTime);
Structure* dateStructure = InternalFunction::createSubclassStructure(exec, newTarget, globalObject->dateStructure());
return DateInstance::create(vm, dateStructure, value);
}
示例9: 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;
}
示例10: 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();
}
示例11: 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();
}
示例12: populateContextMenuItems
static void populateContextMenuItems(ExecState* exec, JSArray* array, ContextMenu& menu)
{
for (size_t i = 0; i < array->length(); ++i) {
JSObject* item = asObject(array->getIndex(exec, i));
JSValue label = item->get(exec, Identifier::fromString(exec, "label"));
JSValue type = item->get(exec, Identifier::fromString(exec, "type"));
JSValue id = item->get(exec, Identifier::fromString(exec, "id"));
JSValue enabled = item->get(exec, Identifier::fromString(exec, "enabled"));
JSValue checked = item->get(exec, Identifier::fromString(exec, "checked"));
JSValue subItems = item->get(exec, Identifier::fromString(exec, "subItems"));
if (!type.isString())
continue;
String typeString = type.toWTFString(exec);
if (typeString == "separator") {
ContextMenuItem item(SeparatorType, ContextMenuItemTagNoAction, String());
menu.appendItem(item);
} else if (typeString == "subMenu" && subItems.inherits(JSArray::info())) {
ContextMenu subMenu;
JSArray* subItemsArray = asArray(subItems);
populateContextMenuItems(exec, subItemsArray, subMenu);
ContextMenuItem item(SubmenuType, ContextMenuItemTagNoAction, label.toWTFString(exec), &subMenu);
menu.appendItem(item);
} else {
ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec));
ContextMenuItem menuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, label.toWTFString(exec));
if (!enabled.isUndefined())
menuItem.setEnabled(enabled.toBoolean(exec));
if (!checked.isUndefined())
menuItem.setChecked(checked.toBoolean(exec));
menu.appendItem(menuItem);
}
}
}
示例13: 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);
}
示例14: jsHTMLDocumentPrototypeFunctionWrite
EncodedJSValue JSC_HOST_CALL jsHTMLDocumentPrototypeFunctionWrite(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(&JSHTMLDocument::s_info))
return throwVMTypeError(exec);
JSHTMLDocument* castedThis = static_cast<JSHTMLDocument*>(asObject(thisValue));
#ifdef JSC_TAINTED
/*
if we comment out the following code segement and move the detection to bindings/js/JSHTMLDocumentCustom.cpp
one of the test case like below cannot be detected anymore. need to investigate the reason behind.
document.write("hello"+document.location.href.substring(document.location.href.indexOf("default=")+8));\
the guess is the following code does not cover the primitive string.
*/
JSValue s = exec->argument(0);
if (s.isString() && s.isTainted()) {
HTMLDocument* d1 = static_cast<HTMLDocument*>(castedThis->impl());
d1->setTainted(s.isTainted());
TaintedStructure trace_struct;
trace_struct.taintedno = s.isTainted();
trace_struct.internalfunc = "jsHTMLDocumentPrototypeFunctionWrite";
trace_struct.jsfunc = "document.write";
trace_struct.action = "sink";
char msg[20];
stringstream msgss;
snprintf(msg, 20, "%s", s.toString(exec).utf8(true).data());
msgss << msg;
msgss >> trace_struct.value;
TaintedTrace* trace = TaintedTrace::getInstance();
trace->addTaintedTrace(trace_struct);
}
示例15: 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;
String functionName = stackTrace[i].friendlyFunctionName(exec);
unsigned line;
unsigned column;
stackTrace[i].computeLineAndColumn(line, column);
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 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, 0);
}
}
return ScriptCallStack::create(frames);
}