<reponame>wenfeifei/miniblink49<filename>gen/blink/bindings/modules/v8/V8MediaEncryptedEventInit.cpp
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

#include "config.h"
#include "V8MediaEncryptedEventInit.h"

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

namespace blink {

void V8MediaEncryptedEventInit::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, MediaEncryptedEventInit& 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;
    v8::Local<v8::Object> v8Object;
    if (!v8Call(v8Value->ToObject(isolate->GetCurrentContext()), v8Object, block)) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }
    {
        v8::Local<v8::Value> initDataValue;
        if (!v8Object->Get(isolate->GetCurrentContext(), v8String(isolate, "initData")).ToLocal(&initDataValue)) {
            exceptionState.rethrowV8Exception(block.Exception());
            return;
        }
        if (initDataValue.IsEmpty() || initDataValue->IsUndefined()) {
            // Do nothing.
        } else if (initDataValue->IsNull()) {
            impl.setInitDataToNull();
        } else {
            DOMArrayBuffer* initData = initDataValue->IsArrayBuffer() ? V8ArrayBuffer::toImpl(v8::Local<v8::ArrayBuffer>::Cast(initDataValue)) : 0;
            if (!initData && !initDataValue->IsNull()) {
                exceptionState.throwTypeError("member initData is not of type ArrayBuffer.");
                return;
            }
            impl.setInitData(initData);
        }
    }

    {
        v8::Local<v8::Value> initDataTypeValue;
        if (!v8Object->Get(isolate->GetCurrentContext(), v8String(isolate, "initDataType")).ToLocal(&initDataTypeValue)) {
            exceptionState.rethrowV8Exception(block.Exception());
            return;
        }
        if (initDataTypeValue.IsEmpty() || initDataTypeValue->IsUndefined()) {
            // Do nothing.
        } else {
            V8StringResource<> initDataType = initDataTypeValue;
            if (!initDataType.prepare(exceptionState))
                return;
            impl.setInitDataType(initDataType);
        }
    }

}

v8::Local<v8::Value> toV8(const MediaEncryptedEventInit& 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 (!toV8MediaEncryptedEventInit(impl, v8Object, creationContext, isolate))
        return v8::Local<v8::Value>();
    return v8Object;
}

bool toV8MediaEncryptedEventInit(const MediaEncryptedEventInit& impl, v8::Local<v8::Object> dictionary, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (impl.hasInitData()) {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "initData"), toV8(impl.initData(), creationContext, isolate))))
            return false;
    } else {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "initData"), v8::Null(isolate))))
            return false;
    }

    if (impl.hasInitDataType()) {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "initDataType"), v8String(isolate, impl.initDataType()))))
            return false;
    } else {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "initDataType"), v8String(isolate, String("")))))
            return false;
    }

    return true;
}

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

} // namespace blink
