JSValue JSHTMLAllCollection::item(ExecState* exec) { uint32_t index = toUInt32FromStringImpl(exec->argument(0).toString(exec)->value(exec).impl()); if (index != PropertyName::NotAnIndex) return toJS(exec, globalObject(), impl().item(index)); return namedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec)->value(exec))); }
// HTMLAllCollections are strange objects, they support both get and call. static EncodedJSValue JSC_HOST_CALL callHTMLAllCollection(ExecState* exec) { if (exec->argumentCount() < 1) return JSValue::encode(jsUndefined()); // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case. JSHTMLAllCollection* jsCollection = jsCast<JSHTMLAllCollection*>(exec->callee()); HTMLAllCollection& collection = jsCollection->impl(); // Also, do we need the TypeError test here ? if (exec->argumentCount() == 1) { // Support for document.all(<index>) etc. String string = exec->argument(0).toString(exec)->value(exec); if (Optional<uint32_t> index = parseIndex(*string.impl())) return JSValue::encode(toJS(exec, jsCollection->globalObject(), collection.item(index.value()))); // Support for document.images('<name>') etc. return JSValue::encode(namedItems(*exec, jsCollection, Identifier::fromString(exec, string))); } // The second arg, if set, is the index of the item we want String string = exec->argument(0).toString(exec)->value(exec); if (Optional<uint32_t> index = parseIndex(*exec->argument(1).toWTFString(exec).impl())) { if (auto* item = collection.namedItemWithIndex(string, index.value())) return JSValue::encode(toJS(exec, jsCollection->globalObject(), item)); } return JSValue::encode(jsUndefined()); }
bool JSHTMLAllCollection::nameGetter(ExecState* state, PropertyName propertyName, JSValue& value) { JSValue items = namedItems(*state, this, propertyName); if (items.isUndefined()) return false; value = items; return true; }
JSValue JSHTMLAllCollection::item(ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (UNLIKELY(state.argumentCount() < 1)) return throwException(&state, scope, createNotEnoughArgumentsError(&state)); String argument = state.uncheckedArgument(0).toWTFString(&state); if (Optional<uint32_t> index = parseIndex(*argument.impl())) return toJS(&state, globalObject(), wrapped().item(index.value())); return namedItems(state, this, Identifier::fromString(&state, argument)); }
JSValue JSHTMLAllCollection::namedItem(ExecState& state) { JSValue value = namedItems(state, this, Identifier::fromString(&state, state.argument(0).toString(&state)->value(&state))); return value.isUndefined() ? jsNull() : value; }
JSValue JSHTMLAllCollection::item(ExecState& state) { if (Optional<uint32_t> index = parseIndex(*state.argument(0).toString(&state)->value(&state).impl())) return toJS(&state, globalObject(), impl().item(index.value())); return namedItems(state, this, Identifier::fromString(&state, state.argument(0).toString(&state)->value(&state))); }
EncodedJSValue JSHTMLAllCollection::nameGetter(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName propertyName) { JSHTMLAllCollection* thisObj = jsCast<JSHTMLAllCollection*>(slotBase); return JSValue::encode(namedItems(exec, thisObj, propertyName)); }
JSValue JSHTMLAllCollection::namedItem(ExecState* exec) { JSValue value = namedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec)->value(exec))); return value.isUndefined() ? jsNull() : value; }