本文整理汇总了C++中JSArray::getIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ JSArray::getIndex方法的具体用法?C++ JSArray::getIndex怎么用?C++ JSArray::getIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSArray
的用法示例。
在下文中一共展示了JSArray::getIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showContextMenu
JSValue JSInspectorFrontendHost::showContextMenu(ExecState* execState, const ArgList& args)
{
if (args.size() < 2)
return jsUndefined();
Event* event = toEvent(args.at(0));
JSArray* array = asArray(args.at(1));
Vector<ContextMenuItem*> items;
for (size_t i = 0; i < array->length(); ++i) {
JSObject* item = asObject(array->getIndex(i));
JSValue label = item->get(execState, Identifier(execState, "label"));
JSValue id = item->get(execState, Identifier(execState, "id"));
if (label.isUndefined() || id.isUndefined())
items.append(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
else {
ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(execState));
items.append(new ContextMenuItem(ActionType, typedId, label.toString(execState)));
}
}
impl()->showContextMenu(event, items);
return jsUndefined();
}
示例2: cryptoKeyUsagesFromJSValue
static CryptoKeyUsageBitmap cryptoKeyUsagesFromJSValue(ExecState& state, ThrowScope& scope, JSValue value)
{
if (!isJSArray(value)) {
throwTypeError(&state, scope);
return { };
}
CryptoKeyUsageBitmap result = 0;
JSArray* array = asArray(value);
for (unsigned i = 0; i < array->length(); ++i) {
auto usageString = array->getIndex(&state, i).toWTFString(&state);
RETURN_IF_EXCEPTION(scope, { });
if (usageString == "encrypt")
result |= CryptoKeyUsageEncrypt;
else if (usageString == "decrypt")
result |= CryptoKeyUsageDecrypt;
else if (usageString == "sign")
result |= CryptoKeyUsageSign;
else if (usageString == "verify")
result |= CryptoKeyUsageVerify;
else if (usageString == "deriveKey")
result |= CryptoKeyUsageDeriveKey;
else if (usageString == "deriveBits")
result |= CryptoKeyUsageDeriveBits;
else if (usageString == "wrapKey")
result |= CryptoKeyUsageWrapKey;
else if (usageString == "unwrapKey")
result |= CryptoKeyUsageUnwrapKey;
}
return result;
}
示例3: cryptoKeyUsagesFromJSValue
static bool cryptoKeyUsagesFromJSValue(ExecState* exec, JSValue value, CryptoKeyUsage& result)
{
if (!isJSArray(value)) {
throwTypeError(exec);
return false;
}
result = 0;
JSArray* array = asArray(value);
for (size_t i = 0; i < array->length(); ++i) {
JSValue element = array->getIndex(exec, i);
String usageString = element.toString(exec)->value(exec);
if (exec->hadException())
return false;
if (usageString == "encrypt")
result |= CryptoKeyUsageEncrypt;
else if (usageString == "decrypt")
result |= CryptoKeyUsageDecrypt;
else if (usageString == "sign")
result |= CryptoKeyUsageSign;
else if (usageString == "verify")
result |= CryptoKeyUsageVerify;
else if (usageString == "deriveKey")
result |= CryptoKeyUsageDeriveKey;
else if (usageString == "deriveBits")
result |= CryptoKeyUsageDeriveBits;
else if (usageString == "wrapKey")
result |= CryptoKeyUsageWrapKey;
else if (usageString == "unwrapKey")
result |= CryptoKeyUsageUnwrapKey;
}
return true;
}
示例4: 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;
}
示例5: reconcileUsages
void JSCryptoKeySerializationJWK::reconcileUsages(CryptoKeyUsage& suggestedUsages) const
{
CryptoKeyUsage jwkUsages = 0;
JSArray* keyOps;
if (getJSArrayFromJSON(m_exec, m_json.get(), "key_ops", keyOps)) {
for (size_t i = 0; i < keyOps->length(); ++i) {
JSValue jsValue = keyOps->getIndex(m_exec, i);
String operation;
if (!jsValue.getString(m_exec, operation)) {
if (!m_exec->hadException())
throwTypeError(m_exec, "JWK key_ops attribute could not be processed");
return;
}
if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral("sign"), CryptoKeyUsageSign))
return;
if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral("verify"), CryptoKeyUsageVerify))
return;
if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral("encrypt"), CryptoKeyUsageEncrypt))
return;
if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral("decrypt"), CryptoKeyUsageDecrypt))
return;
if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral("wrapKey"), CryptoKeyUsageWrapKey))
return;
if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral("unwrapKey"), CryptoKeyUsageUnwrapKey))
return;
if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral("deriveKey"), CryptoKeyUsageDeriveKey))
return;
if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral("deriveBits"), CryptoKeyUsageDeriveBits))
return;
}
} else {
if (m_exec->hadException())
return;
String jwkUseString;
if (!getStringFromJSON(m_exec, m_json.get(), "use", jwkUseString)) {
// We have neither key_ops nor use.
return;
}
if (jwkUseString == "enc")
jwkUsages |= (CryptoKeyUsageEncrypt | CryptoKeyUsageDecrypt | CryptoKeyUsageWrapKey | CryptoKeyUsageUnwrapKey);
else if (jwkUseString == "sig")
jwkUsages |= (CryptoKeyUsageSign | CryptoKeyUsageVerify);
else {
throwTypeError(m_exec, "Unsupported JWK key use value \"" + jwkUseString + "\"");
return;
}
}
suggestedUsages = suggestedUsages & jwkUsages;
}
示例6: 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;
}
示例7: 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;
}
示例8: toDOMStringList
PassRefPtr<DOMStringList> toDOMStringList(ExecState* exec, JSValue value)
{
if (value.inherits(&JSDOMStringList::s_info))
return jsCast<JSDOMStringList*>(asObject(value))->impl();
if (!isJSArray(value))
return 0;
JSArray* array = asArray(value);
RefPtr<DOMStringList> stringList = DOMStringList::create();
for (unsigned i = 0; i < array->length(); ++i)
stringList->append(array->getIndex(exec, i).toString(exec)->value(exec));
return stringList.release();
}
示例9: setUserPreferredLanguages
void JSInternals::setUserPreferredLanguages(ExecState* exec, JSValue value)
{
if (!isJSArray(value)) {
throwError(exec, createSyntaxError(exec, "setUserPreferredLanguages: Expected Array"));
return;
}
Vector<String> languages;
JSArray* array = asArray(value);
for (unsigned i = 0; i < array->length(); ++i) {
String language = ustringToString(array->getIndex(i).toString(exec)->value(exec));
languages.append(language);
}
Internals* imp = static_cast<Internals*>(impl());
imp->setUserPreferredLanguages(languages);
}
示例10: asArray
void JSCanvasRenderingContext2D::setWebkitLineDash(ExecState* exec, JSValue value)
{
if (!isJSArray(value))
return;
Vector<float> dash;
JSArray* valueArray = asArray(value);
for (unsigned i = 0; i < valueArray->length(); ++i) {
float elem = valueArray->getIndex(exec, i).toFloat(exec);
if (elem <= 0 || !std::isfinite(elem))
return;
dash.append(elem);
}
CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());
context->setWebkitLineDash(dash);
}
示例11: boundFunctionConstruct
EncodedJSValue JSC_HOST_CALL boundFunctionConstruct(ExecState* exec)
{
JSBoundFunction* boundFunction = jsCast<JSBoundFunction*>(exec->callee());
ASSERT(isJSArray(boundFunction->boundArgs())); // Currently this is true!
JSArray* boundArgs = asArray(boundFunction->boundArgs());
MarkedArgumentBuffer args;
for (unsigned i = 0; i < boundArgs->length(); ++i)
args.append(boundArgs->getIndex(i));
for (unsigned i = 0; i < exec->argumentCount(); ++i)
args.append(exec->argument(i));
JSObject* targetFunction = boundFunction->targetFunction();
ConstructData constructData;
ConstructType constructType = getConstructData(targetFunction, constructData);
ASSERT(constructType != ConstructTypeNone);
return JSValue::encode(construct(exec, targetFunction, constructType, constructData, args));
}
示例12: showContextMenu
JSValue JSInspectorFrontendHost::showContextMenu(ExecState* exec)
{
if (exec->argumentCount() < 2)
return jsUndefined();
#if ENABLE(CONTEXT_MENUS)
Event* event = toEvent(exec->argument(0));
JSArray* array = asArray(exec->argument(1));
Vector<ContextMenuItem*> items;
for (size_t i = 0; i < array->length(); ++i) {
JSObject* item = asObject(array->getIndex(i));
JSValue label = item->get(exec, Identifier(exec, "label"));
JSValue type = item->get(exec, Identifier(exec, "type"));
JSValue id = item->get(exec, Identifier(exec, "id"));
JSValue enabled = item->get(exec, Identifier(exec, "enabled"));
JSValue checked = item->get(exec, Identifier(exec, "checked"));
if (!type.isString())
continue;
String typeString = ustringToString(type.toString(exec)->value(exec));
if (typeString == "separator") {
items.append(new ContextMenuItem(SeparatorType,
ContextMenuItemCustomTagNoAction,
String()));
} else {
ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec));
ContextMenuItem* menuItem = new ContextMenuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, ustringToString(label.toString(exec)->value(exec)));
if (!enabled.isUndefined())
menuItem->setEnabled(enabled.toBoolean(exec));
if (!checked.isUndefined())
menuItem->setChecked(checked.toBoolean(exec));
items.append(menuItem);
}
}
impl()->showContextMenu(event, items);
#endif
return jsUndefined();
}
示例13: constructJSWebSocket
EncodedJSValue JSC_HOST_CALL JSWebSocketConstructor::constructJSWebSocket(ExecState* exec)
{
JSWebSocketConstructor* jsConstructor = static_cast<JSWebSocketConstructor*>(exec->callee());
ScriptExecutionContext* context = jsConstructor->scriptExecutionContext();
if (!context)
return throwVMError(exec, createReferenceError(exec, "WebSocket constructor associated document is unavailable"));
if (!exec->argumentCount())
return throwVMError(exec, createSyntaxError(exec, "Not enough arguments"));
String urlString = ustringToString(exec->argument(0).toString(exec)->value(exec));
if (exec->hadException())
return throwVMError(exec, createSyntaxError(exec, "wrong URL"));
RefPtr<WebSocket> webSocket = WebSocket::create(context);
ExceptionCode ec = 0;
if (exec->argumentCount() < 2)
webSocket->connect(urlString, ec);
else {
JSValue protocolsValue = exec->argument(1);
if (isJSArray(protocolsValue)) {
Vector<String> protocols;
JSArray* protocolsArray = asArray(protocolsValue);
for (unsigned i = 0; i < protocolsArray->length(); ++i) {
String protocol = ustringToString(protocolsArray->getIndex(i).toString(exec)->value(exec));
if (exec->hadException())
return JSValue::encode(JSValue());
protocols.append(protocol);
}
webSocket->connect(urlString, protocols, ec);
} else {
String protocol = ustringToString(protocolsValue.toString(exec)->value(exec));
if (exec->hadException())
return JSValue::encode(JSValue());
webSocket->connect(urlString, protocol, ec);
}
}
setDOMException(exec, ec);
return JSValue::encode(CREATE_DOM_WRAPPER(exec, jsConstructor->globalObject(), WebSocket, webSocket.get()));
}
示例14: createNumber
static RefPtr<IDBKey> createIDBKeyFromValue(ExecState* exec, JSValue value, Vector<JSArray*>& stack)
{
if (value.isNumber() && !std::isnan(value.toNumber(exec)))
return IDBKey::createNumber(value.toNumber(exec));
if (value.isString())
return IDBKey::createString(value.toString(exec)->value(exec));
if (value.inherits(DateInstance::info()) && !std::isnan(valueToDate(exec, value)))
return IDBKey::createDate(valueToDate(exec, value));
if (value.isObject()) {
JSObject* object = asObject(value);
if (isJSArray(object) || object->inherits(JSArray::info())) {
JSArray* array = asArray(object);
size_t length = array->length();
if (stack.contains(array))
return nullptr;
if (stack.size() >= maximumDepth)
return nullptr;
stack.append(array);
Vector<RefPtr<IDBKey>> subkeys;
for (size_t i = 0; i < length; i++) {
JSValue item = array->getIndex(exec, i);
RefPtr<IDBKey> subkey = createIDBKeyFromValue(exec, item, stack);
if (!subkey)
subkeys.append(IDBKey::createInvalid());
else
subkeys.append(subkey);
}
stack.removeLast();
return IDBKey::createArray(subkeys);
}
}
return nullptr;
}
示例15: cryptoKeyUsagesFromJSValue
static bool cryptoKeyUsagesFromJSValue(ExecState& state, JSValue value, CryptoKeyUsageBitmap& result)
{
VM& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (!isJSArray(value)) {
throwTypeError(&state, scope);
return false;
}
result = 0;
JSArray* array = asArray(value);
for (size_t i = 0; i < array->length(); ++i) {
JSValue element = array->getIndex(&state, i);
String usageString = element.toString(&state)->value(&state);
RETURN_IF_EXCEPTION(scope, false);
if (usageString == "encrypt")
result |= CryptoKeyUsageEncrypt;
else if (usageString == "decrypt")
result |= CryptoKeyUsageDecrypt;
else if (usageString == "sign")
result |= CryptoKeyUsageSign;
else if (usageString == "verify")
result |= CryptoKeyUsageVerify;
else if (usageString == "deriveKey")
result |= CryptoKeyUsageDeriveKey;
else if (usageString == "deriveBits")
result |= CryptoKeyUsageDeriveBits;
else if (usageString == "wrapKey")
result |= CryptoKeyUsageWrapKey;
else if (usageString == "unwrapKey")
result |= CryptoKeyUsageUnwrapKey;
}
return true;
}