本文整理汇总了C++中JSValue::toWTFString方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::toWTFString方法的具体用法?C++ JSValue::toWTFString怎么用?C++ JSValue::toWTFString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::toWTFString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
}
示例2: sanitizedToString
// Based on ErrorPrototype's errorProtoFuncToString(), but is modified to
// have no observable side effects to the user (i.e. does not call proxies,
// and getters).
String ErrorInstance::sanitizedToString(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue nameValue;
auto namePropertName = vm.propertyNames->name;
PropertySlot nameSlot(this, PropertySlot::InternalMethodType::VMInquiry);
JSValue currentObj = this;
unsigned prototypeDepth = 0;
// We only check the current object and its prototype (2 levels) because normal
// Error objects may have a name property, and if not, its prototype should have
// a name property for the type of error e.g. "SyntaxError".
while (currentObj.isCell() && prototypeDepth++ < 2) {
JSObject* obj = jsCast<JSObject*>(currentObj);
if (JSObject::getOwnPropertySlot(obj, exec, namePropertName, nameSlot) && nameSlot.isValue()) {
nameValue = nameSlot.getValue(exec, namePropertName);
break;
}
currentObj = obj->getPrototypeDirect();
}
ASSERT(!scope.exception());
String nameString;
if (!nameValue)
nameString = ASCIILiteral("Error");
else {
nameString = nameValue.toWTFString(exec);
RETURN_IF_EXCEPTION(scope, String());
}
JSValue messageValue;
auto messagePropertName = vm.propertyNames->message;
PropertySlot messageSlot(this, PropertySlot::InternalMethodType::VMInquiry);
if (JSObject::getOwnPropertySlot(this, exec, messagePropertName, messageSlot) && messageSlot.isValue())
messageValue = messageSlot.getValue(exec, messagePropertName);
ASSERT(!scope.exception());
String messageString;
if (!messageValue)
messageString = String();
else {
messageString = messageValue.toWTFString(exec);
RETURN_IF_EXCEPTION(scope, String());
}
if (!nameString.length())
return messageString;
if (!messageString.length())
return nameString;
StringBuilder builder;
builder.append(nameString);
builder.appendLiteral(": ");
builder.append(messageString);
return builder.toString();
}
示例3: 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));
}
示例4: setPort
void JSLocation::setPort(ExecState* exec, JSValue value)
{
String port = value.toWTFString(exec);
if (exec->hadException())
return;
impl()->setPort(port, activeDOMWindow(exec), firstDOMWindow(exec));
}
示例5: putDelegate
bool JSStorage::putDelegate(ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot&, bool& putResult)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// Only perform the custom put if the object doesn't have a native property by this name.
// Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
// the native property slots manually.
PropertySlot slot { this, PropertySlot::InternalMethodType::GetOwnProperty };
JSValue prototype = this->getPrototypeDirect();
if (prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))
return false;
if (propertyName.isSymbol())
return false;
String stringValue = value.toWTFString(state);
RETURN_IF_EXCEPTION(scope, true);
auto setItemResult = wrapped().setItem(propertyNameToString(propertyName), stringValue);
if (setItemResult.hasException()) {
propagateException(*state, scope, setItemResult.releaseException());
return true;
}
putResult = true;
return true;
}
示例6: getTypeFlags
static std::error_code getTypeFlags(ExecState& exec, const JSValue& typeValue, ResourceFlags& flags, uint16_t (*stringToType)(const String&))
{
VM& vm = exec.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (!typeValue.isObject())
return { };
const JSObject* object = typeValue.toObject(&exec);
ASSERT(!scope.exception());
if (!isJSArray(object))
return ContentExtensionError::JSONInvalidTriggerFlagsArray;
const JSArray* array = jsCast<const JSArray*>(object);
unsigned length = array->length();
for (unsigned i = 0; i < length; ++i) {
const JSValue value = array->getIndex(&exec, i);
if (scope.exception() || !value)
return ContentExtensionError::JSONInvalidObjectInTriggerFlagsArray;
String name = value.toWTFString(&exec);
uint16_t type = stringToType(name);
if (!type)
return ContentExtensionError::JSONInvalidStringInTriggerFlagsArray;
flags |= type;
}
return { };
}
示例7: 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;
}
示例8:
template<> Optional<TestStandaloneDictionary::EnumInStandaloneDictionaryFile> parseEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>(ExecState& state, JSValue value)
{
auto stringValue = value.toWTFString(&state);
if (stringValue == "enumValue1")
return TestStandaloneDictionary::EnumInStandaloneDictionaryFile::EnumValue1;
if (stringValue == "enumValue2")
return TestStandaloneDictionary::EnumInStandaloneDictionaryFile::EnumValue2;
return WTF::nullopt;
}
示例9: setJSTestInterfaceConstructorSupplementalStaticAttr
bool setJSTestInterfaceConstructorSupplementalStaticAttr(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
JSValue value = JSValue::decode(encodedValue);
auto nativeValue = value.toWTFString(state);
if (UNLIKELY(state->hadException()))
return false;
WebCore::TestSupplemental::setSupplementalStaticAttr(WTFMove(nativeValue));
return true;
}
示例10: getWithUndefinedOrNullCheck
bool JSDictionary::getWithUndefinedOrNullCheck(const String& propertyName, String& result) const
{
ASSERT(isValid());
JSValue value;
if (tryGetProperty(propertyName.utf8().data(), value) != PropertyFound || value.isUndefinedOrNull())
return false;
result = value.toWTFString(m_exec);
return true;
}
示例11: if
static std::error_code loadAction(ExecState& exec, const JSObject& ruleObject, Action& action, bool& validSelector)
{
VM& vm = exec.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
validSelector = true;
const JSValue actionObject = ruleObject.get(&exec, Identifier::fromString(&exec, "action"));
if (!actionObject || scope.exception() || !actionObject.isObject())
return ContentExtensionError::JSONInvalidAction;
const JSValue typeObject = actionObject.get(&exec, Identifier::fromString(&exec, "type"));
if (!typeObject || scope.exception() || !typeObject.isString())
return ContentExtensionError::JSONInvalidActionType;
String actionType = typeObject.toWTFString(&exec);
if (actionType == "block")
action = ActionType::BlockLoad;
else if (actionType == "ignore-previous-rules")
action = ActionType::IgnorePreviousRules;
else if (actionType == "block-cookies")
action = ActionType::BlockCookies;
else if (actionType == "css-display-none") {
JSValue selector = actionObject.get(&exec, Identifier::fromString(&exec, "selector"));
if (!selector || scope.exception() || !selector.isString())
return ContentExtensionError::JSONInvalidCSSDisplayNoneActionType;
String s = selector.toWTFString(&exec);
if (!isValidSelector(s)) {
// Skip rules with invalid selectors to be backwards-compatible.
validSelector = false;
return { };
}
action = Action(ActionType::CSSDisplayNoneSelector, s);
} else if (actionType == "make-https") {
action = ActionType::MakeHTTPS;
} else
return ContentExtensionError::JSONInvalidActionType;
return { };
}
示例12: setJSTestInterfaceSupplementalStr2
bool setJSTestInterfaceSupplementalStr2(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
JSValue value = JSValue::decode(encodedValue);
UNUSED_PARAM(thisValue);
JSTestInterface* castedThis = jsDynamicCast<JSTestInterface*>(JSValue::decode(thisValue));
if (UNLIKELY(!castedThis)) {
return throwSetterTypeError(*state, "TestInterface", "supplementalStr2");
}
auto& impl = castedThis->wrapped();
auto nativeValue = value.toWTFString(state);
if (UNLIKELY(state->hadException()))
return false;
WebCore::TestSupplemental::setSupplementalStr2(impl, WTFMove(nativeValue));
return true;
}
示例13: setJSTestNodeName
bool setJSTestNodeName(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
JSValue value = JSValue::decode(encodedValue);
UNUSED_PARAM(thisValue);
JSTestNode* castedThis = jsDynamicCast<JSTestNode*>(JSValue::decode(thisValue));
if (UNLIKELY(!castedThis)) {
return throwSetterTypeError(*state, "TestNode", "name");
}
auto& impl = castedThis->wrapped();
auto nativeValue = value.toWTFString(state);
if (UNLIKELY(state->hadException()))
return false;
impl.setName(WTFMove(nativeValue));
return true;
}
示例14: setJSTestGlobalObjectPublicAndPrivateConditionalAttribute
bool setJSTestGlobalObjectPublicAndPrivateConditionalAttribute(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
JSValue value = JSValue::decode(encodedValue);
UNUSED_PARAM(thisValue);
JSTestGlobalObject* castedThis = jsDynamicCast<JSTestGlobalObject*>(JSValue::decode(thisValue));
if (UNLIKELY(!castedThis)) {
return throwSetterTypeError(*state, "TestGlobalObject", "publicAndPrivateConditionalAttribute");
}
auto& impl = castedThis->wrapped();
auto nativeValue = value.toWTFString(state);
if (UNLIKELY(state->hadException()))
return false;
impl.setPublicAndPrivateConditionalAttribute(WTFMove(nativeValue));
return true;
}
示例15: encode
static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyTable(ExecState* exec)
{
VM& vm = exec->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSObject* memoryDescriptor;
{
JSValue argument = exec->argument(0);
if (!argument.isObject())
return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Table expects its first argument to be an object"))));
memoryDescriptor = jsCast<JSObject*>(argument);
}
{
Identifier elementIdent = Identifier::fromString(&vm, "element");
JSValue elementValue = memoryDescriptor->get(exec, elementIdent);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
String elementString = elementValue.toWTFString(exec);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
if (elementString != "anyfunc")
return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Table expects its 'element' field to be the string 'anyfunc'"))));
}
Identifier initialIdent = Identifier::fromString(&vm, "initial");
JSValue initialSizeValue = memoryDescriptor->get(exec, initialIdent);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
uint32_t initial = toNonWrappingUint32(exec, initialSizeValue);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
std::optional<uint32_t> maximum;
Identifier maximumIdent = Identifier::fromString(&vm, "maximum");
bool hasProperty = memoryDescriptor->hasProperty(exec, maximumIdent);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
if (hasProperty) {
JSValue maxSizeValue = memoryDescriptor->get(exec, maximumIdent);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
maximum = toNonWrappingUint32(exec, maxSizeValue);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
if (initial > *maximum) {
return JSValue::encode(throwException(exec, throwScope,
createRangeError(exec, ASCIILiteral("'maximum' property must be greater than or equal to the 'initial' property"))));
}
}
throwScope.release();
return JSValue::encode(JSWebAssemblyTable::create(exec, vm, exec->lexicalGlobalObject()->WebAssemblyTableStructure(), initial, maximum));
}