/*
    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"

#if ENABLE(CSP_NEXT)

#include "JSSecurityPolicyViolationEvent.h"

#include "JSDictionary.h"
#include "SecurityPolicyViolationEvent.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 JSSecurityPolicyViolationEventTableValues[] =
{
    { "documentURI", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSecurityPolicyViolationEventDocumentURI), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "referrer", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSecurityPolicyViolationEventReferrer), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "blockedURI", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSecurityPolicyViolationEventBlockedURI), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "violatedDirective", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSecurityPolicyViolationEventViolatedDirective), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "effectiveDirective", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSecurityPolicyViolationEventEffectiveDirective), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "originalPolicy", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSecurityPolicyViolationEventOriginalPolicy), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "sourceFile", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSecurityPolicyViolationEventSourceFile), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "lineNumber", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSecurityPolicyViolationEventLineNumber), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSecurityPolicyViolationEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSSecurityPolicyViolationEventTable = { 33, 31, true, JSSecurityPolicyViolationEventTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSSecurityPolicyViolationEventConstructorTable = { 1, 0, false, JSSecurityPolicyViolationEventConstructorTableValues, 0 };
EncodedJSValue JSC_HOST_CALL JSSecurityPolicyViolationEventConstructor::constructJSSecurityPolicyViolationEvent(ExecState* exec)
{
    JSSecurityPolicyViolationEventConstructor* jsConstructor = jsCast<JSSecurityPolicyViolationEventConstructor*>(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());

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

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

bool fillSecurityPolicyViolationEventInit(SecurityPolicyViolationEventInit& eventInit, JSDictionary& dictionary)
{
    if (!fillEventInit(eventInit, dictionary))
        return false;

    if (!dictionary.tryGetProperty("documentURI", eventInit.documentURI))
        return false;
    if (!dictionary.tryGetProperty("referrer", eventInit.referrer))
        return false;
    if (!dictionary.tryGetProperty("blockedURI", eventInit.blockedURI))
        return false;
    if (!dictionary.tryGetProperty("violatedDirective", eventInit.violatedDirective))
        return false;
    if (!dictionary.tryGetProperty("effectiveDirective", eventInit.effectiveDirective))
        return false;
    if (!dictionary.tryGetProperty("originalPolicy", eventInit.originalPolicy))
        return false;
    if (!dictionary.tryGetProperty("sourceFile", eventInit.sourceFile))
        return false;
    if (!dictionary.tryGetProperty("lineNumber", eventInit.lineNumber))
        return false;
    return true;
}

const ClassInfo JSSecurityPolicyViolationEventConstructor::s_info = { "SecurityPolicyViolationEventConstructor", &Base::s_info, &JSSecurityPolicyViolationEventConstructorTable, 0, CREATE_METHOD_TABLE(JSSecurityPolicyViolationEventConstructor) };

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

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

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

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

/* Hash table for prototype */

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

static const HashTable JSSecurityPolicyViolationEventPrototypeTable = { 1, 0, false, JSSecurityPolicyViolationEventPrototypeTableValues, 0 };
const ClassInfo JSSecurityPolicyViolationEventPrototype::s_info = { "SecurityPolicyViolationEventPrototype", &Base::s_info, &JSSecurityPolicyViolationEventPrototypeTable, 0, CREATE_METHOD_TABLE(JSSecurityPolicyViolationEventPrototype) };

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

const ClassInfo JSSecurityPolicyViolationEvent::s_info = { "SecurityPolicyViolationEvent", &Base::s_info, &JSSecurityPolicyViolationEventTable, 0 , CREATE_METHOD_TABLE(JSSecurityPolicyViolationEvent) };

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

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

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

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

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


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


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


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


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


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


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


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


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

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


}

#endif // ENABLE(CSP_NEXT)
