selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[nodejs] Implement missing Header.asMap to return a Map

Open ankianan opened this issue 4 months ago • 4 comments

User description

🔗 Related Issues

Fixes #16339

💥 What does this PR do?

Implement asMap function for Header class

🔧 Implementation Notes

💡 Additional Considerations

🔄 Types of changes

  • Bug fix (backwards compatible)

PR Type

Enhancement


Description

  • Add asMap() method to Header class in BiDi network types

  • Converts Header object to Map with name and value entries

  • Implements missing functionality for Header serialization


Diagram Walkthrough

flowchart LR
  A["Header class"] --> B["asMap() method"]
  B --> C["Map with name/value"]
  C --> D["Serialized Header data"]

File Walkthrough

Relevant files
Enhancement
networkTypes.js
Add Header asMap method                                                                   

javascript/selenium-webdriver/bidi/networkTypes.js

  • Add asMap() method to Header class
  • Returns Map with "name" and "value" entries
  • Value is converted using nested asMap() call
+11/-0   

ankianan avatar Sep 21 '25 00:09 ankianan

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Sep 21 '25 00:09 CLAassistant

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

API Consistency

Confirm that returning a native Map from Header.asMap() aligns with surrounding BiDi type serializers; other types may return plain objects. Inconsistent return types could complicate consumers and serialization.

asMap() {
      return new Map([
          ["name", this.name],
          ["value", Object.fromEntries(this.value.asMap())]
      ]);
  };
Value Handling

Object.fromEntries(this.value.asMap()) assumes value.asMap() returns entries; verify BytesValue.asMap() exists and matches expected structure. If value can be null/primitive, add guards to prevent runtime errors.

    ["name", this.name],
    ["value", Object.fromEntries(this.value.asMap())]
]);
Trailing Semicolon/Method Syntax

The class method ends with }; which is unnecessary for class method definitions and may violate lint rules; consider removing the trailing semicolon.

asMap() {
      return new Map([
          ["name", this.name],
          ["value", Object.fromEntries(this.value.asMap())]
      ]);
  };

qodo-code-review[bot] avatar Sep 21 '25 00:09 qodo-code-review[bot]

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Ensure consistent nested Map structures

In the Header.asMap method, remove the Object.fromEntries call to ensure the
nested value remains a Map, maintaining data structure consistency.

javascript/selenium-webdriver/bidi/networkTypes.js [128-131]

 return new Map([
     ["name", this.name],
-    ["value", Object.fromEntries(this.value.asMap())]
+    ["value", this.value.asMap()]
 ]);
  • [ ] Apply / Chat <!-- /improve --apply_suggestion=0 -->
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that converting the nested Map from this.value.asMap() to an object using Object.fromEntries creates an inconsistent data structure, and the proposed change improves API consistency.

Low
  • [ ] More <!-- /improve --more_suggestions=true -->

qodo-code-review[bot] avatar Sep 21 '25 00:09 qodo-code-review[bot]

@ankianan The linter is failing on this. Can you run ./scripts/format.sh and then update your branch?

cgoldberg avatar Sep 30 '25 18:09 cgoldberg