
// This file has been auto-generated by code_generator_v8.py. DO NOT MODIFY!

#include "config.h"
#include "V8RelatedEventInit.h"

#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/V8EventInit.h"
#include "bindings/core/v8/V8EventTarget.h"

namespace blink {

void V8RelatedEventInit::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, RelatedEventInit& impl, ExceptionState& exceptionState)
{
    if (isUndefinedOrNull(v8Value))
        return;
    if (!v8Value->IsObject()) {
        exceptionState.throwTypeError("cannot convert to dictionary.");
        return;
    }

    V8EventInit::toImpl(isolate, v8Value, impl, exceptionState);
    if (exceptionState.hadException())
        return;

    v8::TryCatch block(isolate);
    v8::Local<v8::Object> v8Object;
    if (!v8Call(v8Value->ToObject(isolate->GetCurrentContext()), v8Object, block)) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }
    {
        v8::Local<v8::Value> relatedTargetValue;
        if (!v8Object->Get(isolate->GetCurrentContext(), v8String(isolate, "relatedTarget")).ToLocal(&relatedTargetValue)) {
            exceptionState.rethrowV8Exception(block.Exception());
            return;
        }
        if (relatedTargetValue.IsEmpty() || relatedTargetValue->IsUndefined()) {
            // Do nothing.
        } else if (relatedTargetValue->IsNull()) {
            impl.setRelatedTargetToNull();
        } else {
            EventTarget* relatedTarget = toEventTarget(isolate, relatedTargetValue);
            if (!relatedTarget && !relatedTargetValue->IsNull()) {
                exceptionState.throwTypeError("member relatedTarget is not of type EventTarget.");
                return;
            }
            impl.setRelatedTarget(relatedTarget);
        }
    }

}

v8::Local<v8::Value> toV8(const RelatedEventInit& impl, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
{
    v8::Local<v8::Object> v8Object = v8::Object::New(isolate);
    if (!toV8EventInit(impl, v8Object, creationContext, isolate))
        return v8::Local<v8::Value>();
    if (!toV8RelatedEventInit(impl, v8Object, creationContext, isolate))
        return v8::Local<v8::Value>();
    return v8Object;
}

bool toV8RelatedEventInit(const RelatedEventInit& impl, v8::Local<v8::Object> dictionary, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (impl.hasRelatedTarget()) {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "relatedTarget"), toV8(impl.relatedTarget(), creationContext, isolate))))
            return false;
    }

    return true;
}

RelatedEventInit NativeValueTraits<RelatedEventInit>::nativeValue(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptionState)
{
    RelatedEventInit impl;
    V8RelatedEventInit::toImpl(isolate, value, impl, exceptionState);
    return impl;
}

} // namespace blink
