diff --git a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index bfe1182aff..8de7548a58 100644 --- a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -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(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"~~~( diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 2d6ade6c5d..62871e8630 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -215,14 +215,14 @@ HTML::HTMLElement* Document::body() } // https://html.spec.whatwg.org/multipage/dom.html#dom-document-body -ExceptionOr Document::set_body(HTML::HTMLElement& new_body) +ExceptionOr Document::set_body(HTML::HTMLElement* new_body) { if (!is(new_body) && !is(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 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 {}; diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 0d9a999d1c..4225636f73 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -110,7 +110,7 @@ public: return const_cast(this)->body(); } - ExceptionOr set_body(HTML::HTMLElement& new_body); + ExceptionOr set_body(HTML::HTMLElement* new_body); String title() const; void set_title(const String&); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index 16e44a3078..bb23a9882c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -51,13 +51,16 @@ RefPtr HTMLTableElement::caption() return first_child_of_type(); } -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 HTMLTableElement::create_caption() @@ -93,9 +96,12 @@ RefPtr HTMLTableElement::t_head() return nullptr; } -DOM::ExceptionOr HTMLTableElement::set_t_head(HTMLTableSectionElement& thead) +DOM::ExceptionOr 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 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 HTMLTableElement::t_foot() return nullptr; } -DOM::ExceptionOr HTMLTableElement::set_t_foot(HTMLTableSectionElement& tfoot) +DOM::ExceptionOr 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 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 {}; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h index 6565017d2d..a91a1af20a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h @@ -22,17 +22,17 @@ public: virtual ~HTMLTableElement() override; RefPtr caption(); - void set_caption(HTMLTableCaptionElement&); + void set_caption(HTMLTableCaptionElement*); NonnullRefPtr create_caption(); void delete_caption(); RefPtr t_head(); - DOM::ExceptionOr set_t_head(HTMLTableSectionElement& thead); + DOM::ExceptionOr set_t_head(HTMLTableSectionElement* thead); NonnullRefPtr create_t_head(); void delete_t_head(); RefPtr t_foot(); - DOM::ExceptionOr set_t_foot(HTMLTableSectionElement& thead); + DOM::ExceptionOr set_t_foot(HTMLTableSectionElement* tfoot); NonnullRefPtr create_t_foot(); void delete_t_foot();