summaryrefslogtreecommitdiff
path: root/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp')
-rw-r--r--Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp79
1 files changed, 41 insertions, 38 deletions
diff --git a/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp b/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp
index 227c34dfb..d8286a52a 100644
--- a/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp
+++ b/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,63 +27,61 @@
#include "JSHTMLAllCollection.h"
#include "HTMLAllCollection.h"
-#include "JSDOMBinding.h"
#include "JSNode.h"
#include "JSNodeList.h"
-#include "Node.h"
#include "StaticNodeList.h"
-#include <runtime/JSCJSValue.h>
-#include <wtf/Vector.h>
-#include <wtf/text/AtomicString.h>
+#include <runtime/IdentifierInlines.h>
using namespace JSC;
namespace WebCore {
-static JSValue getNamedItems(ExecState* exec, JSHTMLAllCollection* collection, PropertyName propertyName)
+static JSValue namedItems(ExecState& state, JSHTMLAllCollection* collection, PropertyName propertyName)
{
- Vector<Ref<Element>> namedItems;
- collection->impl().namedItems(propertyNameToAtomicString(propertyName), namedItems);
+ Vector<Ref<Element>> namedItems = collection->wrapped().namedItems(propertyNameToAtomicString(propertyName));
if (namedItems.isEmpty())
return jsUndefined();
if (namedItems.size() == 1)
- return toJS(exec, collection->globalObject(), &namedItems[0].get());
+ return toJS(&state, collection->globalObject(), namedItems[0]);
// FIXME: HTML5 specification says this should be a HTMLCollection.
// http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlallcollection
- return toJS(exec, collection->globalObject(), StaticElementList::adopt(namedItems).get());
+ return toJS(&state, collection->globalObject(), StaticElementList::create(WTFMove(namedItems)));
}
// HTMLAllCollections are strange objects, they support both get and call.
static EncodedJSValue JSC_HOST_CALL callHTMLAllCollection(ExecState* exec)
{
+ VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
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();
+ JSHTMLAllCollection* jsCollection = jsCast<JSHTMLAllCollection*>(exec->jsCallee());
+ HTMLAllCollection& collection = jsCollection->wrapped();
// 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);
- unsigned index = toUInt32FromStringImpl(string.impl());
- if (index != PropertyName::NotAnIndex)
- return JSValue::encode(toJS(exec, jsCollection->globalObject(), collection.item(index)));
+ String string = exec->argument(0).toWTFString(exec);
+ RETURN_IF_EXCEPTION(scope, encodedJSValue());
+ if (std::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(getNamedItems(exec, jsCollection, Identifier(exec, string)));
+ 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);
- unsigned index = toUInt32FromStringImpl(exec->argument(1).toWTFString(exec).impl());
- if (index != PropertyName::NotAnIndex) {
- if (Node* node = collection.namedItemWithIndex(string, index))
- return JSValue::encode(toJS(exec, jsCollection->globalObject(), node));
+ String string = exec->argument(0).toWTFString(exec);
+ RETURN_IF_EXCEPTION(scope, encodedJSValue());
+ if (std::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());
@@ -92,31 +90,36 @@ static EncodedJSValue JSC_HOST_CALL callHTMLAllCollection(ExecState* exec)
CallType JSHTMLAllCollection::getCallData(JSCell*, CallData& callData)
{
callData.native.function = callHTMLAllCollection;
- return CallTypeHost;
+ return CallType::Host;
}
-bool JSHTMLAllCollection::canGetItemsForName(ExecState*, HTMLAllCollection* collection, PropertyName propertyName)
+bool JSHTMLAllCollection::nameGetter(ExecState* state, PropertyName propertyName, JSValue& value)
{
- return collection->hasNamedItem(propertyNameToAtomicString(propertyName));
-}
+ JSValue items = namedItems(*state, this, propertyName);
+ if (items.isUndefined())
+ return false;
-EncodedJSValue JSHTMLAllCollection::nameGetter(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName propertyName)
-{
- JSHTMLAllCollection* thisObj = jsCast<JSHTMLAllCollection*>(JSValue::decode(slotBase));
- return JSValue::encode(getNamedItems(exec, thisObj, propertyName));
+ value = items;
+ return true;
}
-JSValue JSHTMLAllCollection::item(ExecState* exec)
+JSValue JSHTMLAllCollection::item(ExecState& state)
{
- uint32_t index = toUInt32FromStringImpl(exec->argument(0).toString(exec)->value(exec).impl());
- if (index != PropertyName::NotAnIndex)
- return toJS(exec, globalObject(), impl().item(index));
- return getNamedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec)->value(exec)));
+ 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 (std::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* exec)
+JSValue JSHTMLAllCollection::namedItem(ExecState& state)
{
- JSValue value = getNamedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec)->value(exec)));
+ JSValue value = namedItems(state, this, Identifier::fromString(&state, state.argument(0).toWTFString(&state)));
return value.isUndefined() ? jsNull() : value;
}