Implement Console tab support with Rhino #188
Conversation
@@ -28,10 +36,33 @@ public void onCreate() { | |||
|
|||
long startTime = SystemClock.elapsedRealtime(); | |||
final Context context = this; | |||
|
|||
// Setup a javascript runtime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err, accidentally commented on the diff previously. Let's try to simplify this boilerplate (possibly with an Android-specific helper?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only 2 lines are mandatory:
JavaScriptRuntimeBuilder jsRuntimeBuilder = new JavaScriptRuntimeBuilder(context);
Stetho.newInitializerBuilder(context).enableWebKitInspector(jsRuntimeBuilder.javaScriptInspectorModulesProvider());
The other lines where adding to show everything that can be done:
- import a class
- import a package
- add a variable
- add a custom function
What I should do instead is to add these code snippets to the documentation. Let me rework the patch with documentation & screenshots. I'll also comment on the dex increase, apk size, proguard settings.
Can you post a screenshot or a sample session that shows what you can do with this? I'm also interested in how large the dependencies are (how big is the sample APK with this change)? |
Ok, I have updated my repository with a new branch. See the branch https://github.com/potyl/stetho/commits/stetho/repl-js. The integration in the sample app is kept to a bare minimum. I have added a dedicated stetho-repl-js readme for the plugin. In thee i cover examples on how to enhance the runtime, documented the APK file sizes with tips on how to proguard the app. I also have a branch that adds this screenshot to the gh-pages, see https://github.com/potyl/stetho/tree/gh-pages. |
Wow, amazing. A whopping 1.2MB jar file though, but as it is optional I think we can definitely work with that. This PR is based off your repl branch, not repl-js. Was that on purpose? I'd like to put comments on an actual PR instead of the diffs since it's easier to manage through the review. |
I've changed the branch so that the old one would still be present just in case. For now i wanted to have your opinion. I see that i forgot to add the APK sizes, I'l add that to my documentation. I will do a reset --hard to the original branch of the PR. As you mentioned the APK does take a load with the javascript REPL, i would suggest that we keep it optional. For instance in our main app at work I can't enable the module since it busts the dex count even with proguard :/ |
I have updated the read me to include apk sizes and tweaked a bit the documentation. The branch stetho/repl is now final. I'm waiting for your comments. |
Can you take a look at the Travis CI failures? Looks like simple lint errors which you can see locally by checking out the XML report generated by |
I pushed a fix to lint. I don't understand why my branch still fails. The error i get is for:
Which is triggered by:
But all the other projects have |
Any news on this pull request? |
public class MyApplication extends Application { | ||
public void onCreate() { | ||
super.onCreate(); | ||
JavaScriptRuntimeBuilder jsRuntimeBuilder = new JavaScriptRuntimeBuilder(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: would be nice if you bolded the lines that are unique to the repl-js integration. Not 100% sure what that syntax is tho when inside a preformatted code block...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I've read there's not that much that we can do in code blocks besides selecting the language. I'll try to see if I can use a table with the original block on the left and the modified block on the right.
If it would work i could mimic the output of sdiff and it will help to understand what was added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we should do this construction lazily inside the inspector modules provider. The intention of this awkward interface is to make it so that Stetho.initialize does no real work at all until a client actually connects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't bother re the formatting. It's not that important :)
Object result; | ||
final Context jsContext = enterJsContext(); | ||
try { | ||
result = jsContext.evaluateString(mJsScope, expression, "chrome", 1, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "chrome" mean here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"chrome" is the "file name" and 1 is the line number. Remember this is a JS interpreter, in case where it would find an error parsing the JS string the interpreter wants to show a nice error message such as: "compilation error in chrome
(this would be afile name) at line 1 + $lineno
"
So we need to tell the interpreter the name of the "file" and at which line number to start counting lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack'd, sounds good. It does appear in multiple places though so I'd prefer if it were centralized in a named constant somewhere.
Sorry for the review delay, I've been focusing on a big thorn in my side: #197 :) |
Do you mind changing the PR title to something more descriptive like "Implement Console tab support with Rhino"? Makes things nicer when it gets merged :) |
Any more updates? I think with the latest round of feedback implemented this should be merge-able. |
I didn't finish going through all comments/remarks. Let me review the branch this evening and merge the commits. I now have a bit more free time and I can work on this. |
Ok, I've rebased all my changes and removed the commit that modifies stetho-sample so that it doesn't use the javascript repl (I believe that this was requested at some point). Code can still be improved at some point:
I still believe that as a preview the current basis is solid enough to be used, so we could merge this. |
Oh I see, you actually changed the branch. It looks like you're really expecting to merge https://github.com/potyl/stetho/tree/stetho/js-rhino, is that right? If so, can you just push to the original |
My bad! Once I get home i'll update the proper branch On Friday, July 17, 2015, Josh Guilfoyle notifications@github.com wrote:
Emmanuel Rodriguez |
I've pushed to the proper branch. Turns out that I also confused the commits and I previously left the commit to add the javascript to the stetho-sample app and removed the documentation on how to integrate it. This is also now corrected in the stetho/repl branch. |
```xml | ||
<dependency> | ||
<groupId>com.facebook.stetho</groupId> | ||
<artifactId>stetho-repl-js</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be stetho-js-rhino
Very minor documentation comments; this is otherwise ready to merge. Great work, I'm so excited for this feature! |
This is a first draft at adding a REPL. What works: - basic JS expressions - evaluatied statements preserve their states (can create a variable and it will persist between successive calls) - return types are properly expanded by chrome's inspector - binding of android's Context (passed as `context`) - binding for classes: `System.gc()` is `Packages.java.lang.System.gc()` - console redirection with `console.log()` - `importPackage()` to import all classes under a java package - `importClass()` to import a single class - binding variables - binding functions For more details see: - https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java - https://developer.mozilla.org/en-US/docs/Rhino_documentation
Thanks for spotting the 2 documentation errors. I've squashed the fix and ran a grep. No more occurrences of the old repo name. |
Excellent, I'm AFK this weekend but will merge when I get back. Awesome El sáb., 18 de julio de 2015 0:26, Emmanuel Rodriguez <
|
Thanks a lot! |
Implement Console tab support with Rhino
EvaluatorException for sql query is this caused by Rhino? |
This is an implementation of issue #81 using Mozilla's Rhino JavaScript library.