| 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 {% if members %} |
| 14 static const v8::Eternal<v8::Name>* eternal{{v8_class}}Keys(v8::Isolate* isolate
) { |
| 15 static const char* const kKeys[] = { |
| 16 {% for member in members %} |
| 17 "{{member.name}}", |
| 18 {% endfor %} |
| 19 }; |
| 20 return V8PerIsolateData::from(isolate)->findOrCreateEternalNameCache( |
| 21 kKeys, kKeys, WTF_ARRAY_LENGTH(kKeys)); |
| 22 } |
| 23 {% endif %} |
| 24 |
| 13 {% from 'utilities.cpp.tmpl' import v8_value_to_local_cpp_value %} | 25 {% 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) { | 26 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{
cpp_class}}& impl, ExceptionState& exceptionState) { |
| 15 if (isUndefinedOrNull(v8Value)) { | 27 if (isUndefinedOrNull(v8Value)) { |
| 16 {% if required_member_names %} | 28 {% if required_member_names %} |
| 17 exceptionState.throwTypeError("Missing required member(s): {{required_member
_names|join(', ')}}."); | 29 exceptionState.throwTypeError("Missing required member(s): {{required_member
_names|join(', ')}}."); |
| 18 {% endif %} | 30 {% endif %} |
| 19 return; | 31 return; |
| 20 } | 32 } |
| 21 if (!v8Value->IsObject()) { | 33 if (!v8Value->IsObject()) { |
| 22 {% if use_permissive_dictionary_conversion %} | 34 {% if use_permissive_dictionary_conversion %} |
| 23 // Do nothing. | 35 // Do nothing. |
| 24 return; | 36 return; |
| 25 {% else %} | 37 {% else %} |
| 26 exceptionState.throwTypeError("cannot convert to dictionary."); | 38 exceptionState.throwTypeError("cannot convert to dictionary."); |
| 27 return; | 39 return; |
| 28 {% endif %} | 40 {% endif %} |
| 29 } | 41 } |
| 30 v8::Local<v8::Object> v8Object = v8Value.As<v8::Object>(); | 42 v8::Local<v8::Object> v8Object = v8Value.As<v8::Object>(); |
| 31 ALLOW_UNUSED_LOCAL(v8Object); | 43 ALLOW_UNUSED_LOCAL(v8Object); |
| 32 | 44 |
| 33 {% if parent_v8_class %} | 45 {% if parent_v8_class %} |
| 34 {{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState); | 46 {{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState); |
| 35 if (exceptionState.hadException()) | 47 if (exceptionState.hadException()) |
| 36 return; | 48 return; |
| 37 | 49 |
| 38 {% endif %} | 50 {% endif %} |
| 39 {# Declare local variables only when the dictionary has members to avoid unuse
d variable warnings. #} | 51 {# Declare local variables only when the dictionary has members to avoid unuse
d variable warnings. #} |
| 40 {% if members %} | 52 {% if members %} |
| 53 const v8::Eternal<v8::Name>* keys = eternal{{v8_class}}Keys(isolate); |
| 41 v8::TryCatch block(isolate); | 54 v8::TryCatch block(isolate); |
| 55 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 42 {% endif %} | 56 {% endif %} |
| 43 {% for member in members %} | 57 {% for member in members %} |
| 44 {% filter runtime_enabled(member.runtime_enabled_feature_name) %} | 58 {% filter runtime_enabled(member.runtime_enabled_feature_name) %} |
| 45 v8::Local<v8::Value> {{member.name}}Value; | 59 v8::Local<v8::Value> {{member.name}}Value; |
| 46 if (!v8Object->Get(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{me
mber.name}}")).ToLocal(&{{member.name}}Value)) { | 60 if (!v8Object->Get(context, keys[{{loop.index0}}].Get(isolate)).ToLocal(&{{mem
ber.name}}Value)) { |
| 47 exceptionState.rethrowV8Exception(block.Exception()); | 61 exceptionState.rethrowV8Exception(block.Exception()); |
| 48 return; | 62 return; |
| 49 } | 63 } |
| 50 if ({{member.name}}Value.IsEmpty() || {{member.name}}Value->IsUndefined()) { | 64 if ({{member.name}}Value.IsEmpty() || {{member.name}}Value->IsUndefined()) { |
| 51 {% if member.is_required %} | 65 {% if member.is_required %} |
| 52 exceptionState.throwTypeError("required member {{member.name}} is undefined.
"); | 66 exceptionState.throwTypeError("required member {{member.name}} is undefined.
"); |
| 53 return; | 67 return; |
| 54 {% else %} | 68 {% else %} |
| 55 // Do nothing. | 69 // Do nothing. |
| 56 {% endif %} | 70 {% endif %} |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return v8::Undefined(isolate); | 106 return v8::Undefined(isolate); |
| 93 return v8Object; | 107 return v8Object; |
| 94 } | 108 } |
| 95 | 109 |
| 96 bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona
ry, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) { | 110 bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona
ry, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) { |
| 97 {% if parent_v8_class %} | 111 {% if parent_v8_class %} |
| 98 if (!toV8{{parent_cpp_class}}(impl, dictionary, creationContext, isolate)) | 112 if (!toV8{{parent_cpp_class}}(impl, dictionary, creationContext, isolate)) |
| 99 return false; | 113 return false; |
| 100 | 114 |
| 101 {% endif %} | 115 {% endif %} |
| 116 {% if members %} |
| 117 const v8::Eternal<v8::Name>* keys = eternal{{v8_class}}Keys(isolate); |
| 118 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 119 {% endif %} |
| 102 {% for member in members %} | 120 {% for member in members %} |
| 103 v8::Local<v8::Value> {{member.name}}Value; | 121 v8::Local<v8::Value> {{member.name}}Value; |
| 104 bool {{member.name}}HasValueOrDefault = false; | 122 bool {{member.name}}HasValueOrDefault = false; |
| 105 if (impl.{{member.has_method_name}}()) { | 123 if (impl.{{member.has_method_name}}()) { |
| 106 {% if member.is_object %} | 124 {% if member.is_object %} |
| 107 DCHECK(impl.{{member.getter_name}}().isObject()); | 125 DCHECK(impl.{{member.getter_name}}().isObject()); |
| 108 {% endif %} | 126 {% endif %} |
| 109 {{member.name}}Value = {{member.cpp_value_to_v8_value}}; | 127 {{member.name}}Value = {{member.cpp_value_to_v8_value}}; |
| 110 {{member.name}}HasValueOrDefault = true; | 128 {{member.name}}HasValueOrDefault = true; |
| 111 {% if member.v8_default_value %} | 129 {% if member.v8_default_value %} |
| 112 } else { | 130 } else { |
| 113 {{member.name}}Value = {{member.v8_default_value}}; | 131 {{member.name}}Value = {{member.v8_default_value}}; |
| 114 {{member.name}}HasValueOrDefault = true; | 132 {{member.name}}HasValueOrDefault = true; |
| 115 {% elif member.is_nullable %} | 133 {% elif member.is_nullable %} |
| 116 } else { | 134 } else { |
| 117 {{member.name}}Value = v8::Null(isolate); | 135 {{member.name}}Value = v8::Null(isolate); |
| 118 {{member.name}}HasValueOrDefault = true; | 136 {{member.name}}HasValueOrDefault = true; |
| 119 {% elif member.is_required %} | 137 {% elif member.is_required %} |
| 120 } else { | 138 } else { |
| 121 NOTREACHED(); | 139 NOTREACHED(); |
| 122 {% endif %} | 140 {% endif %} |
| 123 } | 141 } |
| 124 {# The HasValueOrDefault variable will be optimized out. | 142 {# The HasValueOrDefault variable will be optimized out. |
| 125 If there is a default value, the compiler will notice that all branches set
it to true. | 143 If there is a default value, the compiler will notice that all branches set
it to true. |
| 126 If there is not, then the compiler will inline this call into the only bran
ch that sets it to true. | 144 If there is not, then the compiler will inline this call into the only bran
ch that sets it to true. |
| 127 Either way, the code is efficient and the variable is completely elided. #} | 145 Either way, the code is efficient and the variable is completely elided. #} |
| 128 if ({{member.name}}HasValueOrDefault && | 146 if ({{member.name}}HasValueOrDefault && |
| 129 !v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext()
, v8AtomicString(isolate, "{{member.name}}"), {{member.name}}Value))) { | 147 !v8CallBoolean(dictionary->CreateDataProperty(context, keys[{{loop.index0}
}].Get(isolate), {{member.name}}Value))) { |
| 130 return false; | 148 return false; |
| 131 } | 149 } |
| 132 | 150 |
| 133 {% endfor %} | 151 {% endfor %} |
| 134 return true; | 152 return true; |
| 135 } | 153 } |
| 136 | 154 |
| 137 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate
, v8::Local<v8::Value> value, ExceptionState& exceptionState) { | 155 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate
, v8::Local<v8::Value> value, ExceptionState& exceptionState) { |
| 138 {{cpp_class}} impl; | 156 {{cpp_class}} impl; |
| 139 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); | 157 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); |
| 140 return impl; | 158 return impl; |
| 141 } | 159 } |
| 142 | 160 |
| 143 } // namespace blink | 161 } // namespace blink |
| 144 | 162 |
| 145 {% endfilter %}{# format_blink_cpp_source_code #} | 163 {% endfilter %}{# format_blink_cpp_source_code #} |
| OLD | NEW |