XPJS (Javascript XPCOM) Documentation? - javascript

Anyone know where is some usable XPJS, or XPCOM in JS, documentation for recent versions of Firefox/Gecko? And sample code/ tutorials would be great too.
I need to write my own Component, but without .IDL (no C++ compiled interface), so I could access it via
Components.classes['#com.mareksebera/compname;1']
.getService().wrappedJSObject;
or this way is not supported anymore? I can't use
Components.classes['#com.mareksebera/compname;1']
.createInstance(Components.interfaces.nsICompName);
Because of missing compiled interface nsICompName
And yes, I know that NSGetModule is deprecated, and I use NSGetFactory and XPCOMUtils.jsm
I know these, but those are not usable with up to date browsers versions
https://developer.mozilla.org/en/Creating_Custom_Firefox_Extensions_with_the_Mozilla_Build_System
https://developer.mozilla.org/en/Using_XPCOM_in_JavaScript_without_leaking
https://developer.mozilla.org/en/how_to_build_an_xpcom_component_in_javascript

The third link you mentioned is pretty good. Another way to get examples though is to actually download the Mozilla source code and look in the /tests subdirectories. There are some examples there of javascript created XPCOM objects.
One example that comes to mind can be found at:
<mozilla-central>\content\xtf\test\unit
But there are a ton of examples throughout the codebase.
If you prefer you can also browse the code online via mxr.

Related

Typescript: missing lib.d.ts

I recently wrote something in typescript. I used the Set data structure like this
var myset = new Set<string>();
I didn't need to include any extra libraries in Typescript and it just works. However, I found out that this only works in IE, as chrome cannot resolve Set data type. Also, when I publish I didn't see anything like lib.d.ts being included in the folder.
How does this work. I am running into some trouble researching as the word "set" has too many meanings and I can't get any useful search result.
Adding to the other answer, Set is part of the ECMAScript 6 collections API that is not enabled by default in Chrome. You can enable it by checking the "Enable Experimental JavaScript" box in the Chrome chrome://flags page, though you're probably better off just not using Set yet since very few people will have this enabled. It will be more widespread in browsers in a year or two, most likely.
See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
The lib.d.ts file is a Typescript Definition file, and is only needed by the compiler to provide information about external libraries. The file does not contain any browser executable code, only interface and method information for the compiler, therefore it is not needed by the browser, so you will not see it load in the page, or in the published folder contents.
See this link for information on typescript definitions.
Now as far as your problem with the library, this is most likely a problem with the code itself. What library contains this Set object? Is it a third party library, or is it a library written by you?

QuickCheck for Javascript

Is there a version of quickcheck that works for Javascript and that is well maintained? I have found several such as check.js and claire, but none of them seem to support shrinking of failing test cases, which has always struck me as the most useful part of the whole problem.
I'm creator of jsverify. I'll try constantly to make it better, bug reports and feature requests are welcomed.
There are also a list of other javascript generative testing libraries in a readme. So far I haven't found any other good alternative to the jsverify.
I recently released https://github.com/dubzzz/fast-check
I built it in order to answer several limitations I encountered in the existing quickcheck implementations in JavaScript.
It comes natively with a shrink feature which can shrink even combination of arbitraries (the frameworks I tried were failing on oneof like arbitraries).
It also can generate large objects and arrays.
By default it tends to try smaller values first in order to detect trivial edge cases while it covers all the possible inputs in next runs.
Lots of other features are on-going or already available :)
Cheers,
Nicolas
I wrote quick_check.js, which has a nice library of generators. Shrinking is not there yet, but is planned.
There seems to be a dearth of good quickcheck-like testing tools in javascript. However they are to be better supported in typed languages, and in fact you can write your tests in one of those languages if you wish.
To avoid dealing with runtime interop, I'd recommend going with a language which compiles to JS and runs on node.js (eg: Purescript with purescript-quickcheck), or a java-based language using the Nashorn engine provided in Java 8, for example ScalaCheck. You could even use ghcjs and the original flavor of the quickcheck library!

Is there a reset.js similar to a reset.css?

Reset.css files are used to resolve browser inconsistencies when it comes to styling.
Is there something similar for JavaScript inconsistencies across browsers like a reset.js?
For example this "reset.js" library would define a prototype for the String trim() method as specified in this question since (among other things) IE8 does not support this.
I know libraries like jQuery can be used to overcome these inconsistencies but having something like a reset.js could help when using 3rd party JavaScript libraries that do not use jQuery.
Yes, there are polyfills to do exactly that. But there are so many things you'd need to fix that you can't put all fixes in one single script :-)
Have a look at the HTML5 Cross Browser Polyfills list.
If you're specifically interested in EcmaScript compliance, there are ES5 shims to retrofit missing or incorrectly implemented methods like String::trim; yet they can't fix the engine bugs (identifier-keywords, NFEs, …).
I don't know of one that is/does exactly what you asked in a single library and as far as I know there are quite a lot of people against 'patching' the built in JavaScript objects, and some libraries (e.g. ExtJS) that did this in previous versions have changed and do now deliver the functionality in custom utility functions.
On the other hand there are a ton of smaller and larger shims to bring missing functionality to older browser, especially dealing with HTML5 inconsistencies.

A server side library to make javascript IE compatible

I have been looking for a server side library that is able to capture all scripts used on an HTML page, and convert them to IE (<9) compatible (e.g., handling things like getter / setters, missing types etc.). However I am not having much luck finding one.
Does anyone know if such a library? Am I dreaming thinking I will be able to find / build such a thing?
My preference is first node.js, second POSIX, however any suggestions would be much appreciated.
Edit: I think it is worth noting that I am not referring to something which handles differences in the IE DOM (although that would be helpful), but rather something that handles javascript language differences.
There are what you call shims, like ES5-shim. Though not thoroughly complete, they create support for ES5 functionality for legacy browsers. This is client-side code though.

Are there JSDoc files for Firefox XPCOM?

While I know much of XPCOM is implemented in C++, it would still be great to have JavaScript stubs with empty functions, constants, and JSDoc. These could be used to support code completion, inspection, quick doc, and other features of IDEs like WebStorm (IntelliJ).
It would be great if this just existed somewhere (but I haven't found it). Another approach would be to try and generate them from the IDL, but I haven't found a a way to do that either. I have question on that at Are there JSDoc files for Firefox XPCOM?.
I wrote a PHP script once, which generates PHP stubs from PHPDoc available at http://www.php.net for providing code assist in Eclipse PDT. You can use similar approach to generate JSDoc from XPCOM Doxygen.

Categories