-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
JS MouseEvent unexpectedly converted to Dart MouseEvent in interop #15216
Comments
This comment was originally written by @rbishop-bah event.clientX also fails if I put it in the initial closure, so passing the proxy to another method is not the issue. |
This comment was originally written by @rbishop-bah Upon further investigation, this appears to be the result of an unexpected (?) auto-conversion of a JavaScript MouseEvent to a Dart MouseEvent. Sequence of events:
void on(String str, OnCallback func) { where OnCallback is defined as: typedef OnCallback(event, item); * The callback function is executed -- after a mouse click, for example -- and its event is actually (unexpectedly to me) a Dart MouseEvent and not a proxy to a JavaScript MouseEvent. * Downstream processing of the event that assumes it's handling a Proxy to a JS MouseEvent crashes (in compiled JS as described above). So at some point the _proxy processes the JS mouse event and it gets auto converted to a Dart mouse event before the callback is executed. Armed with this knowledge I have devised successful workarounds -- testing whether the event in the callback is a Dart MouseEvent before assuming it's a proxy to a JS MouseEvent and processing accordingly. But this is kind of confusing. Is this a bug? If it's not what are the rules for the types in JS callbacks (is there a set of types that get auto-converted from JS to Dart)? |
This comment was originally written by @zoechi I don't know if this changes anything but clientX is deprecated and replaced by client.x |
Removed Area-HTML label. |
Given the further investigation in #2 this seems like a question for dart:js more than for dart:html. This may be stale, given that js.Proxy no longer exists, but I don't know enough about it to say. Removed Library-Html label. |
This issue was originally filed by @rbishop-bah
What steps will reproduce the problem?
What is the expected output? What do you see instead?
I want clientX's value. I get an error.
What version of the product are you using? On what operating system?
Dart SDK 1.0.0.7, Win7x64
Please provide any additional information below.
Same error on both Chrome and Firefox. Here's the relevant Dart, then the JavaScript, then the error:
========================
Dart
_view.on("mousedown", (js.Proxy event, js.Proxy object) {
handleMouseDown(event, object);
});
void handleMouseDown(js.Proxy event, js.Proxy item) {
... some logic
_dragStartClientX = event.clientX;
========================
JavaScript
Thing_initView_closure2: {"": "Closure;this_3-",
call$2: function($event, object) {
this.this_3.handleMouseDown$2($event, object);
"281,520,147,282,147";
},
"+call:2:0": 1,
$isFunction: true,
$is_args2: true
},
_________
handleMouseDown$2: function($event, item) {
/// some other logic, blah blah
this._dragStartClientX = $event.get$clientX();
// etc.
}
Running in JavaScript in Chrome or FireFox yields this error:
TypeError {stack:
"TypeError: Object #<Object> has no method 'get$clientX'
at Thing.handleMouseDown$2 (https://localhost/redacted/index.html_bootstrap.dart.js:161114:39)
...
If I poke around in Chrome's Watch Expressions I can see that:
$event: GenericEvent
$event.clientX: 333
$event.get$clientX(): <not available> <===== THIS IS WHAT COMPILED CODE USES
$event.get$clientX: undefined
$event.clientX(): <not available>
$event.impl.clientX: 333
$event.impl.get$clientX(): <not available>
The text was updated successfully, but these errors were encountered: