1 {% from
'conversions.cpp' import declare_enum_validation_variable
%}
2 {% include
'copyright_block.txt' %}
4 #include "{{v8_original_class}}.h"
6 {% for filename in cpp_includes
if filename
!= '%s.h' % v8_class
%}
7 #include "{{filename}}"
12 {% from
'conversions.cpp' import v8_value_to_local_cpp_value
%}
13 void {{v8_class
}}::toImpl(v8::Isolate
* isolate
, v8::Local
<v8::Value
> v8Value
, {{cpp_class
}}& impl
, ExceptionState
& exceptionState
)
15 if (isUndefinedOrNull(v8Value
))
17 if (!v8Value
->IsObject()) {
18 {% if use_permissive_dictionary_conversion
%}
22 exceptionState
.throwTypeError("cannot convert to dictionary.");
27 {% if parent_v8_class
%}
28 {{parent_v8_class
}}::toImpl(isolate
, v8Value
, impl
, exceptionState
);
29 if (exceptionState
.hadException())
33 {# Declare local variables only when the dictionary has members to avoid unused variable warnings. #}
36 v8::Local
<v8::Object
> v8Object
;
37 if (!v8Call(v8Value
->ToObject(isolate
->GetCurrentContext()), v8Object
, block
)) {
38 exceptionState
.rethrowV8Exception(block
.Exception());
42 {% for member in members
%}
44 v8::Local
<v8::Value
> {{member
.name
}}Value
;
45 if (!v8Object
->Get(isolate
->GetCurrentContext(), v8String(isolate
, "{{member.name}}")).ToLocal(&{{member
.name
}}Value
)) {
46 exceptionState
.rethrowV8Exception(block
.Exception());
49 if ({{member
.name
}}Value
.IsEmpty() || {{member
.name
}}Value
->IsUndefined()) {
50 {% if member
.is_required
%}
51 exceptionState
.throwTypeError("required member {{member.name}} is undefined.");
56 {% if member
.is_nullable
%}
57 } else if ({{member
.name
}}Value
->IsNull()) {
58 impl
.{{member
.null_setter_name
}}();
61 {% if member
.deprecate_as
%}
62 UseCounter::countDeprecationIfNotPrivateScript(isolate
, callingExecutionContext(isolate
), UseCounter::{{member
.deprecate_as
}});
64 {{v8_value_to_local_cpp_value(member
) | indent(12)}}
65 {% if member
.is_interface_type
%}
66 if (!{{member
.name
}} && !{{member
.name
}}Value
->IsNull()) {
67 exceptionState
.throwTypeError("member {{member.name}} is not of type {{member.idl_type}}.");
71 {% if member
.enum_values
%}
72 {{declare_enum_validation_variable(member
.enum_values
) | indent(12)}}
73 if (!isValidEnum({{member
.name
}}, validValues
, WTF_ARRAY_LENGTH(validValues
), "{{member.enum_type}}", exceptionState
))
75 {% elif member
.is_object
%}
76 if (!{{member
.name
}}.isObject()) {
77 exceptionState
.throwTypeError("member {{member.name}} is not an object.");
81 impl
.{{member
.setter_name
}}({{member
.name
}});
88 v8::Local
<v8::Value
> toV8(const {{cpp_class
}}& impl
, v8::Local
<v8::Object
> creationContext
, v8::Isolate
* isolate
)
90 v8::Local
<v8::Object
> v8Object
= v8::Object::New(isolate
);
91 {% if parent_v8_class
%}
92 if (!toV8
{{parent_cpp_class
}}(impl
, v8Object
, creationContext
, isolate
))
93 return v8::Local
<v8::Value
>();
95 if (!toV8
{{cpp_class
}}(impl
, v8Object
, creationContext
, isolate
))
96 return v8::Local
<v8::Value
>();
100 bool toV8
{{cpp_class
}}(const {{cpp_class
}}& impl
, v8::Local
<v8::Object
> dictionary
, v8::Local
<v8::Object
> creationContext
, v8::Isolate
* isolate
)
102 {% for member in members
%}
103 if (impl
.{{member
.has_method_name
}}()) {
104 {% if member
.is_object
%}
105 ASSERT(impl
.{{member
.cpp_name
}}().isObject());
107 if (!v8CallBoolean(dictionary
->CreateDataProperty(isolate
->GetCurrentContext(), v8String(isolate
, "{{member.name}}"), {{member
.cpp_value_to_v8_value
}})))
109 {% if member
.v8_default_value
%}
111 if (!v8CallBoolean(dictionary
->CreateDataProperty(isolate
->GetCurrentContext(), v8String(isolate
, "{{member.name}}"), {{member
.v8_default_value
}})))
113 {% elif member
.is_required
%}
115 ASSERT_NOT_REACHED();
123 {{cpp_class
}} NativeValueTraits
<{{cpp_class
}}>::nativeValue(v8::Isolate
* isolate
, v8::Local
<v8::Value
> value
, ExceptionState
& exceptionState
)
126 {{v8_class
}}::toImpl(isolate
, value
, impl
, exceptionState
);