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

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: GN fix 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
« no previous file with comments | « Source/bindings/templates/dictionary_impl.h ('k') | Source/bindings/templates/templates.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {% endmacro %}
16 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, { {cpp_class}}& impl, ExceptionState& exceptionState) 18 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, { {cpp_class}}& impl, ExceptionState& exceptionState)
17 { 19 {
18 if (isUndefinedOrNull(v8Value)) 20 if (isUndefinedOrNull(v8Value))
19 return; 21 return;
20 if (!v8Value->IsObject()) { 22 if (!v8Value->IsObject()) {
21 exceptionState.throwTypeError("cannot convert to dictionary."); 23 exceptionState.throwTypeError("cannot convert to dictionary.");
22 return; 24 return;
23 } 25 }
24 26
25 {% if parent_v8_class %} 27 {% if parent_v8_class %}
26 {{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState); 28 {{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState);
27 if (exceptionState.hadException()) 29 if (exceptionState.hadException())
28 return; 30 return;
29 31
30 {% endif %} 32 {% endif %}
31 v8::Local<v8::Object> v8Object = v8Value->ToObject(isolate); 33 v8::Local<v8::Object> v8Object = v8Value->ToObject(isolate);
32 v8::TryCatch block; 34 v8::TryCatch block;
33 {% for member in members %} 35 {% for member in members %}
34 v8::Local<v8::Value> {{member.name}}Value = v8Object->Get(v8String(isolate, "{{member.name}}")); 36 v8::Local<v8::Value> {{member.name}}Value = v8Object->Get(v8String(isolate, "{{member.name}}"));
35 if (!{{member.name}}Value.IsEmpty() && !isUndefinedOrNull({{member.name}}Val ue)) { 37 if (block.HasCaught()) {
36 {% if member.use_output_parameter_for_result %} 38 exceptionState.rethrowV8Exception(block.Exception());
39 return;
40 }
41 if ({{member.name}}Value.IsEmpty() || {{member.name}}Value->IsUndefined()) {
42 // Do nothing.
43 {% if member.is_nullable %}
44 } else if ({{member.name}}Value->IsNull()) {
45 impl.{{member.null_setter_name}}();
46 {% endif %}
47 } else {
48 {% if member.use_output_parameter_for_result %}
37 {{member.cpp_type}} {{member.name}}; 49 {{member.cpp_type}} {{member.name}};
38 {% endif %} 50 {% endif %}
39 {{member.v8_value_to_local_cpp_value}}; 51 {{member.v8_value_to_local_cpp_value}};
40 {% if member.enum_validation_expression %} 52 {% if member.enum_validation_expression %}
41 String string = {{member.name}}; 53 String string = {{member.name}};
42 if (!({{member.enum_validation_expression}})) { 54 if (!({{member.enum_validation_expression}})) {
43 exceptionState.throwTypeError("member {{member.name}} ('" + string + "') is not a valid enum value."); 55 exceptionState.throwTypeError("member {{member.name}} ('" + string + "') is not a valid enum value.");
44 return; 56 return;
45 } 57 }
46 {% elif member.is_object %} 58 {% elif member.is_object %}
47 if (!{{member.name}}.isObject()) { 59 if (!{{member.name}}.isObject()) {
48 exceptionState.throwTypeError("member {{member.name}} is not an obje ct."); 60 exceptionState.throwTypeError("member {{member.name}} is not an obje ct.");
49 return; 61 return;
50 } 62 }
51 {% endif %} 63 {% endif %}
52 impl.{{member.setter_name}}({{member.name}}); 64 impl.{{member.setter_name}}({{member.name}});
53 } else if (block.HasCaught()) {
54 exceptionState.rethrowV8Exception(block.Exception());
55 return;
56 } 65 }
57 66
58 {% endfor %} 67 {% endfor %}
59 } 68 }
60 69
61 v8::Handle<v8::Value> toV8(const {{cpp_class}}& impl, v8::Handle<v8::Object> cre ationContext, v8::Isolate* isolate) 70 v8::Handle<v8::Value> toV8(const {{cpp_class}}& impl, v8::Handle<v8::Object> cre ationContext, v8::Isolate* isolate)
62 { 71 {
63 v8::Handle<v8::Object> v8Object = v8::Object::New(isolate); 72 v8::Handle<v8::Object> v8Object = v8::Object::New(isolate);
64 {% if parent_v8_class %} 73 {% if parent_v8_class %}
65 toV8{{parent_cpp_class}}(impl, v8Object, creationContext, isolate); 74 toV8{{parent_cpp_class}}(impl, v8Object, creationContext, isolate);
(...skipping 26 matching lines...) Expand all
92 } 101 }
93 102
94 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(const v8::Handle<v8: :Value>& value, v8::Isolate* isolate, ExceptionState& exceptionState) 103 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(const v8::Handle<v8: :Value>& value, v8::Isolate* isolate, ExceptionState& exceptionState)
95 { 104 {
96 {{cpp_class}} impl; 105 {{cpp_class}} impl;
97 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); 106 {{v8_class}}::toImpl(isolate, value, impl, exceptionState);
98 return impl; 107 return impl;
99 } 108 }
100 109
101 } // namespace blink 110 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/templates/dictionary_impl.h ('k') | Source/bindings/templates/templates.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698