Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: Source/bindings/templates/dictionary_v8.cpp

Issue 765673005: IDL: Null values should be converted for non-nullable dictionary members (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file has been auto-generated by {{code_generator}}. DO NOT MODIFY! 5 // This file has been auto-generated by {{code_generator}}. DO NOT MODIFY!
6 6
7 #include "config.h" 7 #include "config.h"
8 #include "{{v8_original_class}}.h" 8 #include "{{v8_original_class}}.h"
9 9
10 {% for filename in cpp_includes if filename != '%s.h' % v8_class %} 10 {% for filename in cpp_includes if filename != '%s.h' % v8_class %}
11 #include "{{filename}}" 11 #include "{{filename}}"
12 {% endfor %} 12 {% endfor %}
13 13
14 namespace blink { 14 namespace blink {
15 15
16 {% macro convert_and_set_member(member) %}
17 {% if member.use_output_parameter_for_result %}
18 {{member.cpp_type}} {{member.name}};
19 {% endif %}
20 {{member.v8_value_to_local_cpp_value}};
21 {% if member.enum_validation_expression %}
22 String string = {{member.name}};
23 if (!({{member.enum_validation_expression}})) {
24 exceptionState.throwTypeError("member {{member.name}} ('" + string + "') is not a valid enum value.");
25 return;
26 }
27 {% elif member.is_object %}
28 if (!{{member.name}}.isObject()) {
29 exceptionState.throwTypeError("member {{member.name}} is not an object.");
30 return;
31 }
32 {% endif %}
33 impl.{{member.setter_name}}({{member.name}});
34 {% endmacro %}
16 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, { {cpp_class}}& impl, ExceptionState& exceptionState) 35 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, { {cpp_class}}& impl, ExceptionState& exceptionState)
17 { 36 {
18 if (isUndefinedOrNull(v8Value)) 37 if (isUndefinedOrNull(v8Value))
19 return; 38 return;
20 if (!v8Value->IsObject()) { 39 if (!v8Value->IsObject()) {
21 exceptionState.throwTypeError("cannot convert to dictionary."); 40 exceptionState.throwTypeError("cannot convert to dictionary.");
22 return; 41 return;
23 } 42 }
24 43
25 {% if parent_v8_class %} 44 {% if parent_v8_class %}
26 {{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState); 45 {{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState);
27 if (exceptionState.hadException()) 46 if (exceptionState.hadException())
28 return; 47 return;
29 48
30 {% endif %} 49 {% endif %}
31 v8::Local<v8::Object> v8Object = v8Value->ToObject(isolate); 50 v8::Local<v8::Object> v8Object = v8Value->ToObject(isolate);
32 v8::TryCatch block; 51 v8::TryCatch block;
33 {% for member in members %} 52 {% for member in members %}
34 v8::Local<v8::Value> {{member.name}}Value = v8Object->Get(v8String(isolate, "{{member.name}}")); 53 v8::Local<v8::Value> {{member.name}}Value = v8Object->Get(v8String(isolate, "{{member.name}}"));
35 if (!{{member.name}}Value.IsEmpty() && !isUndefinedOrNull({{member.name}}Val ue)) { 54 if (!{{member.name}}Value.IsEmpty() && !{{member.name}}Value->IsUndefined()) {
36 {% if member.use_output_parameter_for_result %} 55 {% if member.is_nullable %}
37 {{member.cpp_type}} {{member.name}}; 56 if ({{member.name}}Value->IsNull()) {
38 {% endif %} 57 impl.{{member.resetter_name}}();
bashi 2014/11/28 05:14:16 This is need to reset default values. Default valu
39 {{member.v8_value_to_local_cpp_value}}; 58 } else {
40 {% if member.enum_validation_expression %} 59 {{convert_and_set_member(member) | indent(12)}}
41 String string = {{member.name}};
42 if (!({{member.enum_validation_expression}})) {
43 exceptionState.throwTypeError("member {{member.name}} ('" + string + "') is not a valid enum value.");
44 return;
45 } 60 }
46 {% elif member.is_object %} 61 {% else %}
47 if (!{{member.name}}.isObject()) { 62 {{convert_and_set_member(member) | indent(8)}}
48 exceptionState.throwTypeError("member {{member.name}} is not an obje ct."); 63 {% endif %}
49 return;
50 }
51 {% endif %}
52 impl.{{member.setter_name}}({{member.name}});
53 } else if (block.HasCaught()) { 64 } else if (block.HasCaught()) {
54 exceptionState.rethrowV8Exception(block.Exception()); 65 exceptionState.rethrowV8Exception(block.Exception());
55 return; 66 return;
56 } 67 }
57 68
58 {% endfor %} 69 {% endfor %}
59 } 70 }
60 71
61 v8::Handle<v8::Value> toV8(const {{cpp_class}}& impl, v8::Handle<v8::Object> cre ationContext, v8::Isolate* isolate) 72 v8::Handle<v8::Value> toV8(const {{cpp_class}}& impl, v8::Handle<v8::Object> cre ationContext, v8::Isolate* isolate)
62 { 73 {
(...skipping 29 matching lines...) Expand all
92 } 103 }
93 104
94 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(const v8::Handle<v8: :Value>& value, v8::Isolate* isolate, ExceptionState& exceptionState) 105 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(const v8::Handle<v8: :Value>& value, v8::Isolate* isolate, ExceptionState& exceptionState)
95 { 106 {
96 {{cpp_class}} impl; 107 {{cpp_class}} impl;
97 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); 108 {{v8_class}}::toImpl(isolate, value, impl, exceptionState);
98 return impl; 109 return impl;
99 } 110 }
100 111
101 } // namespace blink 112 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698