本文整理汇总了C++中JSArray::length方法的典型用法代码示例。如果您正苦于以下问题:C++ JSArray::length方法的具体用法?C++ JSArray::length怎么用?C++ JSArray::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSArray
的用法示例。
在下文中一共展示了JSArray::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getEventListeners
JSValue JSCommandLineAPIHost::getEventListeners(ExecState& state)
{
if (state.argumentCount() < 1)
return jsUndefined();
JSValue value = state.uncheckedArgument(0);
if (!value.isObject() || value.isNull())
return jsUndefined();
Node* node = JSNode::toWrapped(value);
if (!node)
return jsUndefined();
Vector<EventListenerInfo> listenersArray;
wrapped().getEventListenersImpl(node, listenersArray);
JSObject* result = constructEmptyObject(&state);
for (size_t i = 0; i < listenersArray.size(); ++i) {
JSArray* listeners = getJSListenerFunctions(state, &node->document(), listenersArray[i]);
if (!listeners->length())
continue;
AtomicString eventType = listenersArray[i].eventType;
result->putDirect(state.vm(), Identifier::fromString(&state, eventType.impl()), JSValue(listeners));
}
return result;
}
示例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: 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();
}
示例4: getEventListeners
JSValue JSInjectedScriptHost::getEventListeners(ExecState* exec)
{
if (exec->argumentCount() < 1)
return jsUndefined();
JSValue value = exec->argument(0);
if (!value.isObject() || value.isNull())
return jsUndefined();
Node* node = toNode(value);
if (!node)
return jsUndefined();
// This can only happen for orphan DocumentType nodes.
Document* document = node->document();
if (!node->document())
return jsUndefined();
Vector<EventListenerInfo> listenersArray;
impl()->getEventListenersImpl(node, listenersArray);
JSObject* result = constructEmptyObject(exec);
for (size_t i = 0; i < listenersArray.size(); ++i) {
JSArray* listeners = getJSListenerFunctions(exec, document, listenersArray[i]);
if (!listeners->length())
continue;
AtomicString eventType = listenersArray[i].eventType;
result->putDirect(exec->globalData(), Identifier(exec, eventType.impl()), JSValue(listeners));
}
return result;
}
示例5: 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;
}
示例6: 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;
}
示例7: getOwnPropertySlot
bool JSArray::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
JSArray* thisObject = jsCast<JSArray*>(object);
if (propertyName == exec->propertyNames().length) {
unsigned attributes = thisObject->isLengthWritable() ? DontDelete | DontEnum : DontDelete | DontEnum | ReadOnly;
slot.setValue(thisObject, attributes, jsNumber(thisObject->length()));
return true;
}
return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot);
}
示例8: 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++) {
// FIXME: What if the array is in sparse mode? https://bugs.webkit.org/show_bug.cgi?id=95610
JSValue element = array->getIndexQuickly(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;
}
示例9: 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;
}
示例10: getLastParen
JSValue RegExpConstructor::getLastParen(ExecState* exec)
{
JSArray* array = m_cachedResult.lastResult(exec, this);
unsigned length = array->length();
if (length > 1) {
JSValue result = JSValue(array).get(exec, length - 1);
ASSERT(result.isString() || result.isUndefined());
if (!result.isUndefined())
return result;
}
return jsEmptyString(exec);
}
示例11: getBackref
JSValue RegExpConstructor::getBackref(ExecState* exec, unsigned i)
{
JSArray* array = m_cachedResult.lastResult(exec, this);
if (i < array->length()) {
JSValue result = JSValue(array).get(exec, i);
ASSERT(result.isString() || result.isUndefined());
if (!result.isUndefined())
return result;
}
return jsEmptyString(exec);
}
示例12: 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;
}
示例13: 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();
}
示例14: 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);
}
示例15: 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);
}