Skip to content

Conversation

Bashamega
Copy link
Contributor

related #2053

Copy link
Contributor

github-actions bot commented Aug 3, 2025

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

@@ -0,0 +1,12 @@
// Manually moved from Document
Copy link
Contributor

Choose a reason for hiding this comment

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

cssom-view.kdl

function handleMethod(child: Node): Partial<Method> {
const name = child.values[0] as string;
// Build the overrideSignatures array with the method signature string
const overrideSignatures = [
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not use overrideSignatures unless it's explicitly used. Take a look at widlprocess.ts to see how to proceed: (this PR does not need to cover everything in that file)

} else if (member.type === "operation") {
const operation = convertOperation(member, result.exposed);
const { method } = result.methods;
if (!member.name) {
result.anonymousMethods!.method.push(operation);
} else if (method.hasOwnProperty(member.name)) {
method[member.name].signature.push(...operation.signature);
} else {
method[member.name] = operation as Browser.Method;
}
if (member.name) {
addComments(method[member.name], commentMap, i.name, member.name);
}

Bashamega and others added 3 commits August 3, 2025 16:50
Co-authored-by: Kagami Sascha Rosylight <[email protected]>
Co-authored-by: Kagami Sascha Rosylight <[email protected]>
…meters and update return types for elementFromPoint and elementsFromPoint methods. Enhance method handling in patches.ts to accommodate nullable return types and array signatures.
@Bashamega
Copy link
Contributor Author

I've updated it, @saschanaz.
I used array instead of wrapping the return value with a sequence. If you still prefer your version, I can make it work with a regex. That said, I believe the current implementation is better for the parser.

@@ -0,0 +1,12 @@
// Manually moved from Document
Copy link
Contributor

Choose a reason for hiding this comment

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

.kdl, not .kd 😛

Also maybe 2-space indent to be consistent with the rest of the code 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fixed the name

Copy link
Contributor

Choose a reason for hiding this comment

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

but not the indent 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot, I have updated them

param x type=long
param y type=long
}
method elementsFromPoint returns="Element" array {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to follow the syntax of

export interface Typed {
type: string | Typed[];
subtype?: Typed | Typed[];
nullable?: boolean;
overrideType?: string;
additionalTypes?: string[];
allowShared?: boolean;
}

But that doesn't seem possible as a property. Perhaps we should allow (but not force) type as a member for complex cases like this.

method elementsFromPoint {
  type sequence {
     type Element
  }
  param x type=long
  param y type=long
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

@Bashamega
Copy link
Contributor Author

I have updated it @saschanaz

@Bashamega
Copy link
Contributor Author

Hello @saschanaz
Do you have any more requests for this PR?

// Manually moved from Document
// See https://github.com/w3c/csswg-drafts/issues/5886 and https://github.com/w3c/csswg-drafts/issues/556
interface-mixin DocumentOrShadowRoot {
method elementFromPoint returns=Element nullable=#true {
Copy link
Contributor

Choose a reason for hiding this comment

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

nullable is logically a property of the return type rather than the method, so in this case it would be also nicer to use separate type node as below.


const signature: Method["signature"] = [
{
type: type.name == "type" ? (type.values[0] as string) : returnType,
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll probably get similar situation on other things than methods, this should probably be done in a helper function so that others can reuse it, something like handleTyped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made it a helper function

const nullable = child.properties.nullable as boolean;

const params = child.children
.filter((c) => c.values[0] != "sequence")
Copy link
Contributor

Choose a reason for hiding this comment

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

It should filter in based on the type param, not filter out based on name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@Bashamega
Copy link
Contributor Author

I have updated it @saschanaz

@Bashamega Bashamega requested a review from saschanaz August 7, 2025 06:23
@Bashamega
Copy link
Contributor Author

Hello @saschanaz
Do you have any more requests for this PR?

@Bashamega
Copy link
Contributor Author

Welcome back from vacation, @saschanaz!
I hope you had a great time. I’m excited to get this PR merged whenever you’re ready.

Copy link
Contributor

@saschanaz saschanaz left a comment

Choose a reason for hiding this comment

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

Sorry for the long delay!

* @param child The child node to handle.
*/
function handleMethod(child: Node): Partial<Method> {
const name = child.values[0] as string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Too many as string, would be nice to have something like

function string(arg: unknown): string {
  if (typeof arg !== "string") {
    throw new Error(`Expected a string but found ${typeof arg}`);
  }
  return arg;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*/
function handleMethod(child: Node): Partial<Method> {
const name = child.values[0] as string;
const type = child.children[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

We should iterate and check types than assuming a position or using filter(), otherwise we can't throw on unexpected child. Just like line 120.

}
case "method": {
const methodName = child.values[0] as string;
method[methodName] = handleMethod(child);
Copy link
Contributor

Choose a reason for hiding this comment

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

(Fine for now but eventually this will need to change to support overloads)

const name = isTyped ? (type.values[0] as string) : returnType;
const subType =
type.children.length > 0
? { type: type.children[0].values[0] as string }
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a recursive call to handleTyped

@Bashamega
Copy link
Contributor Author

Bashamega commented Aug 27, 2025

No problem :)
I will take a look at the review today

@Bashamega
Copy link
Contributor Author

I have updated it @saschanaz 😃

@Bashamega Bashamega requested a review from saschanaz August 27, 2025 08:53
@Bashamega
Copy link
Contributor Author

Hello @saschanaz,
Is there anything else that is missing here?

Copy link
Contributor

@saschanaz saschanaz left a comment

Choose a reason for hiding this comment

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

Let's remove returns for now and then this should be ok. Thanks!

BTW I think we got a lot more conversion boilerplate than I expected... I'll think about how to simplify.

*/
function handleMethod(child: Node): Partial<Method> {
const name = string(child.values[0]);
const returnType = child.properties.returns;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not used here, maybe add back when it's actually used but not now

switch (c.name) {
case "type":
if (typeNode) {
throw new Error(`Method "${name}" has multiple type nodes (invalid)`);
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually want to allow this for union types, but for now this is ok as we don't have union types right now

...handleTyped(typeNode, returnType),
},
];
return { name, signature };
Copy link
Contributor

Choose a reason for hiding this comment

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

(This is fine for now but eventually we'll hit a problem when dealing with overloads)

@Bashamega
Copy link
Contributor Author

Thank you for your review @saschanaz !
I have removed returns

@Bashamega
Copy link
Contributor Author

Hello @saschanaz
Is there anything left here?

return arg;
}

function handleTyped(type: Node, returnType?: Value): Typed {
Copy link
Contributor

Choose a reason for hiding this comment

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

Still have unused parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it needed though? subtype would also be a type, so isTyped should be true, and then the second parameter won't be used, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will update it

@Bashamega
Copy link
Contributor Author

Done @saschanaz

@saschanaz
Copy link
Contributor

LGTM

Copy link
Contributor

There was an issue merging, maybe try again saschanaz. Details

@jakebailey jakebailey merged commit 522dbd5 into microsoft:main Sep 20, 2025
5 checks passed
@saschanaz
Copy link
Contributor

LGTM (I feel like we are going to hit an anniversary of double LGTMing 😂)

Copy link
Contributor

Sorry @saschanaz, this PR isn't open.

@jakebailey
Copy link
Member

Well, I'm at least merging them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants