Skip to content

feat: implement removal methods for HTMLElement and add tests - #20

Merged
ziflex merged 1 commit into
mainfrom
feat/delete-prop
May 23, 2026
Merged

feat: implement removal methods for HTMLElement and add tests#20
ziflex merged 1 commit into
mainfrom
feat/delete-prop

Conversation

@ziflex

@ziflex ziflex commented May 23, 2026

Copy link
Copy Markdown
Member

This pull request introduces support for child element removal by index and key to both memory and CDP-backed HTML elements, along with comprehensive tests to verify this new functionality. The changes ensure that HTMLElement types in both backends implement the new IndexRemovable and KeyRemovable interfaces, and that removal operations behave consistently and correctly, including type safety for keys.

New removal functionality for HTML elements:

  • Added RemoveAt and RemoveKey methods to memory.HTMLElement and cdpdom.HTMLElement, allowing removal of child elements by index and key. These methods return the removed element or an error if the operation is invalid (e.g., non-integer key). [1] [2]
  • Implemented the corresponding JavaScript template for child removal in CDP (removeChildByIndex) and integrated it into the element evaluation logic.

Interface and capability updates:

  • Registered IndexRemovable and KeyRemovable interfaces for both backends and updated capability tests to verify their implementation. [1] [2] [3] [4] [5]
  • Updated the read-only contract test to check that only the correct element types implement these new interfaces. [1] [2]

Testing improvements:

  • Added new unit tests for memory-backed elements to verify correct removal by index and key, including edge cases (e.g., missing index, invalid key type).
  • Added a test for CDP-backed elements to ensure RemoveKey rejects non-integer keys. [1] [2]

These changes collectively enhance the flexibility and robustness of HTML element manipulation in both memory and CDP drivers.

Copilot AI review requested due to automatic review settings May 23, 2026 02:12
@ziflex ziflex added enhancement New feature or request module/web/html HTML module issues labels May 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds child-removal support to HTMLElement implementations across the memory and CDP backends, exposing removal by index (RemoveAt) and by key (RemoveKey) and updating capability/contract tests accordingly.

Changes:

  • Implement RemoveAt/RemoveKey on memory.HTMLElement and cdpdom.HTMLElement to remove child elements by index.
  • Add a CDP JS evaluation template (removeChildByIndex) used by CDP-backed element removal.
  • Extend capability/contract tests and add new unit tests (notably for memory-backed removal and key-type validation).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
modules/web/html/drivers/read_only_contract_test.go Extends contract assertions to include IndexRemovable/KeyRemovable support expectations.
modules/web/html/drivers/memory/element.go Adds child removal implementations for memory-backed elements.
modules/web/html/drivers/memory/element_removal_test.go Adds unit tests validating memory-backed removal behavior and edge cases.
modules/web/html/drivers/cdp/templates/children.go Introduces JS template used to remove a child by index in the CDP backend.
modules/web/html/drivers/cdp/dom/element_value_test.go Adds a unit test to ensure RemoveKey rejects non-integer keys.
modules/web/html/drivers/cdp/dom/element_query.go Adds CDP-backed RemoveAt/RemoveKey methods using the new template.
modules/web/html/drivers/capabilities_test.go Registers and validates IndexRemovable/KeyRemovable capabilities for both backends.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 18 to +20
keyWritable := reflect.TypeOf((*runtime.KeyWritable)(nil)).Elem()
indexRemovable := reflect.TypeOf((*runtime.IndexRemovable)(nil)).Elem()
keyRemovable := reflect.TypeOf((*runtime.KeyRemovable)(nil)).Elem()
Comment on lines +20 to +36
func (el *HTMLElement) RemoveAt(ctx context.Context, idx runtime.Int) (runtime.Value, error) {
if idx < 0 {
return runtime.None, nil
}

return el.eval.EvalElement(ctx, templates.RemoveChildByIndex(el.id, idx))
}

func (el *HTMLElement) RemoveKey(ctx context.Context, key runtime.Value) error {
idx, ok := key.(runtime.Int)
if !ok {
return runtime.Error(runtime.ErrInvalidArgument, "element child index must be an integer")
}

_, err := el.RemoveAt(ctx, idx)

return err
@ziflex
ziflex merged commit e71eece into main May 23, 2026
33 checks passed
@ziflex
ziflex deleted the feat/delete-prop branch May 23, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request module/web/html HTML module issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants