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

#include "CloseEvent.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 JSCloseEventTableValues[] =
{
    { "wasClean", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCloseEventWasClean), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "code", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCloseEventCode), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "reason", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCloseEventReason), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCloseEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSCloseEventTable = { 9, 7, true, JSCloseEventTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSCloseEventConstructorTable = { 1, 0, false, JSCloseEventConstructorTableValues, 0 };
EncodedJSValue JSC_HOST_CALL JSCloseEventConstructor::constructJSCloseEvent(ExecState* exec)
{
    JSCloseEventConstructor* jsConstructor = jsCast<JSCloseEventConstructor*>(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());

    CloseEventInit 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 (!fillCloseEventInit(eventInit, dictionary))
            return JSValue::encode(jsUndefined());
    }

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

bool fillCloseEventInit(CloseEventInit& eventInit, JSDictionary& dictionary)
{
    if (!fillEventInit(eventInit, dictionary))
        return false;

    if (!dictionary.tryGetProperty("wasClean", eventInit.wasClean))
        return false;
    if (!dictionary.tryGetProperty("code", eventInit.code))
        return false;
    if (!dictionary.tryGetProperty("reason", eventInit.reason))
        return false;
    return true;
}

static const HashTable& getJSCloseEventConstructorTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSCloseEventConstructorTable);
}

const ClassInfo JSCloseEventConstructor::s_info = { "CloseEventConstructor", &Base::s_info, 0, getJSCloseEventConstructorTable, CREATE_METHOD_TABLE(JSCloseEventConstructor) };

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

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

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

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

/* Hash table for prototype */

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

static const HashTable JSCloseEventPrototypeTable = { 1, 0, false, JSCloseEventPrototypeTableValues, 0 };
static const HashTable& getJSCloseEventPrototypeTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSCloseEventPrototypeTable);
}

const ClassInfo JSCloseEventPrototype::s_info = { "CloseEventPrototype", &Base::s_info, 0, getJSCloseEventPrototypeTable, CREATE_METHOD_TABLE(JSCloseEventPrototype) };

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

static const HashTable& getJSCloseEventTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSCloseEventTable);
}

const ClassInfo JSCloseEvent::s_info = { "CloseEvent", &Base::s_info, 0, getJSCloseEventTable , CREATE_METHOD_TABLE(JSCloseEvent) };

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

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

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

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

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


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


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


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

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


}
