| 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 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 return v8Object; | 93 return v8Object; |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona
ry, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) { | 96 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 %} | 97 {% if parent_v8_class %} |
| 98 if (!toV8{{parent_cpp_class}}(impl, dictionary, creationContext, isolate)) | 98 if (!toV8{{parent_cpp_class}}(impl, dictionary, creationContext, isolate)) |
| 99 return false; | 99 return false; |
| 100 | 100 |
| 101 {% endif %} | 101 {% endif %} |
| 102 {% for member in members %} | 102 {% for member in members %} |
| 103 v8::Local<v8::Value> {{member.name}}Value; |
| 104 bool {{member.name}}HasValueOrDefault = false; |
| 103 if (impl.{{member.has_method_name}}()) { | 105 if (impl.{{member.has_method_name}}()) { |
| 104 {% if member.is_object %} | 106 {% if member.is_object %} |
| 105 DCHECK(impl.{{member.getter_name}}().isObject()); | 107 DCHECK(impl.{{member.getter_name}}().isObject()); |
| 106 {% endif %} | 108 {% endif %} |
| 107 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext
(), v8AtomicString(isolate, "{{member.name}}"), {{member.cpp_value_to_v8_value}}
))) | 109 {{member.name}}Value = {{member.cpp_value_to_v8_value}}; |
| 108 return false; | 110 {{member.name}}HasValueOrDefault = true; |
| 109 {% if member.v8_default_value %} | 111 {% if member.v8_default_value %} |
| 110 } else { | 112 } else { |
| 111 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext
(), v8AtomicString(isolate, "{{member.name}}"), {{member.v8_default_value}}))) | 113 {{member.name}}Value = {{member.v8_default_value}}; |
| 112 return false; | 114 {{member.name}}HasValueOrDefault = true; |
| 113 {% elif member.is_nullable %} | 115 {% elif member.is_nullable %} |
| 114 } else { | 116 } else { |
| 115 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext
(), v8AtomicString(isolate, "{{member.name}}"), v8::Null(isolate)))) | 117 {{member.name}}Value = v8::Null(isolate); |
| 116 return false; | 118 {{member.name}}HasValueOrDefault = true; |
| 117 {% elif member.is_required %} | 119 {% elif member.is_required %} |
| 118 } else { | 120 } else { |
| 119 NOTREACHED(); | 121 NOTREACHED(); |
| 120 {% endif %} | 122 {% endif %} |
| 121 } | 123 } |
| 124 {# 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. |
| 126 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. #} |
| 128 if ({{member.name}}HasValueOrDefault && |
| 129 !v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext()
, v8AtomicString(isolate, "{{member.name}}"), {{member.name}}Value))) { |
| 130 return false; |
| 131 } |
| 122 | 132 |
| 123 {% endfor %} | 133 {% endfor %} |
| 124 return true; | 134 return true; |
| 125 } | 135 } |
| 126 | 136 |
| 127 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate
, v8::Local<v8::Value> value, ExceptionState& exceptionState) { | 137 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate
, v8::Local<v8::Value> value, ExceptionState& exceptionState) { |
| 128 {{cpp_class}} impl; | 138 {{cpp_class}} impl; |
| 129 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); | 139 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); |
| 130 return impl; | 140 return impl; |
| 131 } | 141 } |
| 132 | 142 |
| 133 } // namespace blink | 143 } // namespace blink |
| 134 | 144 |
| 135 {% endfilter %}{# format_blink_cpp_source_code #} | 145 {% endfilter %}{# format_blink_cpp_source_code #} |
| OLD | NEW |