Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@joshualitt
Copy link
Contributor

@joshualitt joshualitt commented Feb 20, 2023

Type checking is not well defined with JS interop. A safer approach is to type check JS values in JS using js_util. This CL implements such an explicit test.

@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label Feb 20, 2023
@joshualitt joshualitt requested a review from mdebbar February 21, 2023 17:48
@joshualitt
Copy link
Contributor Author

joshualitt commented Feb 21, 2023

@mdebbar ptal, I think you may have added this test a few years ago. I'm not sure how we want to handle this, but this test relies on not well specified behavior of JS interop. In particular, JS interop APIs don't have the same type checking guarantees that Dart APIs do, and as we iterate on the new JS interop, these guarantees will be weakened further.

I'm not sure the best path forward. I think the best 'type checking' we can do is ensure that when we get this property, it has a typeof === 'function'.

@joshualitt joshualitt marked this pull request as ready for review February 22, 2023 00:32
@mdebbar
Copy link
Contributor

mdebbar commented Feb 22, 2023

Would it work if we added type-checking here? :

jsSetUrlStrategy = allowInterop((JsUrlStrategy? jsStrategy) {
customUrlStrategy =
jsStrategy == null ? null : CustomUrlStrategy.fromJs(jsStrategy);
});

I'm not sure the best path forward. I think the best 'type checking' we can do is ensure that when we get this property, it has a typeof === 'function'.

We are not type-checking the function here, we are type-checking the arguments passed to the function. We need to make sure the argument is a JsUrlStrategy, but I'm not sure how to do that in the static js interop world. Maybe check that some properties exist on the object? e.g. js_util.hasProperty(obj, 'addPopStateListener')

@joshualitt joshualitt changed the title [web] Remove invalid test. [web] Add explicit JS type test for JsStrategy. Feb 22, 2023
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@joshualitt
Copy link
Contributor Author

Good call, I added a check for addPopStateListener in the non-null case. ptal.

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

@joshualitt joshualitt force-pushed the remove-test branch 2 times, most recently from c51ab16 to d13d6b9 Compare March 2, 2023 20:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs tests platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants