[html] cleanup JS types

This ensures JS calls in the SDK are statically typed (or, at least, don't
inadvertently trigger dynamic calls).

Analyzer has a hack where `JS('String', ...)` is typed as `String`.  Kernel
doesn't, but we get the same effect (in DDK) via `JS<String>('String', ...)`.

This should not affect dart2js which specially interprets the type string
itself.

Change-Id: I63c5f199e2c51da2beca72659261acf1faff66e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112937
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Vijay Menon <vsm@google.com>
This commit is contained in:
Vijay Menon
2019-08-14 18:02:09 +00:00
committed by commit-bot@chromium.org
parent 2ea18498e9
commit 1eaa7d2902
7 changed files with 56 additions and 59 deletions
@@ -106,10 +106,7 @@ library dart._foreign_helper;
*/
// Add additional optional arguments if needed. The method is treated internally
// as a variable argument method.
// TODO(vsm): Enforce that this doesn't fall back to dynamic by typing it as:
// `T JS<T extends Object>(...)`
// once we clean up html libraries.
T JS<T>(String typeDescription, String codeTemplate,
T JS<T extends Object>(String typeDescription, String codeTemplate,
[arg0,
arg1,
arg2,
+28 -25
View File
@@ -13273,28 +13273,28 @@ class Element extends Node
final Element offsetParent;
int get offsetHeight => JS('num', '#.offsetHeight', this).round();
int get offsetHeight => JS<num>('num', '#.offsetHeight', this).round();
int get offsetLeft => JS('num', '#.offsetLeft', this).round();
int get offsetLeft => JS<num>('num', '#.offsetLeft', this).round();
int get offsetTop => JS('num', '#.offsetTop', this).round();
int get offsetTop => JS<num>('num', '#.offsetTop', this).round();
int get offsetWidth => JS('num', '#.offsetWidth', this).round();
int get offsetWidth => JS<num>('num', '#.offsetWidth', this).round();
int get scrollHeight => JS('num', '#.scrollHeight', this).round();
int get scrollLeft => JS('num', '#.scrollLeft', this).round();
int get scrollHeight => JS<num>('num', '#.scrollHeight', this).round();
int get scrollLeft => JS<num>('num', '#.scrollLeft', this).round();
set scrollLeft(int value) {
JS("void", "#.scrollLeft = #", this, value.round());
}
int get scrollTop => JS('num', '#.scrollTop', this).round();
int get scrollTop => JS<num>('num', '#.scrollTop', this).round();
set scrollTop(int value) {
JS("void", "#.scrollTop = #", this, value.round());
}
int get scrollWidth => JS('num', '#.scrollWidth', this).round();
int get scrollWidth => JS<num>('num', '#.scrollWidth', this).round();
// To suppress missing implicit constructor warnings.
factory Element._() {
@@ -28848,14 +28848,14 @@ class Touch extends Interceptor {
// As of Chrome 37, these all changed from long to double. This code
// preserves backwards compatibility for the time being.
int get __clientX => JS('num', '#.clientX', this).round();
int get __clientY => JS('num', '#.clientY', this).round();
int get __screenX => JS('num', '#.screenX', this).round();
int get __screenY => JS('num', '#.screenY', this).round();
int get __pageX => JS('num', '#.pageX', this).round();
int get __pageY => JS('num', '#.pageY', this).round();
int get __radiusX => JS('num', '#.radiusX', this).round();
int get __radiusY => JS('num', '#.radiusY', this).round();
int get __clientX => JS<num>('num', '#.clientX', this).round();
int get __clientY => JS<num>('num', '#.clientY', this).round();
int get __screenX => JS<num>('num', '#.screenX', this).round();
int get __screenY => JS<num>('num', '#.screenY', this).round();
int get __pageX => JS<num>('num', '#.pageX', this).round();
int get __pageY => JS<num>('num', '#.pageY', this).round();
int get __radiusX => JS<num>('num', '#.radiusX', this).round();
int get __radiusY => JS<num>('num', '#.radiusY', this).round();
Point get client => new Point(__clientX, __clientY);
@@ -30617,8 +30617,11 @@ class Window extends EventTarget
void _cancelAnimationFrame(int id) native;
_ensureRequestAnimationFrame() {
if (JS('bool', '!!(#.requestAnimationFrame && #.cancelAnimationFrame)',
this, this)) return;
if (JS<bool>(
'bool',
'!!(#.requestAnimationFrame && #.cancelAnimationFrame)',
this,
this)) return;
JS(
'void',
@@ -32110,9 +32113,9 @@ class Window extends EventTarget
return db;
}
int get pageXOffset => JS('num', '#.pageXOffset', this).round();
int get pageXOffset => JS<num>('num', '#.pageXOffset', this).round();
int get pageYOffset => JS('num', '#.pageYOffset', this).round();
int get pageYOffset => JS<num>('num', '#.pageYOffset', this).round();
/**
* The distance this window has been scrolled horizontally.
@@ -32124,8 +32127,8 @@ class Window extends EventTarget
* * [scrollX](https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollX)
* from MDN.
*/
int get scrollX => JS('bool', '("scrollX" in #)', this)
? JS('num', '#.scrollX', this).round()
int get scrollX => JS<bool>('bool', '("scrollX" in #)', this)
? JS<num>('num', '#.scrollX', this).round()
: document.documentElement.scrollLeft;
/**
@@ -32138,8 +32141,8 @@ class Window extends EventTarget
* * [scrollY](https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollY)
* from MDN.
*/
int get scrollY => JS('bool', '("scrollY" in #)', this)
? JS('num', '#.scrollY', this).round()
int get scrollY => JS<bool>('bool', '("scrollY" in #)', this)
? JS<num>('num', '#.scrollY', this).round()
: document.documentElement.scrollTop;
}
@@ -32154,7 +32157,7 @@ class _BeforeUnloadEvent extends _WrappedEvent implements BeforeUnloadEvent {
_returnValue = value;
// FF and IE use the value as the return value, Chrome will return this from
// the event callback function.
if (JS('bool', '("returnValue" in #)', wrapped)) {
if (JS<bool>('bool', '("returnValue" in #)', wrapped)) {
JS('void', '#.returnValue = #', wrapped, value);
}
}
+2 -2
View File
@@ -237,9 +237,9 @@ abstract class _AcceptStructuredClone {
}
if (isJavaScriptArray(e)) {
var l = JS('returns:List;creates:;', '#', e);
var l = JS<List>('returns:List;creates:;', '#', e);
var slot = findSlot(l);
var copy = JS('returns:List|Null;creates:;', '#', readSlot(slot));
var copy = JS<List>('returns:List|Null;creates:;', '#', readSlot(slot));
if (copy != null) return copy;
int length = l.length;
@@ -87,7 +87,6 @@
"Dynamic access of 'firstChild'.": 2,
"Dynamic invocation of 'append'.": 1,
"Dynamic access of 'tagName'.": 2,
"Dynamic invocation of 'round'.": 20,
"Dynamic invocation of 'call'.": 1,
"Dynamic invocation of 'dart.dom.html::_initKeyboardEvent'.": 1,
"Dynamic access of 'attributes'.": 1,
@@ -99,9 +98,7 @@
"Dynamic invocation of 'createElement'.": 1
},
"org-dartlang-sdk:///sdk/lib/html/html_common/conversions.dart": {
"Dynamic invocation of '[]='.": 2,
"Dynamic access of 'length'.": 1,
"Dynamic invocation of '[]'.": 1
"Dynamic invocation of '[]='.": 1
},
"org-dartlang-sdk:///sdk/lib/html/html_common/filtered_element_list.dart": {
"Dynamic invocation of 'remove'.": 1
@@ -1492,28 +1492,28 @@ $(ANNOTATIONS)$(NATIVESPEC)class $CLASSNAME$EXTENDS$IMPLEMENTS {
final Element offsetParent;
int get offsetHeight => JS('num', '#.offsetHeight', this).round();
int get offsetHeight => JS<num>('num', '#.offsetHeight', this).round();
int get offsetLeft => JS('num', '#.offsetLeft', this).round();
int get offsetLeft => JS<num>('num', '#.offsetLeft', this).round();
int get offsetTop => JS('num', '#.offsetTop', this).round();
int get offsetTop => JS<num>('num', '#.offsetTop', this).round();
int get offsetWidth => JS('num', '#.offsetWidth', this).round();
int get offsetWidth => JS<num>('num', '#.offsetWidth', this).round();
int get scrollHeight => JS('num', '#.scrollHeight', this).round();
int get scrollLeft => JS('num', '#.scrollLeft', this).round();
int get scrollHeight => JS<num>('num', '#.scrollHeight', this).round();
int get scrollLeft => JS<num>('num', '#.scrollLeft', this).round();
set scrollLeft(int value) {
JS("void", "#.scrollLeft = #", this, value.round());
}
int get scrollTop => JS('num', '#.scrollTop', this).round();
int get scrollTop => JS<num>('num', '#.scrollTop', this).round();
set scrollTop(int value) {
JS("void", "#.scrollTop = #", this, value.round());
}
int get scrollWidth => JS('num', '#.scrollWidth', this).round();
int get scrollWidth => JS<num>('num', '#.scrollWidth', this).round();
$!MEMBERS
}
@@ -9,14 +9,14 @@ $!MEMBERS
// As of Chrome 37, these all changed from long to double. This code
// preserves backwards compatibility for the time being.
int get __clientX => JS('num', '#.clientX', this).round();
int get __clientY => JS('num', '#.clientY', this).round();
int get __screenX => JS('num', '#.screenX', this).round();
int get __screenY => JS('num', '#.screenY', this).round();
int get __pageX => JS('num', '#.pageX', this).round();
int get __pageY => JS('num', '#.pageY', this).round();
int get __radiusX => JS('num', '#.radiusX', this).round();
int get __radiusY => JS('num', '#.radiusY', this).round();
int get __clientX => JS<num>('num', '#.clientX', this).round();
int get __clientY => JS<num>('num', '#.clientY', this).round();
int get __screenX => JS<num>('num', '#.screenX', this).round();
int get __screenY => JS<num>('num', '#.screenY', this).round();
int get __pageX => JS<num>('num', '#.pageX', this).round();
int get __pageY => JS<num>('num', '#.pageY', this).round();
int get __radiusX => JS<num>('num', '#.radiusX', this).round();
int get __radiusY => JS<num>('num', '#.radiusY', this).round();
Point get client => new Point(__clientX, __clientY);
@@ -129,7 +129,7 @@ $(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
void _cancelAnimationFrame(int id) native;
_ensureRequestAnimationFrame() {
if (JS('bool',
if (JS<bool>('bool',
'!!(#.requestAnimationFrame && #.cancelAnimationFrame)', this, this))
return;
@@ -241,9 +241,9 @@ $!MEMBERS
return db;
}
int get pageXOffset => JS('num', '#.pageXOffset', this).round();
int get pageXOffset => JS<num>('num', '#.pageXOffset', this).round();
int get pageYOffset => JS('num', '#.pageYOffset', this).round();
int get pageYOffset => JS<num>('num', '#.pageYOffset', this).round();
/**
* The distance this window has been scrolled horizontally.
@@ -255,8 +255,8 @@ $!MEMBERS
* * [scrollX](https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollX)
* from MDN.
*/
int get scrollX => JS('bool', '("scrollX" in #)', this) ?
JS('num', '#.scrollX', this).round() :
int get scrollX => JS<bool>('bool', '("scrollX" in #)', this) ?
JS<num>('num', '#.scrollX', this).round() :
document.documentElement.scrollLeft;
/**
@@ -269,8 +269,8 @@ $!MEMBERS
* * [scrollY](https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollY)
* from MDN.
*/
int get scrollY => JS('bool', '("scrollY" in #)', this) ?
JS('num', '#.scrollY', this).round() :
int get scrollY => JS<bool>('bool', '("scrollY" in #)', this) ?
JS<num>('num', '#.scrollY', this).round() :
document.documentElement.scrollTop;
}
@@ -285,7 +285,7 @@ class _BeforeUnloadEvent extends _WrappedEvent implements BeforeUnloadEvent {
_returnValue = value;
// FF and IE use the value as the return value, Chrome will return this from
// the event callback function.
if (JS('bool', '("returnValue" in #)', wrapped)) {
if (JS<bool>('bool', '("returnValue" in #)', wrapped)) {
JS('void', '#.returnValue = #', wrapped, value);
}
}