immersive-web / hit-test

https://immersive-web.github.io/hit-test/
Other
78 stars 31 forks source link

Fix webidl for XRRay #83

Closed Manishearth closed 4 years ago

Manishearth commented 4 years ago

r? @bialpio


Preview | Diff

Manishearth commented 4 years ago

Actually it seems like one of the tests asserts that this throws an error, so i'm just going to switch that over to an error

Manishearth commented 4 years ago

Actually, ugh, this isn't right either, because now new XRRay(point) doesn't work, and new XRRay(point, {}) will throw an error.

Manishearth commented 4 years ago

At least in Servo the overload isn't working when we pass a single argument, either.

Manishearth commented 4 years ago

Yeah so the current model is fundamentally broken, it relies on obsolete webidl behavior (which is no longer allowed by Firefox and Servo's webidl parser and cannot be implemented).

It is not possible to distinguish between a null and initial-value dict argument.

Furthermore, new XRRay(domPoint) will not work if domPoint is a DomPoint object (or DomPointReadOnly) as tested by xrRay_constructor.html. The overload resolution algorithm step 12, substep 4, will notice that domPoint is a "platform object" and focus on resolving against the XRRigidTransform constructor, and at that point fail. It is a bug in Chrome's webidl implementation that new XRRay(new DOMPoint({x: 1, y: 0, z: 0})) works at all.

But I kind of want that to work -- we might need to introduce an additional single-argument DOMPointReadonly overload.

Manishearth commented 4 years ago

The overload resolution algorithm step 12, substep 4, will notice that domPoint is a "platform object" and focus on resolving against the XRRigidTransform constructor, and at that point fail. It is a bug in Chrome's webidl implementation that new XRRay(new DOMPoint({x: 1, y: 0, z: 0})) works at all.

Hmm, actually, maybe not, it requires that V implement it. Could be a bug on our side, but I'm not sure.

Update: yeah that's a bug on our side.

The original change in this PR still stands.

bialpio commented 4 years ago

I'm not sure if we should silently accept new XRRay({}, {}); - it is equivalent to new XRRay({}, {x:0, x:0, y:0, w:1}), and I think this should be rejected instead of automatically fixed by us. Would updating the spec to accept DOMPointReadOnlys instead of DOMPointInits solve this issue in a non-API-breaking way?

And now it occurred to me that we ignore ws of the passed in dictionaries - it feels wrong that we don't even validate it, but then we won't be able to correctly validate the default direction (since w needs to be set to 0 there...).

Manishearth commented 4 years ago

@bialpio there is no way to distinguish between new XRRay({}, {}) and new XRRay({})

Using DOMPointReadOnlys is an API breaking change, because currently you can pass a dictionary and making it use DOMPointReadOnly will force you to use an interface.

And yeah, we ignore the ws, i'd noticed that but wasn't sure how best to handle that. We can divide by w for position and error in the zero case, but there's not much we can do for direction.

Manishearth commented 4 years ago

Oh, another option we have available is to define a new dictionary for direction that has different defaults. Thoughts?

Manishearth commented 4 years ago

It's not pretty, but it would work.

Manishearth commented 4 years ago

Should I file an issue for this with the various options?

bialpio commented 4 years ago

I like the idea of having a new dictionary - I think it checks all the boxes (should not be a breaking change, we won't be auto-fixing incorrect parameters, allows us to correctly validate & handle w both for position and direction). Sure, go ahead and file a new issue.

Manishearth commented 4 years ago

I'm closing this and will reopen a fresh PR