mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
LibWeb: Make WrapperGenerator generate nullable wrapper types
Previously it was not doing so, and some code relied on this not being the case. In particular, set_caption, set_t_head and set_t_foot in HTMLTableElement relied on this. This commit is not here to fix this, so I added an assertion to make it equivalent to a reference for now.
This commit is contained in:
parent
62c015dc96
commit
a826df773e
5 changed files with 43 additions and 16 deletions
|
@ -573,7 +573,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
)~~~");
|
||||
}
|
||||
} else if (is_wrappable_type(parameter.type)) {
|
||||
scoped_generator.append(R"~~~(
|
||||
if (!parameter.type.nullable) {
|
||||
scoped_generator.append(R"~~~(
|
||||
auto @cpp_name@_object = @js_name@@js_suffix@.to_object(global_object);
|
||||
if (vm.exception())
|
||||
@return_statement@
|
||||
|
@ -585,6 +586,23 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
|
||||
auto& @cpp_name@ = static_cast<@parameter.type.name@Wrapper*>(@cpp_name@_object)->impl();
|
||||
)~~~");
|
||||
} else {
|
||||
scoped_generator.append(R"~~~(
|
||||
@parameter.type.name@* @cpp_name@ = nullptr;
|
||||
if (!@js_name@@js_suffix@.is_null()) {
|
||||
auto @cpp_name@_object = @js_name@@js_suffix@.to_object(global_object);
|
||||
if (vm.exception())
|
||||
@return_statement@
|
||||
|
||||
if (!is<@parameter.type.name@Wrapper>(@cpp_name@_object)) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "@parameter.type.name@");
|
||||
@return_statement@
|
||||
}
|
||||
|
||||
@cpp_name@ = &static_cast<@parameter.type.name@Wrapper*>(@cpp_name@_object)->impl();
|
||||
}
|
||||
)~~~");
|
||||
}
|
||||
} else if (parameter.type.name == "double") {
|
||||
if (!optional) {
|
||||
scoped_generator.append(R"~~~(
|
||||
|
|
|
@ -215,14 +215,14 @@ HTML::HTMLElement* Document::body()
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
|
||||
ExceptionOr<void> Document::set_body(HTML::HTMLElement& new_body)
|
||||
ExceptionOr<void> Document::set_body(HTML::HTMLElement* new_body)
|
||||
{
|
||||
if (!is<HTML::HTMLBodyElement>(new_body) && !is<HTML::HTMLFrameSetElement>(new_body))
|
||||
return DOM::HierarchyRequestError::create("Invalid document body element, must be 'body' or 'frameset'");
|
||||
|
||||
auto* existing_body = body();
|
||||
if (existing_body) {
|
||||
auto replace_result = existing_body->parent()->replace_child(new_body, *existing_body);
|
||||
auto replace_result = existing_body->parent()->replace_child(*new_body, *existing_body);
|
||||
if (replace_result.is_exception())
|
||||
return replace_result.exception();
|
||||
return {};
|
||||
|
@ -232,7 +232,7 @@ ExceptionOr<void> Document::set_body(HTML::HTMLElement& new_body)
|
|||
if (!document_element)
|
||||
return DOM::HierarchyRequestError::create("Missing document element");
|
||||
|
||||
auto append_result = document_element->append_child(new_body);
|
||||
auto append_result = document_element->append_child(*new_body);
|
||||
if (append_result.is_exception())
|
||||
return append_result.exception();
|
||||
return {};
|
||||
|
|
|
@ -110,7 +110,7 @@ public:
|
|||
return const_cast<Document*>(this)->body();
|
||||
}
|
||||
|
||||
ExceptionOr<void> set_body(HTML::HTMLElement& new_body);
|
||||
ExceptionOr<void> set_body(HTML::HTMLElement* new_body);
|
||||
|
||||
String title() const;
|
||||
void set_title(const String&);
|
||||
|
|
|
@ -51,13 +51,16 @@ RefPtr<HTMLTableCaptionElement> HTMLTableElement::caption()
|
|||
return first_child_of_type<HTMLTableCaptionElement>();
|
||||
}
|
||||
|
||||
void HTMLTableElement::set_caption(HTMLTableCaptionElement& caption)
|
||||
void HTMLTableElement::set_caption(HTMLTableCaptionElement* caption)
|
||||
{
|
||||
// FIXME: This is not always the case, but this function is currently written in a way that assumes non-null.
|
||||
VERIFY(caption);
|
||||
|
||||
// FIXME: The spec requires deleting the current caption if caption is null
|
||||
// Currently the wrapper generator doesn't send us a nullable value
|
||||
delete_caption();
|
||||
|
||||
pre_insert(caption, first_child());
|
||||
pre_insert(*caption, first_child());
|
||||
}
|
||||
|
||||
NonnullRefPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption()
|
||||
|
@ -93,9 +96,12 @@ RefPtr<HTMLTableSectionElement> HTMLTableElement::t_head()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
DOM::ExceptionOr<void> HTMLTableElement::set_t_head(HTMLTableSectionElement& thead)
|
||||
DOM::ExceptionOr<void> HTMLTableElement::set_t_head(HTMLTableSectionElement* thead)
|
||||
{
|
||||
if (thead.tag_name() != TagNames::thead)
|
||||
// FIXME: This is not always the case, but this function is currently written in a way that assumes non-null.
|
||||
VERIFY(thead);
|
||||
|
||||
if (thead->tag_name() != TagNames::thead)
|
||||
return DOM::HierarchyRequestError::create("Element is not thead");
|
||||
|
||||
// FIXME: The spec requires deleting the current thead if thead is null
|
||||
|
@ -120,7 +126,7 @@ DOM::ExceptionOr<void> HTMLTableElement::set_t_head(HTMLTableSectionElement& the
|
|||
break;
|
||||
}
|
||||
|
||||
pre_insert(thead, child_to_append_after);
|
||||
pre_insert(*thead, child_to_append_after);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -177,9 +183,12 @@ RefPtr<HTMLTableSectionElement> HTMLTableElement::t_foot()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
DOM::ExceptionOr<void> HTMLTableElement::set_t_foot(HTMLTableSectionElement& tfoot)
|
||||
DOM::ExceptionOr<void> HTMLTableElement::set_t_foot(HTMLTableSectionElement* tfoot)
|
||||
{
|
||||
if (tfoot.tag_name() != TagNames::tfoot)
|
||||
// FIXME: This is not always the case, but this function is currently written in a way that assumes non-null.
|
||||
VERIFY(tfoot);
|
||||
|
||||
if (tfoot->tag_name() != TagNames::tfoot)
|
||||
return DOM::HierarchyRequestError::create("Element is not tfoot");
|
||||
|
||||
// FIXME: The spec requires deleting the current tfoot if tfoot is null
|
||||
|
@ -187,7 +196,7 @@ DOM::ExceptionOr<void> HTMLTableElement::set_t_foot(HTMLTableSectionElement& tfo
|
|||
delete_t_foot();
|
||||
|
||||
// We insert the new tfoot at the end of the table
|
||||
append_child(tfoot);
|
||||
append_child(*tfoot);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -22,17 +22,17 @@ public:
|
|||
virtual ~HTMLTableElement() override;
|
||||
|
||||
RefPtr<HTMLTableCaptionElement> caption();
|
||||
void set_caption(HTMLTableCaptionElement&);
|
||||
void set_caption(HTMLTableCaptionElement*);
|
||||
NonnullRefPtr<HTMLTableCaptionElement> create_caption();
|
||||
void delete_caption();
|
||||
|
||||
RefPtr<HTMLTableSectionElement> t_head();
|
||||
DOM::ExceptionOr<void> set_t_head(HTMLTableSectionElement& thead);
|
||||
DOM::ExceptionOr<void> set_t_head(HTMLTableSectionElement* thead);
|
||||
NonnullRefPtr<HTMLTableSectionElement> create_t_head();
|
||||
void delete_t_head();
|
||||
|
||||
RefPtr<HTMLTableSectionElement> t_foot();
|
||||
DOM::ExceptionOr<void> set_t_foot(HTMLTableSectionElement& thead);
|
||||
DOM::ExceptionOr<void> set_t_foot(HTMLTableSectionElement* tfoot);
|
||||
NonnullRefPtr<HTMLTableSectionElement> create_t_foot();
|
||||
void delete_t_foot();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue