webengine/osswebengine/DerivedSources/WebCore/JSNodeList.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2     This file is part of the WebKit open source project.
       
     3     This file has been generated by generate-bindings.pl. DO NOT MODIFY!
       
     4 
       
     5     This library is free software; you can redistribute it and/or
       
     6     modify it under the terms of the GNU Library General Public
       
     7     License as published by the Free Software Foundation; either
       
     8     version 2 of the License, or (at your option) any later version.
       
     9 
       
    10     This library is distributed in the hope that it will be useful,
       
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13     Library General Public License for more details.
       
    14 
       
    15     You should have received a copy of the GNU Library General Public License
       
    16     along with this library; see the file COPYING.LIB.  If not, write to
       
    17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    18     Boston, MA 02110-1301, USA.
       
    19 */
       
    20 
       
    21 #include "config.h"
       
    22 
       
    23 #include "JSNodeList.h"
       
    24 
       
    25 #include <wtf/GetPtr.h>
       
    26 
       
    27 #include "AtomicString.h"
       
    28 #include "ExceptionCode.h"
       
    29 #include "JSNode.h"
       
    30 #include "Node.h"
       
    31 #include "NodeList.h"
       
    32 
       
    33 using namespace KJS;
       
    34 
       
    35 namespace WebCore {
       
    36 
       
    37 /* Hash table */
       
    38 
       
    39 static const HashEntry JSNodeListTableEntries[] =
       
    40 {
       
    41     { 0, 0, 0, 0, 0 },
       
    42     { "length", JSNodeList::LengthAttrNum, DontDelete|ReadOnly, 0, &JSNodeListTableEntries[2] },
       
    43     { "constructor", JSNodeList::ConstructorAttrNum, DontDelete|DontEnum|ReadOnly, 0, 0 }
       
    44 };
       
    45 
       
    46 static const HashTable JSNodeListTable = 
       
    47 {
       
    48     2, 3, JSNodeListTableEntries, 2
       
    49 };
       
    50 
       
    51 /* Hash table for constructor */
       
    52 
       
    53 static const HashEntry JSNodeListConstructorTableEntries[] =
       
    54 {
       
    55     { 0, 0, 0, 0, 0 }
       
    56 };
       
    57 
       
    58 static const HashTable JSNodeListConstructorTable = 
       
    59 {
       
    60     2, 1, JSNodeListConstructorTableEntries, 1
       
    61 };
       
    62 
       
    63 class JSNodeListConstructor : public DOMObject {
       
    64 public:
       
    65     JSNodeListConstructor(ExecState* exec)
       
    66     {
       
    67         setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
       
    68         putDirect(exec->propertyNames().prototype, JSNodeListPrototype::self(exec), None);
       
    69     }
       
    70     virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
       
    71     JSValue* getValueProperty(ExecState*, int token) const;
       
    72     virtual const ClassInfo* classInfo() const { return &info; }
       
    73     static const ClassInfo info;
       
    74 
       
    75     virtual bool implementsHasInstance() const { return true; }
       
    76 };
       
    77 
       
    78 const ClassInfo JSNodeListConstructor::info = { "NodeListConstructor", 0, &JSNodeListConstructorTable, 0 };
       
    79 
       
    80 bool JSNodeListConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
    81 {
       
    82     return getStaticValueSlot<JSNodeListConstructor, DOMObject>(exec, &JSNodeListConstructorTable, this, propertyName, slot);
       
    83 }
       
    84 
       
    85 JSValue* JSNodeListConstructor::getValueProperty(ExecState*, int token) const
       
    86 {
       
    87     // The token is the numeric value of its associated constant
       
    88     return jsNumber(token);
       
    89 }
       
    90 
       
    91 /* Hash table for prototype */
       
    92 
       
    93 static const HashEntry JSNodeListPrototypeTableEntries[] =
       
    94 {
       
    95     { "item", JSNodeList::ItemFuncNum, DontDelete|Function, 1, 0 }
       
    96 };
       
    97 
       
    98 static const HashTable JSNodeListPrototypeTable = 
       
    99 {
       
   100     2, 1, JSNodeListPrototypeTableEntries, 1
       
   101 };
       
   102 
       
   103 const ClassInfo JSNodeListPrototype::info = { "NodeListPrototype", 0, &JSNodeListPrototypeTable, 0 };
       
   104 
       
   105 JSObject* JSNodeListPrototype::self(ExecState* exec)
       
   106 {
       
   107     return KJS::cacheGlobalObject<JSNodeListPrototype>(exec, "[[JSNodeList.prototype]]");
       
   108 }
       
   109 
       
   110 bool JSNodeListPrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
   111 {
       
   112     return getStaticFunctionSlot<JSNodeListPrototypeFunction, JSObject>(exec, &JSNodeListPrototypeTable, this, propertyName, slot);
       
   113 }
       
   114 
       
   115 const ClassInfo JSNodeList::info = { "NodeList", 0, &JSNodeListTable, 0 };
       
   116 
       
   117 JSNodeList::JSNodeList(ExecState* exec, NodeList* impl)
       
   118     : m_impl(impl)
       
   119 {
       
   120     setPrototype(JSNodeListPrototype::self(exec));
       
   121 }
       
   122 
       
   123 JSNodeList::~JSNodeList()
       
   124 {
       
   125     ScriptInterpreter::forgetDOMObject(m_impl.get());
       
   126 }
       
   127 
       
   128 bool JSNodeList::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
   129 {
       
   130     const HashEntry* entry = Lookup::findEntry(&JSNodeListTable, propertyName);
       
   131     if (entry) {
       
   132         slot.setStaticEntry(this, entry, staticValueGetter<JSNodeList>);
       
   133         return true;
       
   134     }
       
   135     bool ok;
       
   136     unsigned index = propertyName.toUInt32(&ok, false);
       
   137     if (ok && index < static_cast<NodeList*>(impl())->length()) {
       
   138         slot.setCustomIndex(this, index, indexGetter);
       
   139         return true;
       
   140     }
       
   141     if (canGetItemsForName(exec, static_cast<NodeList*>(impl()), propertyName)) {
       
   142         slot.setCustom(this, nameGetter);
       
   143         return true;
       
   144     }
       
   145     return KJS::DOMObject::getOwnPropertySlot(exec, propertyName, slot);
       
   146 }
       
   147 
       
   148 JSValue* JSNodeList::getValueProperty(ExecState* exec, int token) const
       
   149 {
       
   150     switch (token) {
       
   151     case LengthAttrNum: {
       
   152         NodeList* imp = static_cast<NodeList*>(impl());
       
   153 
       
   154         return jsNumber(imp->length());
       
   155     }
       
   156     case ConstructorAttrNum:
       
   157         return getConstructor(exec);
       
   158     }
       
   159     return 0;
       
   160 }
       
   161 
       
   162 JSValue* JSNodeList::getConstructor(ExecState* exec)
       
   163 {
       
   164     return KJS::cacheGlobalObject<JSNodeListConstructor>(exec, "[[NodeList.constructor]]");
       
   165 }
       
   166 JSValue* JSNodeListPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
       
   167 {
       
   168     if (!thisObj->inherits(&JSNodeList::info))
       
   169       return throwError(exec, TypeError);
       
   170 
       
   171     NodeList* imp = static_cast<NodeList*>(static_cast<JSNodeList*>(thisObj)->impl());
       
   172 
       
   173     switch (id) {
       
   174     case JSNodeList::ItemFuncNum: {
       
   175         bool indexOk;
       
   176         int index = args[0]->toInt32(exec, indexOk);
       
   177         if (!indexOk) {
       
   178             setDOMException(exec, TYPE_MISMATCH_ERR);
       
   179             return jsUndefined();
       
   180         }
       
   181         if (index < 0) {
       
   182             setDOMException(exec, INDEX_SIZE_ERR);
       
   183             return jsUndefined();
       
   184         }
       
   185 
       
   186 
       
   187         KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->item(index)));
       
   188         return result;
       
   189     }
       
   190     }
       
   191     return 0;
       
   192 }
       
   193 
       
   194 JSValue* JSNodeList::indexGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
       
   195 {
       
   196     JSNodeList* thisObj = static_cast<JSNodeList*>(slot.slotBase());
       
   197     return toJS(exec, static_cast<NodeList*>(thisObj->impl())->item(slot.index()));
       
   198 }
       
   199 KJS::JSValue* toJS(KJS::ExecState* exec, NodeList* obj)
       
   200 {
       
   201     return KJS::cacheDOMObject<NodeList, JSNodeList>(exec, obj);
       
   202 }
       
   203 NodeList* toNodeList(KJS::JSValue* val)
       
   204 {
       
   205     return val->isObject(&JSNodeList::info) ? static_cast<JSNodeList*>(val)->impl() : 0;
       
   206 }
       
   207 
       
   208 }