1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
// 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}}. DO NOT MODIFY!
#include "config.h"
#include "{{v8_original_class}}.h"
{% for filename in cpp_includes if filename != '%s.h' % v8_class %}
#include "{{filename}}"
{% endfor %}
namespace blink {
{% macro convert_and_set_member(member) %}
{% endmacro %}
void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{cpp_class}}& impl, ExceptionState& exceptionState)
{
if (isUndefinedOrNull(v8Value))
return;
if (!v8Value->IsObject()) {
{% if use_permissive_dictionary_conversion %}
// Do nothing.
{% else %}
exceptionState.throwTypeError("cannot convert to dictionary.");
{% endif %}
return;
}
{% if parent_v8_class %}
{{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState);
if (exceptionState.hadException())
return;
{% endif %}
{# Declare local variables only when the dictionary has members to avoid unused variable warnings. #}
{% if members %}
v8::Local<v8::Object> v8Object = v8Value->ToObject(isolate);
v8::TryCatch block;
{% endif %}
{% for member in members %}
v8::Local<v8::Value> {{member.name}}Value = v8Object->Get(v8String(isolate, "{{member.name}}"));
if (block.HasCaught()) {
exceptionState.rethrowV8Exception(block.Exception());
return;
}
if ({{member.name}}Value.IsEmpty() || {{member.name}}Value->IsUndefined()) {
// Do nothing.
{% if member.is_nullable %}
} else if ({{member.name}}Value->IsNull()) {
impl.{{member.null_setter_name}}();
{% endif %}
} else {
{% if member.deprecate_as %}
UseCounter::countDeprecationIfNotPrivateScript(isolate, callingExecutionContext(isolate), UseCounter::{{member.deprecate_as}});
{% endif %}
{% if member.use_output_parameter_for_result %}
{{member.cpp_type}} {{member.name}};
{% endif %}
{{member.v8_value_to_local_cpp_value}};
{% if member.is_interface_type %}
if (!{{member.name}} && !{{member.name}}Value->IsNull()) {
exceptionState.throwTypeError("member {{member.name}} is not of type {{member.idl_type}}.");
return;
}
{% endif %}
{% if member.enum_validation_expression %}
String string = {{member.name}};
if (!({{member.enum_validation_expression}})) {
exceptionState.throwTypeError("member {{member.name}} ('" + string + "') is not a valid enum value.");
return;
}
{% elif member.is_object %}
if (!{{member.name}}.isObject()) {
exceptionState.throwTypeError("member {{member.name}} is not an object.");
return;
}
{% endif %}
impl.{{member.setter_name}}({{member.name}});
}
{% endfor %}
}
v8::Local<v8::Value> toV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
{
v8::Local<v8::Object> v8Object = v8::Object::New(isolate);
{% if parent_v8_class %}
toV8{{parent_cpp_class}}(impl, v8Object, creationContext, isolate);
{% endif %}
toV8{{cpp_class}}(impl, v8Object, creationContext, isolate);
return v8Object;
}
void toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictionary, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
{
{% for member in members %}
if (impl.{{member.has_method_name}}()) {
{% if member.is_object %}
ASSERT(impl.{{member.cpp_name}}().isObject());
{% endif %}
dictionary->Set(v8String(isolate, "{{member.name}}"), {{member.cpp_value_to_v8_value}});
{% if member.v8_default_value %}
} else {
dictionary->Set(v8String(isolate, "{{member.name}}"), {{member.v8_default_value}});
{% endif %}
}
{% endfor %}
}
{{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(const v8::Local<v8::Value>& value, v8::Isolate* isolate, ExceptionState& exceptionState)
{
{{cpp_class}} impl;
{{v8_class}}::toImpl(isolate, value, impl, exceptionState);
return impl;
}
} // namespace blink
|