| OLD | NEW |
| 1 {% filter format_blink_cpp_source_code %} | 1 {% filter format_blink_cpp_source_code %} |
| 2 | 2 |
| 3 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable %} | 3 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable %} |
| 4 {% include 'copyright_block.txt' %} | 4 {% include 'copyright_block.txt' %} |
| 5 #include "{{v8_original_class}}.h" | 5 #include "{{v8_original_class}}.h" |
| 6 | 6 |
| 7 {% for filename in cpp_includes if filename != '%s.h' % v8_class %} | 7 {% for filename in cpp_includes if filename != '%s.h' % v8_class %} |
| 8 #include "{{filename}}" | 8 #include "{{filename}}" |
| 9 {% endfor %} | 9 {% endfor %} |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 {% from 'utilities.cpp.tmpl' import v8_value_to_local_cpp_value %} | 13 {% from 'utilities.cpp.tmpl' import v8_value_to_local_cpp_value %} |
| 14 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{
cpp_class}}& impl, ExceptionState& exceptionState) | 14 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{
cpp_class}}& impl, ExceptionState& exceptionState) { |
| 15 { | 15 if (isUndefinedOrNull(v8Value)) { |
| 16 if (isUndefinedOrNull(v8Value)) { | 16 {% if required_member_names %} |
| 17 {% if required_member_names %} | 17 exceptionState.throwTypeError("Missing required member(s): {{required_member
_names|join(', ')}}."); |
| 18 exceptionState.throwTypeError("Missing required member(s): {{required_me
mber_names|join(', ')}}."); | 18 {% endif %} |
| 19 {% endif %} | 19 return; |
| 20 return; | 20 } |
| 21 } | 21 if (!v8Value->IsObject()) { |
| 22 if (!v8Value->IsObject()) { | 22 {% if use_permissive_dictionary_conversion %} |
| 23 {% if use_permissive_dictionary_conversion %} | 23 // Do nothing. |
| 24 // Do nothing. | 24 return; |
| 25 return; | 25 {% else %} |
| 26 {% else %} | 26 exceptionState.throwTypeError("cannot convert to dictionary."); |
| 27 exceptionState.throwTypeError("cannot convert to dictionary."); | 27 return; |
| 28 return; | 28 {% endif %} |
| 29 {% endif %} | 29 } |
| 30 } | |
| 31 | 30 |
| 32 {% if parent_v8_class %} | 31 {% if parent_v8_class %} |
| 33 {{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState); | 32 {{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState); |
| 34 if (exceptionState.hadException()) | 33 if (exceptionState.hadException()) |
| 35 return; | 34 return; |
| 36 | 35 |
| 36 {% endif %} |
| 37 {# Declare local variables only when the dictionary has members to avoid unuse
d variable warnings. #} |
| 38 {% if members %} |
| 39 v8::TryCatch block(isolate); |
| 40 v8::Local<v8::Object> v8Object; |
| 41 if (!v8Call(v8Value->ToObject(isolate->GetCurrentContext()), v8Object, block))
{ |
| 42 exceptionState.rethrowV8Exception(block.Exception()); |
| 43 return; |
| 44 } |
| 45 {% endif %} |
| 46 {% for member in members %} |
| 47 {% filter runtime_enabled(member.runtime_enabled_function) %} |
| 48 v8::Local<v8::Value> {{member.name}}Value; |
| 49 if (!v8Object->Get(isolate->GetCurrentContext(), v8String(isolate, "{{member.n
ame}}")).ToLocal(&{{member.name}}Value)) { |
| 50 exceptionState.rethrowV8Exception(block.Exception()); |
| 51 return; |
| 52 } |
| 53 if ({{member.name}}Value.IsEmpty() || {{member.name}}Value->IsUndefined()) { |
| 54 {% if member.is_required %} |
| 55 exceptionState.throwTypeError("required member {{member.name}} is undefined.
"); |
| 56 return; |
| 57 {% else %} |
| 58 // Do nothing. |
| 37 {% endif %} | 59 {% endif %} |
| 38 {# Declare local variables only when the dictionary has members to avoid unu
sed variable warnings. #} | 60 {% if member.is_nullable %} |
| 39 {% if members %} | 61 } else if ({{member.name}}Value->IsNull()) { |
| 40 v8::TryCatch block(isolate); | 62 impl.{{member.null_setter_name}}(); |
| 41 v8::Local<v8::Object> v8Object; | 63 {% endif %} |
| 42 if (!v8Call(v8Value->ToObject(isolate->GetCurrentContext()), v8Object, block
)) { | 64 } else { |
| 43 exceptionState.rethrowV8Exception(block.Exception()); | 65 {% if member.deprecate_as %} |
| 44 return; | 66 Deprecation::countDeprecationIfNotPrivateScript(isolate, currentExecutionCon
text(isolate), UseCounter::{{member.deprecate_as}}); |
| 67 {% endif %} |
| 68 {{v8_value_to_local_cpp_value(member) | indent}} |
| 69 {% if member.is_interface_type %} |
| 70 if (!{{member.name}}) { |
| 71 exceptionState.throwTypeError("member {{member.name}} is not of type {{mem
ber.idl_type}}."); |
| 72 return; |
| 45 } | 73 } |
| 46 {% endif %} | 74 {% endif %} |
| 47 {% for member in members %} | 75 {% if member.enum_values %} |
| 48 {% filter runtime_enabled(member.runtime_enabled_function) %} | 76 {{declare_enum_validation_variable(member.enum_values) | indent}} |
| 49 v8::Local<v8::Value> {{member.name}}Value; | 77 if (!isValidEnum({{member.name}}, validValues, WTF_ARRAY_LENGTH(validValues)
, "{{member.enum_type}}", exceptionState)) |
| 50 if (!v8Object->Get(isolate->GetCurrentContext(), v8String(isolate, "{{member
.name}}")).ToLocal(&{{member.name}}Value)) { | 78 return; |
| 51 exceptionState.rethrowV8Exception(block.Exception()); | 79 {% elif member.is_object %} |
| 52 return; | 80 if (!{{member.name}}.isObject()) { |
| 81 exceptionState.throwTypeError("member {{member.name}} is not an object."); |
| 82 return; |
| 53 } | 83 } |
| 54 if ({{member.name}}Value.IsEmpty() || {{member.name}}Value->IsUndefined()) { | |
| 55 {% if member.is_required %} | |
| 56 exceptionState.throwTypeError("required member {{member.name}} is undefi
ned."); | |
| 57 return; | |
| 58 {% else %} | |
| 59 // Do nothing. | |
| 60 {% endif %} | |
| 61 {% if member.is_nullable %} | |
| 62 } else if ({{member.name}}Value->IsNull()) { | |
| 63 impl.{{member.null_setter_name}}(); | |
| 64 {% endif %} | 84 {% endif %} |
| 65 } else { | 85 impl.{{member.setter_name}}({{member.name}}); |
| 66 {% if member.deprecate_as %} | 86 } |
| 67 Deprecation::countDeprecationIfNotPrivateScript(isolate, currentExecutio
nContext(isolate), UseCounter::{{member.deprecate_as}}); | 87 {% endfilter %} |
| 68 {% endif %} | |
| 69 {{v8_value_to_local_cpp_value(member) | indent(8)}} | |
| 70 {% if member.is_interface_type %} | |
| 71 if (!{{member.name}}) { | |
| 72 exceptionState.throwTypeError("member {{member.name}} is not of type
{{member.idl_type}}."); | |
| 73 return; | |
| 74 } | |
| 75 {% endif %} | |
| 76 {% if member.enum_values %} | |
| 77 {{declare_enum_validation_variable(member.enum_values) | indent(8)}} | |
| 78 if (!isValidEnum({{member.name}}, validValues, WTF_ARRAY_LENGTH(validVal
ues), "{{member.enum_type}}", exceptionState)) | |
| 79 return; | |
| 80 {% elif member.is_object %} | |
| 81 if (!{{member.name}}.isObject()) { | |
| 82 exceptionState.throwTypeError("member {{member.name}} is not an obje
ct."); | |
| 83 return; | |
| 84 } | |
| 85 {% endif %} | |
| 86 impl.{{member.setter_name}}({{member.name}}); | |
| 87 } | |
| 88 {% endfilter %} | |
| 89 | 88 |
| 90 {% endfor %} | 89 {% endfor %} |
| 91 } | 90 } |
| 92 | 91 |
| 93 v8::Local<v8::Value> {{cpp_class}}::toV8Impl(v8::Local<v8::Object> creationConte
xt, v8::Isolate* isolate) const | 92 v8::Local<v8::Value> {{cpp_class}}::toV8Impl(v8::Local<v8::Object> creationConte
xt, v8::Isolate* isolate) const { |
| 94 { | 93 v8::Local<v8::Object> v8Object = v8::Object::New(isolate); |
| 95 v8::Local<v8::Object> v8Object = v8::Object::New(isolate); | 94 if (!toV8{{cpp_class}}(*this, v8Object, creationContext, isolate)) |
| 96 if (!toV8{{cpp_class}}(*this, v8Object, creationContext, isolate)) | 95 return v8::Undefined(isolate); |
| 97 return v8::Undefined(isolate); | 96 return v8Object; |
| 98 return v8Object; | |
| 99 } | 97 } |
| 100 | 98 |
| 101 bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona
ry, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) | 99 bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona
ry, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) { |
| 102 { | 100 {% if parent_v8_class %} |
| 103 {% if parent_v8_class %} | 101 if (!toV8{{parent_cpp_class}}(impl, dictionary, creationContext, isolate)) |
| 104 if (!toV8{{parent_cpp_class}}(impl, dictionary, creationContext, isolate)) | 102 return false; |
| 105 return false; | |
| 106 | 103 |
| 104 {% endif %} |
| 105 {% for member in members %} |
| 106 if (impl.{{member.has_method_name}}()) { |
| 107 {% if member.is_object %} |
| 108 DCHECK(impl.{{member.cpp_name}}().isObject()); |
| 107 {% endif %} | 109 {% endif %} |
| 108 {% for member in members %} | 110 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext
(), v8String(isolate, "{{member.name}}"), {{member.cpp_value_to_v8_value}}))) |
| 109 if (impl.{{member.has_method_name}}()) { | 111 return false; |
| 110 {% if member.is_object %} | 112 {% if member.v8_default_value %} |
| 111 ASSERT(impl.{{member.cpp_name}}().isObject()); | 113 } else { |
| 112 {% endif %} | 114 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext
(), v8String(isolate, "{{member.name}}"), {{member.v8_default_value}}))) |
| 113 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentCon
text(), v8String(isolate, "{{member.name}}"), {{member.cpp_value_to_v8_value}}))
) | 115 return false; |
| 114 return false; | 116 {% elif member.is_nullable %} |
| 115 {% if member.v8_default_value %} | 117 } else { |
| 116 } else { | 118 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext
(), v8String(isolate, "{{member.name}}"), v8::Null(isolate)))) |
| 117 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentCon
text(), v8String(isolate, "{{member.name}}"), {{member.v8_default_value}}))) | 119 return false; |
| 118 return false; | 120 {% elif member.is_required %} |
| 119 {% elif member.is_nullable %} | 121 } else { |
| 120 } else { | 122 NOTREACHED(); |
| 121 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentCon
text(), v8String(isolate, "{{member.name}}"), v8::Null(isolate)))) | 123 {% endif %} |
| 122 return false; | 124 } |
| 123 {% elif member.is_required %} | |
| 124 } else { | |
| 125 ASSERT_NOT_REACHED(); | |
| 126 {% endif %} | |
| 127 } | |
| 128 | 125 |
| 129 {% endfor %} | 126 {% endfor %} |
| 130 return true; | 127 return true; |
| 131 } | 128 } |
| 132 | 129 |
| 133 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate
, v8::Local<v8::Value> value, ExceptionState& exceptionState) | 130 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate
, v8::Local<v8::Value> value, ExceptionState& exceptionState) { |
| 134 { | 131 {{cpp_class}} impl; |
| 135 {{cpp_class}} impl; | 132 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); |
| 136 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); | 133 return impl; |
| 137 return impl; | |
| 138 } | 134 } |
| 139 | 135 |
| 140 } // namespace blink | 136 } // namespace blink |
| 141 | 137 |
| 142 {% endfilter %}{# format_blink_cpp_source_code #} | 138 {% endfilter %}{# format_blink_cpp_source_code #} |
| OLD | NEW |