/*
    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(SHADOW_DOM)

#include "JSCSSHostRule.h"

#include "CSSHostRule.h"
#include "CSSRuleList.h"
#include "ExceptionCode.h"
#include "JSCSSRuleList.h"
#include "JSDOMBinding.h"
#include <runtime/Error.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSCSSHostRuleTableValues[] =
{
    { "cssRules", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSHostRuleCssRules), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCSSHostRuleConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSCSSHostRuleTable = { 4, 3, true, JSCSSHostRuleTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSCSSHostRuleConstructorTable = { 1, 0, false, JSCSSHostRuleConstructorTableValues, 0 };
const ClassInfo JSCSSHostRuleConstructor::s_info = { "CSSHostRuleConstructor", &Base::s_info, &JSCSSHostRuleConstructorTable, 0, CREATE_METHOD_TABLE(JSCSSHostRuleConstructor) };

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

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

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

/* Hash table for prototype */

static const HashTableValue JSCSSHostRulePrototypeTableValues[] =
{
    { "insertRule", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsCSSHostRulePrototypeFunctionInsertRule), (intptr_t) (0) },
    { "deleteRule", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsCSSHostRulePrototypeFunctionDeleteRule), (intptr_t) (0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSCSSHostRulePrototypeTable = { 4, 3, false, JSCSSHostRulePrototypeTableValues, 0 };
const ClassInfo JSCSSHostRulePrototype::s_info = { "CSSHostRulePrototype", &Base::s_info, &JSCSSHostRulePrototypeTable, 0, CREATE_METHOD_TABLE(JSCSSHostRulePrototype) };

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

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

const ClassInfo JSCSSHostRule::s_info = { "CSSHostRule", &Base::s_info, &JSCSSHostRuleTable, 0 , CREATE_METHOD_TABLE(JSCSSHostRule) };

JSCSSHostRule::JSCSSHostRule(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<CSSHostRule> impl)
    : JSCSSRule(structure, globalObject, impl)
{
}

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

JSObject* JSCSSHostRule::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
    return JSCSSHostRulePrototype::create(vm, globalObject, JSCSSHostRulePrototype::createStructure(vm, globalObject, JSCSSRulePrototype::self(vm, globalObject)));
}

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

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


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

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

EncodedJSValue JSC_HOST_CALL jsCSSHostRulePrototypeFunctionInsertRule(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSCSSHostRule* castedThis = jsDynamicCast<JSCSSHostRule*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSCSSHostRule::info());
    CSSHostRule& impl = castedThis->impl();
    ExceptionCode ec = 0;
    const String& rule(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    unsigned index(toUInt32(exec, exec->argument(1), NormalConversion));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = jsNumber(impl.insertRule(rule, index, ec));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsCSSHostRulePrototypeFunctionDeleteRule(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSCSSHostRule* castedThis = jsDynamicCast<JSCSSHostRule*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSCSSHostRule::info());
    CSSHostRule& impl = castedThis->impl();
    ExceptionCode ec = 0;
    unsigned index(toUInt32(exec, exec->argument(0), NormalConversion));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    impl.deleteRule(index, ec);
    setDOMException(exec, ec);
    return JSValue::encode(jsUndefined());
}


}

#endif // ENABLE(SHADOW_DOM)
