Skip to content
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

Open
ghost opened this issue Nov 10, 2014 · 8 comments
Open

normalize undefined/null on DOM call boundary #21555

ghost opened this issue Nov 10, 2014 · 8 comments
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. library-html type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@ghost
Copy link

ghost commented Nov 10, 2014

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"

@rakudrama
Copy link
Member

This example is slightly bogus.
If we could do so, we would improve on the JS DOM and declare TextInputElement.value as a non-nullable String.
To see this, consider it is not possible to load the value fields and get something that is not a String. Converting null and undefined are in the same category of crazy JavaScript conversions as converting numbers or objects with a valueOf field.

I am worried about the code size and performance implications of putting conversions on DOM APIs.
It will prevent inlining and cause setters to be encoded as functions rather that fields. We will never match JS performance if we have to insert checks.

Browsers are not totally consistent in their implementation of the standards.

@ghost
Copy link
Author

ghost commented Nov 10, 2014

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.

@ghost
Copy link
Author

ghost commented Nov 14, 2014

Set owner to @rakudrama.

@vsmenon
Copy link
Member

vsmenon commented Nov 21, 2014

Issue #21684 has been merged into this issue.

@DanTup
Copy link
Collaborator

DanTup commented Feb 27, 2015

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.

@alan-knight
Copy link
Contributor

It seems reasonable that we could force this to be an error in Dartium without impacting dart2js performance.

@floitschG
Copy link
Contributor

How?
Dartium doesn't have any null/undefined distinction. It can't warn you when you pass an undefined instead of a null to the DOM.

@alan-knight
Copy link
Contributor

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.

@ghost ghost assigned rakudrama Mar 31, 2015
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed triaged labels Mar 1, 2016
@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. library-html type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

6 participants