/*
    This file is part of the WebKit open source project.
    This file has been generated by generate-bindings.pl. DO NOT MODIFY!

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "config.h"
#include "JSNodeIterator.h"

#include "ExceptionCode.h"
#include "JSDOMBinding.h"
#include "JSNode.h"
#include "JSNodeFilter.h"
#include "Node.h"
#include "NodeFilter.h"
#include "NodeIterator.h"
#include <runtime/Error.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSNodeIteratorTableValues[] =
{
    { "root", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNodeIteratorRoot), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "whatToShow", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNodeIteratorWhatToShow), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "filter", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNodeIteratorFilter), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "expandEntityReferences", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNodeIteratorExpandEntityReferences), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "referenceNode", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNodeIteratorReferenceNode), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "pointerBeforeReferenceNode", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNodeIteratorPointerBeforeReferenceNode), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNodeIteratorConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSNodeIteratorTable = { 18, 15, true, JSNodeIteratorTableValues, 0 };
/* Hash table for constructor */

static const HashTableValue JSNodeIteratorConstructorTableValues[] =
{
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSNodeIteratorConstructorTable = { 1, 0, false, JSNodeIteratorConstructorTableValues, 0 };
const ClassInfo JSNodeIteratorConstructor::s_info = { "NodeIteratorConstructor", &Base::s_info, &JSNodeIteratorConstructorTable, 0, CREATE_METHOD_TABLE(JSNodeIteratorConstructor) };

JSNodeIteratorConstructor::JSNodeIteratorConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
    : DOMConstructorObject(structure, globalObject)
{
}

void JSNodeIteratorConstructor::finishCreation(VM& vm, JSDOMGlobalObject* globalObject)
{
    Base::finishCreation(vm);
    ASSERT(inherits(info()));
    putDirect(vm, vm.propertyNames->prototype, JSNodeIteratorPrototype::self(vm, globalObject), DontDelete | ReadOnly);
    putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontDelete | DontEnum);
}

bool JSNodeIteratorConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    return getStaticValueSlot<JSNodeIteratorConstructor, JSDOMWrapper>(exec, JSNodeIteratorConstructorTable, jsCast<JSNodeIteratorConstructor*>(object), propertyName, slot);
}

/* Hash table for prototype */

static const HashTableValue JSNodeIteratorPrototypeTableValues[] =
{
    { "nextNode", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsNodeIteratorPrototypeFunctionNextNode), (intptr_t) (0) },
    { "previousNode", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsNodeIteratorPrototypeFunctionPreviousNode), (intptr_t) (0) },
    { "detach", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsNodeIteratorPrototypeFunctionDetach), (intptr_t) (0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSNodeIteratorPrototypeTable = { 8, 7, false, JSNodeIteratorPrototypeTableValues, 0 };
const ClassInfo JSNodeIteratorPrototype::s_info = { "NodeIteratorPrototype", &Base::s_info, &JSNodeIteratorPrototypeTable, 0, CREATE_METHOD_TABLE(JSNodeIteratorPrototype) };

JSObject* JSNodeIteratorPrototype::self(VM& vm, JSGlobalObject* globalObject)
{
    return getDOMPrototype<JSNodeIterator>(vm, globalObject);
}

bool JSNodeIteratorPrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    JSNodeIteratorPrototype* thisObject = jsCast<JSNodeIteratorPrototype*>(object);
    return getStaticFunctionSlot<JSObject>(exec, JSNodeIteratorPrototypeTable, thisObject, propertyName, slot);
}

const ClassInfo JSNodeIterator::s_info = { "NodeIterator", &Base::s_info, &JSNodeIteratorTable, 0 , CREATE_METHOD_TABLE(JSNodeIterator) };

JSNodeIterator::JSNodeIterator(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<NodeIterator> impl)
    : JSDOMWrapper(structure, globalObject)
    , m_impl(impl.leakRef())
{
}

void JSNodeIterator::finishCreation(VM& vm)
{
    Base::finishCreation(vm);
    ASSERT(inherits(info()));
}

JSObject* JSNodeIterator::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
    return JSNodeIteratorPrototype::create(vm, globalObject, JSNodeIteratorPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
}

void JSNodeIterator::destroy(JSC::JSCell* cell)
{
    JSNodeIterator* thisObject = static_cast<JSNodeIterator*>(cell);
    thisObject->JSNodeIterator::~JSNodeIterator();
}

JSNodeIterator::~JSNodeIterator()
{
    releaseImplIfNotNull();
}

bool JSNodeIterator::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    JSNodeIterator* thisObject = jsCast<JSNodeIterator*>(object);
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    return getStaticValueSlot<JSNodeIterator, Base>(exec, JSNodeIteratorTable, thisObject, propertyName, slot);
}

EncodedJSValue jsNodeIteratorRoot(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSNodeIterator* castedThis = jsDynamicCast<JSNodeIterator*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    NodeIterator& impl = castedThis->impl();
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.root()));
    return JSValue::encode(result);
}


EncodedJSValue jsNodeIteratorWhatToShow(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSNodeIterator* castedThis = jsDynamicCast<JSNodeIterator*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    NodeIterator& impl = castedThis->impl();
    JSValue result = jsNumber(impl.whatToShow());
    return JSValue::encode(result);
}


EncodedJSValue jsNodeIteratorFilter(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSNodeIterator* castedThis = jsDynamicCast<JSNodeIterator*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    NodeIterator& impl = castedThis->impl();
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.filter()));
    return JSValue::encode(result);
}


EncodedJSValue jsNodeIteratorExpandEntityReferences(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSNodeIterator* castedThis = jsDynamicCast<JSNodeIterator*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    NodeIterator& impl = castedThis->impl();
    JSValue result = jsBoolean(impl.expandEntityReferences());
    return JSValue::encode(result);
}


EncodedJSValue jsNodeIteratorReferenceNode(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSNodeIterator* castedThis = jsDynamicCast<JSNodeIterator*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    NodeIterator& impl = castedThis->impl();
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.referenceNode()));
    return JSValue::encode(result);
}


EncodedJSValue jsNodeIteratorPointerBeforeReferenceNode(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSNodeIterator* castedThis = jsDynamicCast<JSNodeIterator*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    NodeIterator& impl = castedThis->impl();
    JSValue result = jsBoolean(impl.pointerBeforeReferenceNode());
    return JSValue::encode(result);
}


EncodedJSValue jsNodeIteratorConstructor(ExecState* exec, EncodedJSValue thisValue, EncodedJSValue, PropertyName)
{
    JSNodeIterator* domObject = jsDynamicCast<JSNodeIterator*>(JSValue::decode(thisValue));
    if (!domObject)
        return throwVMTypeError(exec);
    if (!domObject)
        return throwVMTypeError(exec);
    return JSValue::encode(JSNodeIterator::getConstructor(exec->vm(), domObject->globalObject()));
}

JSValue JSNodeIterator::getConstructor(VM& vm, JSGlobalObject* globalObject)
{
    return getDOMConstructor<JSNodeIteratorConstructor>(vm, jsCast<JSDOMGlobalObject*>(globalObject));
}

EncodedJSValue JSC_HOST_CALL jsNodeIteratorPrototypeFunctionNextNode(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSNodeIterator* castedThis = jsDynamicCast<JSNodeIterator*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSNodeIterator::info());
    NodeIterator& impl = castedThis->impl();
    ExceptionCode ec = 0;

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.nextNode(exec, ec)));
    setDOMException(exec, ec);
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsNodeIteratorPrototypeFunctionPreviousNode(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSNodeIterator* castedThis = jsDynamicCast<JSNodeIterator*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSNodeIterator::info());
    NodeIterator& impl = castedThis->impl();
    ExceptionCode ec = 0;

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.previousNode(exec, ec)));
    setDOMException(exec, ec);
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsNodeIteratorPrototypeFunctionDetach(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSNodeIterator* castedThis = jsDynamicCast<JSNodeIterator*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSNodeIterator::info());
    NodeIterator& impl = castedThis->impl();
    impl.detach();
    return JSValue::encode(jsUndefined());
}

bool JSNodeIteratorOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
{
    UNUSED_PARAM(handle);
    UNUSED_PARAM(visitor);
    return false;
}

void JSNodeIteratorOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
    JSNodeIterator* jsNodeIterator = jsCast<JSNodeIterator*>(handle.get().asCell());
    DOMWrapperWorld& world = *static_cast<DOMWrapperWorld*>(context);
    uncacheWrapper(world, &jsNodeIterator->impl(), jsNodeIterator);
    jsNodeIterator->releaseImpl();
}

JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, NodeIterator* impl)
{
    if (!impl)
        return jsNull();
    if (JSValue result = getExistingWrapper<JSNodeIterator>(exec, impl))
        return result;
#if COMPILER(CLANG)
    // If you hit this failure the interface definition has the ImplementationLacksVTable
    // attribute. You should remove that attribute. If the class has subclasses
    // that may be passed through this toJS() function you should use the SkipVTableValidation
    // attribute to NodeIterator.
    COMPILE_ASSERT(!__is_polymorphic(NodeIterator), NodeIterator_is_polymorphic_but_idl_claims_not_to_be);
#endif
    ReportMemoryCost<NodeIterator>::reportMemoryCost(exec, impl);
    return createNewWrapper<JSNodeIterator>(exec, globalObject, impl);
}

NodeIterator* toNodeIterator(JSC::JSValue value)
{
    return value.inherits(JSNodeIterator::info()) ? &jsCast<JSNodeIterator*>(value)->impl() : 0;
}

}
