UglifyJS2 call minify function programmatically - uglifyjs2

I would like to know if I can call the minify main function programmatically.
I am able to run the same code as defined in compress, however replacing UglifyJS.Compressor with UglifyJS.minify does not work.
This is because I would like to pass the same options defined in the README of UglifyJS2, instead of the ones in compress.
Please note that I am running the code in Nashorn, and not in Node.js so that would be similar to a browser environment.

This is a work in progress: see this issue and this PR.

Related

Electrolysis compatibility shims doesn't work with evalInSandbox

We have a rather old XUL extension which we want to make sure works with Electrolysis. We will eventually migrate it to the WebExtensions API, but for now we want to use the compatibility shims.
We can access content stuff (using window.content for example) in the some of our scripts (e.g, the overlay scripts). However, our extension also load some scripts using evalInSandbox. It look something like this:
var sandbox = Components.utils.Sandbox(Components.classes["#mozilla.org/systemprincipal;1"].createInstance(Components.interfaces.nsIPrincipal), {
sandboxPrototype: window,
wantXrays: false
});
// ...
Components.utils.evalInSandbox(script, sandbox, url, 0);
We don't seem to be able to access window.content on the scripts loaded in the sandbox. It seem like the shims don't work in this case. Is this a bug, or is it by design?
Thanks
Your sandboxPrototype is wrong, you are setting it to the nsIDOMWindow, set it to the aNSIDOMWindow.gBrowser.tabContainer.childNodes[tab_index_goes_here].contentWindow
see this example on mdn: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.Sandbox#Example
also here is how to load in a script as file rather then doing evalInSandbox:
https://github.com/Noitidart/modtools

Can we add custom action to HtmlLoggerState

I'm using VS2013/CodedUI and my palybacksetting is as follow:
Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;
I also have a 3rd party tool that I have integrated to my code that does some action that codedui can't...Iw an to be able to log those steps into the ActionLog.html file with where codedui capture the actions and screenshot.
I searched a lot but didn't find anything on how we can achieve this.
thanks in advance for any help
I posted a response over here: Writing Custom HTML Logs
It sounds like there's not a good way to do this. You can get the path to where the html file lives and write a custom logger from there. I'm not sure it'd be safe to try and write to it while your test is executing, but perhaps once your test is complete.

Using Closure Stylesheets with Plovr in serve mode

i am using plovr for developing a closure application. and that i am often using plovr in serve mode. from this source code of plovr and this post from the author it seems that plovr also supports compiling closure stylesheets (gss).
with that in mind, i am specifying the bare minimum in my plovr config file to get this working. but can't figure out what url i should use in my page to load the compiled css.
for example, while plovr is running the compiled js can be fetched with
http://localhost:9810/compile?id=project_id
i guess fetching the compiled css can be done with something like the following:
http://localhost:9810/view?id=project_id&name=output.css
but unfortunately can't figure out the right documentation for it. what is the approach to achieve this?
also is it possible to make use of the css class name renaming feature through plovr?
http://localhost:9810/css/project_id/
did the trick. looks like i need not specify the output css file name.

excluding files with guard-jasmine while running coverage

I am using guard-jasmine create coverage reports for my javascript app written with backbone js. I would like to exclude the template files from being included in the coverage. Is there a way to do this currently? I have also tried looking through the source and passing the -x option to the intrument command in the coverage.rb file but that doesn't seem to help at all. Any pointers would be appreciated.
Thanks!
There is currently no way of configuring Guard::Jasmine to skip specific files from generating the coverage.
A possible way to add this would be to add something like a coverage_skip option that contains a regex to check it as a preconodition in the coverage tilt template:
return data if file =~ ENV['COVERAGE_SKIP']
Since we do not have access to the Guard::Jasmine options, we need to set it as an environment variable in the server process.
A pull request is heartly welcome ;)

How to obtain firefox user agent string?

I'm building an add-on for FireFox that simulates a website, but running from a local library. (If you want to know more, look here)
I'm looking for a way to get a hold of the user-agent string that FireFox would send if it were doing plain http. I'm doing the nsIProtocolHandler myself and serve my own implementation of nsIHttpChannel, so if I have a peek at the source, it looks like I'll have to do all the work myself.
Unless there's a contract/object-id on nsHttpHandler I could use to create an instance just for a brief moment to get the UserAgent? (Though I notice I'll need to call Init() because it does InitUserAgentComponents() and hope it'll get to there... And I guess the http protocol handler does the channels and handlers so there won't be a contract to nsHttpHandler directly.)
If I have a little peek over the wall I notice this globally available call ObtainUserAgentString which does just this in that parallel dimension...
Apparently Firefox changed how this was done in version 4. Have you tried:
alert(window.navigator.userAgent);
You can get it via XPCOM like this:
var httpHandler = Cc["#mozilla.org/network/protocol;1?name=http"].
getService(Ci.nsIHttpProtocolHandler);
var userAgent = httpHandler.userAgent;
If for some reason you actaully do need to use NPAPI like you suggest in your tags, you can use NPN_UserAgent to get it; however, I would be shocked if you actually needed to do that just for an extension. Most likely Anthony's answer is more what you're looking for.

Resources