OLD | NEW |
1 {% from 'utilities.cpp' import declare_enum_validation_variable %} | 1 {% from 'utilities.cpp' import declare_enum_validation_variable %} |
2 {% include 'copyright_block.txt' %} | 2 {% include 'copyright_block.txt' %} |
3 #include "{{v8_original_class}}.h" | 3 #include "{{v8_original_class}}.h" |
4 | 4 |
5 {% for filename in cpp_includes if filename != '%s.h' % v8_class %} | 5 {% for filename in cpp_includes if filename != '%s.h' % v8_class %} |
6 #include "{{filename}}" | 6 #include "{{filename}}" |
7 {% endfor %} | 7 {% endfor %} |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 {# Declare local variables only when the dictionary has members to avoid unu
sed variable warnings. #} | 36 {# Declare local variables only when the dictionary has members to avoid unu
sed variable warnings. #} |
37 {% if members %} | 37 {% if members %} |
38 v8::TryCatch block(isolate); | 38 v8::TryCatch block(isolate); |
39 v8::Local<v8::Object> v8Object; | 39 v8::Local<v8::Object> v8Object; |
40 if (!v8Call(v8Value->ToObject(isolate->GetCurrentContext()), v8Object, block
)) { | 40 if (!v8Call(v8Value->ToObject(isolate->GetCurrentContext()), v8Object, block
)) { |
41 exceptionState.rethrowV8Exception(block.Exception()); | 41 exceptionState.rethrowV8Exception(block.Exception()); |
42 return; | 42 return; |
43 } | 43 } |
44 {% endif %} | 44 {% endif %} |
45 {% for member in members %} | 45 {% for member in members %} |
46 {% if member.runtime_enabled_function %} | 46 {% filter runtime_enabled(member.runtime_enabled_function) %} |
47 if ({{member.runtime_enabled_function}}()) { | 47 v8::Local<v8::Value> {{member.name}}Value; |
48 {% else %} | 48 if (!v8Object->Get(isolate->GetCurrentContext(), v8String(isolate, "{{member
.name}}")).ToLocal(&{{member.name}}Value)) { |
49 { | 49 exceptionState.rethrowV8Exception(block.Exception()); |
| 50 return; |
| 51 } |
| 52 if ({{member.name}}Value.IsEmpty() || {{member.name}}Value->IsUndefined()) { |
| 53 {% if member.is_required %} |
| 54 exceptionState.throwTypeError("required member {{member.name}} is undefi
ned."); |
| 55 return; |
| 56 {% else %} |
| 57 // Do nothing. |
| 58 {% endif %} |
| 59 {% if member.is_nullable %} |
| 60 } else if ({{member.name}}Value->IsNull()) { |
| 61 impl.{{member.null_setter_name}}(); |
50 {% endif %} | 62 {% endif %} |
51 v8::Local<v8::Value> {{member.name}}Value; | 63 } else { |
52 if (!v8Object->Get(isolate->GetCurrentContext(), v8String(isolate, "{{me
mber.name}}")).ToLocal(&{{member.name}}Value)) { | 64 {% if member.deprecate_as %} |
53 exceptionState.rethrowV8Exception(block.Exception()); | 65 Deprecation::countDeprecationIfNotPrivateScript(isolate, currentExecutio
nContext(isolate), UseCounter::{{member.deprecate_as}}); |
| 66 {% endif %} |
| 67 {{v8_value_to_local_cpp_value(member) | indent(8)}} |
| 68 {% if member.is_interface_type %} |
| 69 if (!{{member.name}} && !{{member.name}}Value->IsNull()) { |
| 70 exceptionState.throwTypeError("member {{member.name}} is not of type
{{member.idl_type}}."); |
54 return; | 71 return; |
55 } | 72 } |
56 if ({{member.name}}Value.IsEmpty() || {{member.name}}Value->IsUndefined(
)) { | 73 {% endif %} |
57 {% if member.is_required %} | 74 {% if member.enum_values %} |
58 exceptionState.throwTypeError("required member {{member.name}} is un
defined."); | 75 {{declare_enum_validation_variable(member.enum_values) | indent(8)}} |
| 76 if (!isValidEnum({{member.name}}, validValues, WTF_ARRAY_LENGTH(validVal
ues), "{{member.enum_type}}", exceptionState)) |
59 return; | 77 return; |
60 {% else %} | 78 {% elif member.is_object %} |
61 // Do nothing. | 79 if (!{{member.name}}.isObject()) { |
62 {% endif %} | 80 exceptionState.throwTypeError("member {{member.name}} is not an obje
ct."); |
63 {% if member.is_nullable %} | 81 return; |
64 } else if ({{member.name}}Value->IsNull()) { | 82 } |
65 impl.{{member.null_setter_name}}(); | |
66 {% endif %} | 83 {% endif %} |
67 } else { | 84 impl.{{member.setter_name}}({{member.name}}); |
68 {% if member.deprecate_as %} | |
69 Deprecation::countDeprecationIfNotPrivateScript(isolate, currentExec
utionContext(isolate), UseCounter::{{member.deprecate_as}}); | |
70 {% endif %} | |
71 {{v8_value_to_local_cpp_value(member) | indent(12)}} | |
72 {% if member.is_interface_type %} | |
73 if (!{{member.name}} && !{{member.name}}Value->IsNull()) { | |
74 exceptionState.throwTypeError("member {{member.name}} is not of
type {{member.idl_type}}."); | |
75 return; | |
76 } | |
77 {% endif %} | |
78 {% if member.enum_values %} | |
79 {{declare_enum_validation_variable(member.enum_values) | indent(12)}
} | |
80 if (!isValidEnum({{member.name}}, validValues, WTF_ARRAY_LENGTH(vali
dValues), "{{member.enum_type}}", exceptionState)) | |
81 return; | |
82 {% elif member.is_object %} | |
83 if (!{{member.name}}.isObject()) { | |
84 exceptionState.throwTypeError("member {{member.name}} is not an
object."); | |
85 return; | |
86 } | |
87 {% endif %} | |
88 impl.{{member.setter_name}}({{member.name}}); | |
89 } | |
90 } | 85 } |
| 86 {% endfilter %} |
91 | 87 |
92 {% endfor %} | 88 {% endfor %} |
93 } | 89 } |
94 | 90 |
95 v8::Local<v8::Value> toV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creat
ionContext, v8::Isolate* isolate) | 91 v8::Local<v8::Value> toV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creat
ionContext, v8::Isolate* isolate) |
96 { | 92 { |
97 v8::Local<v8::Object> v8Object = v8::Object::New(isolate); | 93 v8::Local<v8::Object> v8Object = v8::Object::New(isolate); |
98 {% if parent_v8_class %} | 94 {% if parent_v8_class %} |
99 if (!toV8{{parent_cpp_class}}(impl, v8Object, creationContext, isolate)) | 95 if (!toV8{{parent_cpp_class}}(impl, v8Object, creationContext, isolate)) |
100 return v8::Local<v8::Value>(); | 96 return v8::Local<v8::Value>(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 128 } |
133 | 129 |
134 {{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) |
135 { | 131 { |
136 {{cpp_class}} impl; | 132 {{cpp_class}} impl; |
137 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); | 133 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); |
138 return impl; | 134 return impl; |
139 } | 135 } |
140 | 136 |
141 } // namespace blink | 137 } // namespace blink |
OLD | NEW |