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

dart:js library doesn't work in Dartium #13215

Closed
skybrian opened this issue Sep 10, 2013 · 7 comments
Closed

dart:js library doesn't work in Dartium #13215

skybrian opened this issue Sep 10, 2013 · 7 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant library-js type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@skybrian
Copy link

== jstest.html ==
<!DOCTYPE html>
<html>
  <head>
    <title>jstest</title>
  </head>

  <body>
    <script type="application/dart" src="jstest.dart"></script>
    <script src="packages/browser/dart.js"></script>
  </body>
</html>

== jstest.dart ==
library jstest;

import 'dart:js' as js;

main() {
  print("main called");
  js.context.callMethod("alert", ["hello"]);
  print("main done");
}

== output in Dartium ==
main called
Breaking on exception: The null object does not have a method 'callMethod'.

Exception: The null object does not have a method 'callMethod'.

NoSuchMethodError : method not found: 'callMethod'
Receiver: null
Arguments: ["alert", GrowableObjectArray len:1]
  Object.noSuchMethod (dart:core-patch/object_patch.dart:20:25)
  main (http://127.0.0.1:3030/Users/skybrian/dart/bugtest/web/jstest.dart:7:24)
  main (http://127.0.0.1:3030/Users/skybrian/dart/bugtest/web/jstest.dart:7:24)

== output in JavaScript ==
main called
main done

Dart Editor version 0.7.1_r27025
Dart SDK version 0.7.1.0_r27025

@skybrian
Copy link
Author

Looks like the issue is that I left out a script tag:

 <script src="packages/browser/interop.js"></script>

The documentation for 'package:js/js.dart' explains this, but the 'dart:js' library's documentation doesn't.

(Also, perhaps improve the error message for this case?)

@skybrian
Copy link
Author

Additional issues:
  - The documentation refers to features that are aren't in this library. For example, Callback.once doesn't exist.
  - It looks like there's no longer a way to free a proxy?
  - Contrary to the documentation, DOM nodes can't be passed between Dart and JavaScript. (They end up as Dart proxies and JS proxies.)
 
Also, a feature request: instead of:

   var jsElt = js.context["document"].callMethod("getElementById", [id]);

It seems like it might be nice to write it as:

  var jsElt = js.context.callMethod("document.getElementById", [id]);

This might even be more efficient, since there would only be one round trip and no intermediate proxies would need to be created. Perhaps array access could be implemented as well, sort of like using query() to find a DOM node.

(I can break those out into bugs if needed, but it sounds like this library is going to change anyway.)

@dgrove
Copy link
Contributor

dgrove commented Sep 11, 2013

Set owner to @justinfagnani.
Added Area-Library, Triaged labels.

@DartBot
Copy link

DartBot commented Sep 11, 2013

This comment was originally written by @a14n


Comments on your additional issues :
 - There are some CL which are waiting before cleaning the doc.
 - One goal of "dart:js" was to get rid of scopes. However in Dartium this will cause memory leaks for now.
 - Unlike package:js the DOM nodes are not directly converted between Dart and JS (that has been done to reduce the generated js output)

On your feature request : with this syntax there could be some edge cases to handle. For instance if a "document.getElementById" variable had been defined ( e.g. window["document.getElementById"] = function(){return 1;}; ). Perhaps something like js.context.callMethodOn(["a", "b", "c"], methodName, args) for a.b.c.methodName(args).

There is also a CL to add Array support that is waiting to be merged (https://chromiumcodereview.appspot.com/23291005/).

@lrhn
Copy link
Member

lrhn commented May 5, 2014

Added Library-JS label.

@sethladd
Copy link
Contributor

Hi,

Is this issue still valid?

@justinfagnani
Copy link
Contributor

The original bug? no.

There is a possible feature request with passing path/index expressions to callMethod().

@skybrian skybrian added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-js labels Aug 20, 2014
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant library-js type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

8 participants