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

#include "ErrorEvent.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 JSErrorEventTableValues[] =
{
    { "message", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventMessage), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "filename", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventFilename), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "lineno", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventLineno), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "colno", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventColno), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsErrorEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSErrorEventTable = { 16, 15, true, JSErrorEventTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSErrorEventConstructorTable = { 1, 0, false, JSErrorEventConstructorTableValues, 0 };
EncodedJSValue JSC_HOST_CALL JSErrorEventConstructor::constructJSErrorEvent(ExecState* exec)
{
    JSErrorEventConstructor* jsConstructor = jsCast<JSErrorEventConstructor*>(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());

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

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

bool fillErrorEventInit(ErrorEventInit& eventInit, JSDictionary& dictionary)
{
    if (!fillEventInit(eventInit, dictionary))
        return false;

    if (!dictionary.tryGetProperty("message", eventInit.message))
        return false;
    if (!dictionary.tryGetProperty("filename", eventInit.filename))
        return false;
    if (!dictionary.tryGetProperty("lineno", eventInit.lineno))
        return false;
    if (!dictionary.tryGetProperty("colno", eventInit.colno))
        return false;
    return true;
}

static const HashTable& getJSErrorEventConstructorTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSErrorEventConstructorTable);
}

const ClassInfo JSErrorEventConstructor::s_info = { "ErrorEventConstructor", &Base::s_info, 0, getJSErrorEventConstructorTable, CREATE_METHOD_TABLE(JSErrorEventConstructor) };

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

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

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

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

/* Hash table for prototype */

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

static const HashTable JSErrorEventPrototypeTable = { 1, 0, false, JSErrorEventPrototypeTableValues, 0 };
static const HashTable& getJSErrorEventPrototypeTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSErrorEventPrototypeTable);
}

const ClassInfo JSErrorEventPrototype::s_info = { "ErrorEventPrototype", &Base::s_info, 0, getJSErrorEventPrototypeTable, CREATE_METHOD_TABLE(JSErrorEventPrototype) };

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

static const HashTable& getJSErrorEventTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSErrorEventTable);
}

const ClassInfo JSErrorEvent::s_info = { "ErrorEvent", &Base::s_info, 0, getJSErrorEventTable , CREATE_METHOD_TABLE(JSErrorEvent) };

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

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

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

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

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


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


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


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


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

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


}
