/*
    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 "JSHashChangeEvent.h"

#include "ExceptionCode.h"
#include "HashChangeEvent.h"
#include "JSDOMBinding.h"
#include "JSDictionary.h"
#include "URL.h"
#include <runtime/Error.h>
#include <runtime/JSString.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSHashChangeEventTableValues[] =
{
    { "oldURL", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHashChangeEventOldURL), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "newURL", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHashChangeEventNewURL), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHashChangeEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSHashChangeEventTable = { 8, 7, true, JSHashChangeEventTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSHashChangeEventConstructorTable = { 1, 0, false, JSHashChangeEventConstructorTableValues, 0 };
EncodedJSValue JSC_HOST_CALL JSHashChangeEventConstructor::constructJSHashChangeEvent(ExecState* exec)
{
    JSHashChangeEventConstructor* jsConstructor = jsCast<JSHashChangeEventConstructor*>(exec->callee());

    ScriptExecutionContext* executionContext = jsConstructor->scriptExecutionContext();
    if (!executionContext)
        return throwVMError(exec, createReferenceError(exec, "Constructor associated execution context is unavailable"));

    AtomicString eventType = exec->argument(0).toString(exec)->value(exec);
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    HashChangeEventInit eventInit;

    JSValue initializerValue = exec->argument(1);
    if (!initializerValue.isUndefinedOrNull()) {
        // Given the above test, this will always yield an object.
        JSObject* initializerObject = initializerValue.toObject(exec);

        // Create the dictionary wrapper from the initializer object.
        JSDictionary dictionary(exec, initializerObject);

        // Attempt to fill in the EventInit.
        if (!fillHashChangeEventInit(eventInit, dictionary))
            return JSValue::encode(jsUndefined());
    }

    RefPtr<HashChangeEvent> event = HashChangeEvent::create(eventType, eventInit);
    return JSValue::encode(toJS(exec, jsConstructor->globalObject(), event.get()));
}

bool fillHashChangeEventInit(HashChangeEventInit& eventInit, JSDictionary& dictionary)
{
    if (!fillEventInit(eventInit, dictionary))
        return false;

    if (!dictionary.tryGetProperty("oldURL", eventInit.oldURL))
        return false;
    if (!dictionary.tryGetProperty("newURL", eventInit.newURL))
        return false;
    return true;
}

const ClassInfo JSHashChangeEventConstructor::s_info = { "HashChangeEventConstructor", &Base::s_info, &JSHashChangeEventConstructorTable, 0, CREATE_METHOD_TABLE(JSHashChangeEventConstructor) };

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

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

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

ConstructType JSHashChangeEventConstructor::getConstructData(JSCell*, ConstructData& constructData)
{
    constructData.native.function = constructJSHashChangeEvent;
    return ConstructTypeHost;
}

/* Hash table for prototype */

static const HashTableValue JSHashChangeEventPrototypeTableValues[] =
{
    { "initHashChangeEvent", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsHashChangeEventPrototypeFunctionInitHashChangeEvent), (intptr_t) (0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSHashChangeEventPrototypeTable = { 2, 1, false, JSHashChangeEventPrototypeTableValues, 0 };
const ClassInfo JSHashChangeEventPrototype::s_info = { "HashChangeEventPrototype", &Base::s_info, &JSHashChangeEventPrototypeTable, 0, CREATE_METHOD_TABLE(JSHashChangeEventPrototype) };

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

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

const ClassInfo JSHashChangeEvent::s_info = { "HashChangeEvent", &Base::s_info, &JSHashChangeEventTable, 0 , CREATE_METHOD_TABLE(JSHashChangeEvent) };

JSHashChangeEvent::JSHashChangeEvent(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<HashChangeEvent> impl)
    : JSEvent(structure, globalObject, impl)
{
}

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

JSObject* JSHashChangeEvent::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
    return JSHashChangeEventPrototype::create(vm, globalObject, JSHashChangeEventPrototype::createStructure(vm, globalObject, JSEventPrototype::self(vm, globalObject)));
}

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

EncodedJSValue jsHashChangeEventOldURL(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSHashChangeEvent* castedThis = jsDynamicCast<JSHashChangeEvent*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    HashChangeEvent& impl = castedThis->impl();
    JSValue result = jsStringWithCache(exec, impl.oldURL());
    return JSValue::encode(result);
}


EncodedJSValue jsHashChangeEventNewURL(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSHashChangeEvent* castedThis = jsDynamicCast<JSHashChangeEvent*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    HashChangeEvent& impl = castedThis->impl();
    JSValue result = jsStringWithCache(exec, impl.newURL());
    return JSValue::encode(result);
}


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

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

EncodedJSValue JSC_HOST_CALL jsHashChangeEventPrototypeFunctionInitHashChangeEvent(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSHashChangeEvent* castedThis = jsDynamicCast<JSHashChangeEvent*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSHashChangeEvent::info());
    HashChangeEvent& impl = castedThis->impl();
    const String& type(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    bool canBubble(exec->argument(1).toBoolean(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    bool cancelable(exec->argument(2).toBoolean(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    const String& oldURL(exec->argument(3).isEmpty() ? String() : exec->argument(3).toString(exec)->value(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    const String& newURL(exec->argument(4).isEmpty() ? String() : exec->argument(4).toString(exec)->value(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    impl.initHashChangeEvent(type, canBubble, cancelable, oldURL, newURL);
    return JSValue::encode(jsUndefined());
}


}
