I'm using VS Code with AngularDart. I need to see, what values are inside some variables. Usually one can do that, by setting a breakpoint. But the debugger doesn't seem to work for web projects.
What's the best way to analyse the contents of my variables? How can I do that? Is this a feature that is supported in Webstorm?
I'm using 5.0.0 and Dartium doesn't seem to be supported anymore.
When you use Dart Dev Compiler (DDC) you can use chrome devtools as you would debug any other scripts on the page. The DDC provides source maps so that you can debug the Dart code you would expect, even though DDC is really providing JS underneath.
Related
In ruy on rails in order to debug the application you could just call, "debugger", and
it will start a debugger in the console. How is this approach possible in Grails? Especially in a .gsp file? I am using a simple text editor for my development, Sublime.
Thanks
Debugging java is simply not possible in Sublime.You can use another debugger like JDebugTools or a full-featured IDE like Eclipse or Netbeans (but that breaks the whole point to have a lightweight IDE like Sublime, which is great for Java, if not for debugging purpose)
There exists a command-line debugging tool, jdb which can be used for very simple debugging purposes, and may be integrated as a build tool for Sublime (I don't think the result will be good though)
Debugging for Grails is done with the --debug switch as for recent versions, you can then attach a debugger to the session. GSP debugging, like JSP, needs a specific tooling as to be aware of compilation means, and you'd better switch to IntelliJ Idea or [GGTS (Groovy/Grails Tool Suite)](http://spring.io/tools/ggts) which provide both strong debugging capabilities
I cannot find the reason why my app does not work when compiled to JavaScript using dart2js. I have tried debugging my compiled JavaScript app using Google DevTools but found it very difficult to understand both the debugger and JavaScript code. You can find my web app on GitHub. I suspect there is a conflict between compiled JavaScript code and imported third party JS libraries such as jquery but not sure. I highly appreciate your help.
The easiest is probably to add a few print statements into your code. With binary search it should be relatively easy to figure out when the VM and dart2js diverge.
Please report back, what the reason was and/or file a bug at http://dartbug.com/ if you believe that dart2js did it wrong.
Solution (as reported by OP): "dart.js should come after [the] app script line".
Is there a REPL for Dart to experiment with?
I tried inputing dart code in DevTools in Dartium and that also didn't work.
So I couldn't find an easy way to play with various APIs in dart.
I tried inputing dart code in devtools in Dartium and that also didn't
work.
I'm very new to Dart, but something I came across was that you CAN evaluate code in Dartium. In order to do so, you must first load a page with Dart code in it and then toggle this selector in the console from "javascript page context" to one that references a Dart package or Dart code.
Once you do that you should be able to execute Dart in the console:
As a VIM user, I hardly have to open the Dart Editor now :). I should also mention that breakpoints, hovering over stepped into code to get variable details, navigating the call stack, and some level of intellisense in the console also work. I couldn't get conditional breakpoints to work, though.
Though it is not really a REPL, you may find the Try Dart online tool useful for playing around. It's a bit slow, since it is actually compiling the Dart code to JavaScript in order to have it work within the browser.
There is also a console that someone built, which is probably better if you're looking for a real REPL, but it requires a bit of setup.
There is an announcement about REPL for Dartium - see Nathanial's comment below. There are plans for Smalltalk like super-REPL. Here is what Gilad Bracha (member of the Dart team at Google) wrote on this subject in Is there a REPL or console for Dart:
"I don't see this as a language question at all. It is a matter of tooling and reflective library support. With proper mirror builder APIs, building a REPL would be trivial. As it sands right now, it can be quite challenging. And of course, REPL is not the ultimate goal - there are more advanced interactive tools, like workspaces in Smalltalk/Self/Newspeak, where you not only evaluate things interactively at some top level, but can inspect the resulting objects, evaluate within the scope of an individual declaration or object etc. I am sure we will get there in time - and i much prefer sooner than later."
The correct answer is https://dartpad.dev/
That site didn't exist when the other answers were posted in 2013, but you've stumbled on this post after 2020. And now you know. https://dartpad.dev allows you to create and share new Dart snippets and even put them in a Flutter app running online. Very, very cool!
Since 2022.10.22, there is a REPL for Dart: https://github.com/fzyzcjy/dart_interactive :)
Features:
Use any third-party package freely
Auto hot-reload code anywhere, with state preserved
Supports full grammar in REPL
Play with existing code side-by-side
Disclaimer: I wrote that package.
I am running the latest Chromium build, with the Dart VM. I would like to start playing with Dart's HTML library by messing around with websites, using the Console to enter Dart commands. Obviously, this is easy with Javascript, but I can't work out how to tell the console that I am entering Dart, not JS.
Is this possible?
It is not. I actually requested this feature on the bug tracker a while back but I can't seem to find it. IIRC, it has to do with the fact that you'd have to be running the code within a particular isolate, which at the moment is not possible. In javascript, everything is global so there is a fundamental difference.
It is possible if it has the Dart VM... I run Dartium but I guess that it can be similar!
https://drive.google.com/file/d/0B1XajbEHFd35OFRJSU5hR0FPZlE/edit?usp=sharing
You have to change in the context menu.
If this answer doesn't work for you I'm sorry...
I have played a little with Dart and I think it's great. I understand that it can output native JS and that the VM will likely be supported by Google in their browser. As it is possible that other browser suppliers won't support the Dart VM, is it at all possible to install the Dart VM on client machines for use in foreign browsers?
is it at all possible to install the Dart VM on client machines for use in foreign browsers?
It is, however it is easier to supply the Dart VM yourself.
Javascript is perfectly able to:
Find a script of a specific type
Convert the script into Javascript
Execute the compiled script
While this is technically not a Dart Virtual Machine, it will get your Dart code executed at full speed. However, you do have to wait for the compilation to complete. The usual way is to do the compilation on the server (once), and only send the compiled javascript to clients.
Another option is interpreted code. Instead of compiling to javascript, the Dart instructions are executed one-by-one. Dart is not a machine-level language, so it needs parsing, but what follows is interpretation. The downside is reduced performance. This will get you as close to having a full-blown virtual machine (separate from the Javascript one) as possible.
Normally, you don't care which one you get (maybe you'll even get a just-in-time compiler), but it does make a difference in terms of a Dart virtual machine being present (rather than just getting your code executed).
The Dart compiler needs to be present on the page somehow (unless you precompile).
The easiest way is to just write <script src="path/to/your/dart-compiler.js"></script> into the head.
The Dartium browser does support Dart natively, but it is not designed for common use. Wikipedia says:
In the Dartium Browser: The Dart SDK ships with a version of the Chromium web browser modified to include a Dart virtual machine. This browser can run Dart code directly without compilation to Javascript. It is currently not intended for general-purpose use, but rather as a development tool for Dart applications.[7] When embedding Dart code into web apps, the current recommended procedure is to load a bootstrap JavaScript file, "dart.js", which will detect the presence or absence of the Dart VM and load the corresponding Dart or compiled Javascript code, respectively,[8] therefore guaranteeing browser compatibility with or without the custom Dart VM.
If you want the ability to run Dart be dependent on the client machine rather than on the page, there are a few ways too.
One way is to include the compiler as a user-script. This will work in all both modern desktop browsers. However, I'm not sure if there's an existing way to add user-script support to Internet Explorer.
One way is to add a browser extension. All modern desktop browsers support extensions, and Internet Explorer has Browser Helper Objects.
All of these will require the extra Javascript step. If you want native interpretation that bypasses Javascript, you need a plugin. Plugins require a specific mime-type to run (not sure if the script type counts), but you can install an extension that will trigger the use of the plugin. However, DOM manipulation still needs the extra Javascript step. There is no way around it.
A desktop installer can definitely install a plugin into a browser. Indeed, this is the way plugins normally get installed. Installing extensions from a desktop installer might be possible as well, but I can't confirm or deny this last claim for now.
As far as I know there is no way to just simply install a plugin (like Flash) for Dart. For Internet Explorer one could install Chrome-frame, but I haven't seen something similar for Firefox and Safari.