Execute Javascript before launching the default XUL page - mozilla

Have to execute scripts using spidermonkey(jagermonkey) javascript engine availalble within XULRunner.The javascript has some dependent Javascript libraries like requriejs/commonjs etc.
RequireJS provides documentation for Rhino/NodeJS javascript runtime environment.The documentation or testcases does not suggest anything about Spidermonkey scripting environment.
Is it possible to use requirejs with Spidermonkey?Any pointers on how to go about it ?
I am using the javascript runtime packaged within XULRunner 2.0.

For XULRunner in particular, you can take a look at the Firebug code -- it embeds requirejs with an adapter for running in XUL.

Related

is it required babel configuration when I use vite in place of webpack

Recently I was create react app using vite , it is lightweight , less config and fast then compare with webpack . now my question is , is it required bable configuration in Vite project
No, vite does automatic syntax transforms but it only targets browsers that support es modules (firefox & chrome started supporting it around 2018). If you want to support new js features in older browsers you need to add polyfills though. You can read about the exact behavior and how to support even older browsers here.
I think that question need more information about that topic.
Vite.js uses the built-in JavaScript support of the browser, so you don't need to explicitly configure the JavaScript version in Vite.js itself.
When I said Vite.js uses the built-in JavaScript support of the browser, I meant that Vite.js relies on the JavaScript engine of the browser to interpret and run the JavaScript code in your application. The JavaScript engine is the component of the browser that executes JavaScript code. When you visit a web page that contains JavaScript, the browser runs the JavaScript code using its built-in JavaScript engine. This means that the version of JavaScript that is supported by your application is determined by the version of the JavaScript engine that is built into the browser. In the case of Vite.js, the JavaScript code in your application is not transpiled or otherwise modified before being run by the browser. However, if your application uses modern JavaScript syntax that is not supported by the target browsers, you will need to transpile the code to an older version of the language that is supported. In that case, you can use Babel.
No, it is already setup on the background. However if you'd like to adjust Babel's config you can do it. Read the docs here: https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md

is node.js merely a functions file that has files in it? (read the question detail for more detail)

When I download node.js from the internet through bash shell commands, am I merely downloading a "functions" folder that has many files in them, or am I downloading anything else besides that?
This question came from the shocking realization I got when I downloaded AngularJS framework and realized it was literally a one page document and nothing more.
Node.js contains a compiled executable that can load and run Javascript code.
This exposes quite a few built in functions that run compiled code within the executable, as well lots of other plain javascript in plain *.js files that make up the standard library.
But to run all that Node.js integrates the V8 javascript engine which is written in C++ and then compiled for your operating system.
When you download Angular, it is meant to run in a browser. That browser provides the execution environment. So all Anglular must provide is it's own code, which you can then leverage for your own projects. Javascript libraries really are just Javascript.
Think of Node.js more like your web browser. It's a program that can execute Javascript, as well as provides the basic functionality you need to write Javascript programs.

What does node.js mean for Nightwatchjs?

I have been using Selenium, Testng, Java, Maven to automate browser and I know these compliment each other. We can use one tool's method (APIs) in with other.
Now I have to automate using Nightwatch.js. During its initial setup I was asked to install node.js, but never got to know that why I need it? Why an installation of Nightwatch.js itself not enough?
I have tried to find out on Nightwatch's official page, but couldn't find out. Seems I am asking a very basic, foundation level question.
In a Nutshell:
NodeJS is a Javascript runtime that runs on the server. It is built on V8, Google's Javascript engine. This is the equivalent of the JVM and the Java Platform.
npm is a very popular package manager for the Javascript world and it is tighly integrated with Node. This is probably on the npm repositories that you will download Nightwatch.js. This is the package manager part of Maven for Javascript.
Nightwatch.js is a Node library that wraps Selenium for use in a Javascript environment. It is also a test runner, like JUnit or TestNG are for Java.
Hope this helps.

What is the relationship between Node.js and V8?

I've been thinking about this question for a while and can't seem to find the answer. What is the relationship between Node.js and V8? and Can Node.js work without V8?
What is the relationship between Node.js and V8?
V8 is the Javascript engine inside of node.js that parses and runs your Javascript. The same V8 engine is used inside of Chrome to run javascript in the Chrome browser. Google open-sourced the V8 engine and the builders of node.js used it to run Javascript in node.js.
Can Node.js work without V8?
No. The current node.js binary cannot work without V8. It would have no Javascript engine and thus no ability to run code which would obviously render it non-functional. Node.js was not designed to run with any other Javascript engine and, in fact, all the native code bindings that come with node.js (such as the fs module or the net module) all rely on the specific V8 interface between C++ and Javascript.
There is an effort by Microsoft to allow the Chakra Javascript engine (that's the engine in Edge) to be used with node.js. They build a V8 shim on top of Chakra so that the node.js binary code that expects to be talking to V8 can continue to do what it was doing, but actually end up talking to the Chakra engine underneath. From what I've read this is particularly targeted at Microsoft platforms that already have the Chakra engine and do not have the V8 engine running on them, though presumably you could use it on Windows too.
Node.js can actually function to some extent without V8, through use of the node-chakracore project. There is ongoing work to reduce the tight coupling between V8 and Node, so that different JavaScript engines can be used in-place.
Many beginners think that nodejs is a programming language but it is not. Before getting into the relation between v8 and nodejs lets see what V8 actually is.
V8
V8 is a javascript engine. A javascript engine is used to interpret javascript code to machine code. There are different javascript engines ex: V8 for chrome, Chakra for IE, Spider monkey for Netscape etc.
nodejs and V8
V8 is a browser engine whereas nodejs is built on top of V8 which is a runtime environment that gives javascript the power to run at the server-side.
Can Node.js work without V8?
Yes, but I have never used nodejs with other javascript engines.

JS library that provides simple utilities for browsers and the nodejs environment?

I'm looking for a javascript library that attempts to provide the same simple utilities in both the browser environment AND nodejs (iteration, mapping, maybe control-flow) so that code can more easily be re-used across server and client. I know you can hack out parts of any JS library (YUI, jQuery, ...) and get them to work in both environments, I'm just wondering if it's already been done or standardized.
The closest I've seen is this: https://github.com/kof/sharedjs
But it's incomplete and has some odd stuff. I'm wondering if there is something more polished before I fork and hack.
The underscore library was built to add more functional programming to jquery, things like mapping, and also templating.
Because it doesn't rely on the DOM (it leaves that to jquery) it functions well in node.
The RightJS link library has a server build link that has node.js in mind.
From the download page:
RightJS is also available as a server-side library. In this case it contains only the native JavaScript unit extensions and the Class, Observer, Options units along with all the non-DOM utility functions from the Util module.
Our server-side build follows the CommonJS principles and is ready for use with the node.js framework.
Node's GitHub wiki has a list of CommonJS-compatible modules which will run in Node and browsers.
Some of the other modules on that page may also run in a browser environment. For example, the excellent DateJS works fine in Node. (It is available as a NPM.)
Btw, RightJS is also available on NPM

Resources