New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
normalize undefined/null on DOM call boundary #21555
Comments
This example is slightly bogus. I am worried about the code size and performance implications of putting conversions on DOM APIs. Browsers are not totally consistent in their implementation of the standards. |
Why do you think the example is bogus? Just consider a setting where you use some framework with data binding that binds a List of String to a set of input fields. If you push the initial state of your List to the input fields, you would get loads of ¨undefined¨ unless your framework has some special handling to work around this quirk. I would also be OK with disallowing null in the first place. |
Set owner to @rakudrama. |
Issue #21684 has been merged into this issue. |
The example given is totally valid. I hit this exact issue in a real project I was prototyping (see Issue #21684). Everything worked fine in Dartium; then when I compiled to JS all of my forms were full of "undefined" strings. Whether assigning null to a textboxes value is a good thing to do or not; the more differences there are between Dartium and "real" browsers, the more frustrating and expensive development with Dart will be. We're starting to see that we just can't trust how things work in Dartium; and that's going to be a serious barrier to adoption. |
It seems reasonable that we could force this to be an error in Dartium without impacting dart2js performance. |
How? |
I meant to add null-checks in Dartium for these sorts of APIs. So rather than just converting null to an empty string it would throw. |
Dart does not have the notion of an undefined value and dart2js uses both undefined and null in JavaScript to represent the Dart null. This works fine within code generated by dart2js but breaks on the boundary to the DOM. Depending on how a value is assigned, different results are produced.
An example using an input field:
var e = new TextInputElement();
e.value = null; // null value
print(e.value); // prints "" (empty string)
var e = new TextInputElement();
var list = new List(5);
e.value = list[0]; // null value
print(e.value); // prints "undefined"
The text was updated successfully, but these errors were encountered: