The Timers interface defined in HTML specification is a widely adopted interface among many javascript engine, including all browser's javascript engines (SpiderMonkey, V8, Chakra...) and the well known NodeJS (V8), but it is not a feature of javascript itself, so I'm wondering if there is any javascript engines that does not provide setTimeout and setInterval as a method of the global object..
Afaik jsdb doesn't provide setTimeout/setInterval. It does provide a [system.]sleep method.
Related
Definitely, all of us know about powerful JavaScript engine, So why in React Native is used a different engine that name is JavaScriptCore.
The JavaScriptCore does not support some ES6 features like below function:
Array.prototype.flatten
What is benefits of JavaScriptCore to V8? Why the Facebook developers didn't use V8?
V8 does not run on iOS, because Apple does not allow third-party apps to generate code at runtime (a.k.a. "JIT-compiling"), which V8 heavily relies on for performance (*). JavaScriptCore, being made by Apple, is allowed to run (and JIT-compile code) on iOS. Since React Native's purpose is cross-platform development, this is a strong argument.
That said, Array.prototype.flatten is not an ES6 feature. It is currently a "stage 3 proposal", meaning it will probably soon become an official part of JavaScript -- maybe ES2019 ("ES10" in the old naming scheme) or so. Also, it has been renamed to Array.prototype.flat due to web compatibility issues with the name .flatten. JavaScript engines have started to implement it; according to MDN the latest version of Safari/JavaScriptCore already support it, so it's probably only a matter of time until support arrives in React Native too.
(*) There is an ongoing effort to build a version of V8 that avoids all runtime code generation, trading a lot of performance for the ability to run anywhere, but it's not available yet.
I would like to filter an array in my XPage with serverside Javascript. Unfortunately I get the following error:
Error calling method 'filter(Function)' on an object of type 'Array [JavaScript Object]'
I have an Array of Strings like ["elem1","elem2","elem3"]
I call the function like this:
list.filter(function(){
});
Is there any reason why this error happens? Does this function even exist in ssjs?
This question is not duplicate since it is not clear that Xpages/Lotus Notes runs Rhino in background.
It sounds like whatever server-side JavaScript environment you're using doesn't support ES5 features (that's features from the 5th edition specification from December 2009).
You can use a polyfill for that and other things that were added to Array, see MDN, but beware: If ES5 features aren't supported, it's impossible to add things to Array.prototype without making them enumerable, meaning any code (mis)using for-in to loop through arrays will be affected.
There is Rhino behind XPages. And this SO topic
No Array.filter() in Rhino? says, it is out of date.
Edit:
No, it is not. Years ago I read somewhere about it. Now it seems it was not true. According to comment by Dan Sickles (quoting Philippe Riand?) here:
It runs on the server jvm and uses javascript as the application
language. For licensing reasons, IBM wrote their own jvm javascript
engine instead of using Rhino. With Rhino shipping in java 6, they
should be able to ship it in Designer 8.5 (or later). The licensing
problems may have been around the extensions like #Formulas and type
declarations. Classes, modules/namespaces and type declarations are
coming in javascript 2 and even google is helping to get that
implemented in Rhino. I'd hate to see a non-standard, javascript
engine underlying the coolest web development technology in Domino.
Speaking of Rhino, the "most important new feature that is not as
certain to be in 8.5 as XPages" uses Rhino and other jvm scripting
languages on the client. If this makes it into the product, two years
from now most new Notes applications will be written in neither
Lotusscript nor Java. I'll leave it at that.
In fact, there are few topics how to use Rhino in XPages, so with newest Rhino version your code would work. Anyway, my advice is to use Java calls.
I have some JavaScript benchmark code that is supported to be running on browser. But I would like to run it on console mode of JavaScript engine such as 'd8' in V8 for testing purpose.
I have written empty variables and functions for each DOM variables and functions(e.g. document.getElementById, etc.). But I cannot fully run the code since setTimeout() and setInterval() are supported by browser not from V8 engine. Is there a way to implement or simply emulate those functions in pure JavaScript code?
I appreciate any kind of comments.
You can't to that with just V8 + some JS, you have to embbed the JS engine in some kind of runtime that supports timers. For V8 there's zombie.js for instance.
Let's take a look how it is implemented in node timers.js. You can see at line #24, that timer_wrap binding is registered. This "internal module" is just a C library that supplies js module with time operations. That means that js timer implementation is based on some modules of an "upper level" and unfortunately can't be achieved in "pure js" as you wish.
If it's a scripting language as the name implies it must be written in a lower level language right? Like how PHP is written in C what language is JavaScript written in?
Javascript is just a standard, more formally known as ECMAScript. It can be implemented in any language, just like any standard.
Chrome's Javascript engine, V8, is written in C++.
From the project page:
V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
V8 implements ECMAScript as specified in ECMA-262, 5th edition, and
runs on Windows (XP or newer), Mac OS X (10.5 or newer), and Linux
systems that use IA-32, x64, or ARM processors.
Firefox's Javascript engine, SpiderMonkey (and now TraceMonkey) is also written in C++. And as maerics below said, Rhino is written in Java.
All the answers so far are correct, but since it hasn't been mentioned yet, JavaScript can be written in JavaScript.
Most Javascript interpreters are written in C/C++ (V8, Nitro, etc…), however a compliant interpreter can be written in any language (Rhino→Java, Interpreter→Javascript, etc…).
Whichever language the client webbrowsers javascript interpreter was written in :)
Javascript is an implementation of the ECMAScript standard, but there is no singular canonical interpreter like you see with PHP.
Most of the major implementations (standalone or as parts of web browsers) out there tend to be largely written in C or C++ for performance reasons, but that's not necessarily always the case. Rhino, an engine maintained by Mozilla, is written in Java.
Most implementations of Javascript show behaviour that is clearly caused by the use of pointers and byref parameter passing, which normally points towards the use of C, or C++
This is clearly notable for instance when you are taking apart a multidimensional array in a loop, with the help of intermediate array's. These tend to behave very "strangely", if you are not familiar with pointers and byref passing of parameters (You need do var hlp = new Array() each time or it will overwrite the previous values which you already stored somewhere else)
I'm rather curious as to how an implementation of javascript in for instance Java, because I imagine that this kind of behaviour will be quite different in that case?
C++ is the fundamental language for anything modern and fancy. Most modern high level languages are subset of low level language,C++. All modern languages you see today is a subset of C++ someway or the other. Even Java is a subset of C++.
I drive into this issue:
I create COM object using C#, register it and managed to work with it using powershell.
when i trying to do the same with JavaScript it fails, but javascript keeps throwing object null errors.
Do you have any advice on how to fix this problem? or maybe you JavaScript doesn't support COM (if so, where can i read more about it)???
Thanks a lot!
Use Shanti Rao's JSDB shell. It's based on the core Spidermonkey engine (Mozilla's Javascript implementation) used in Firefox, but has a bunch of bindings for databases & ActiveX objects and such. It has a few limitations but unless you're using something complicated you should be able to make use of it.
Example:
x=new ActiveX('MSXML2.DOMDocument.6.0');
x.async = false;
// I forget how to use IXMLDOMDocument but other calls go here
I know this is a bit late, but for others who find this, yes this can be done easily. This assumes you're running on Windows since you're looking for Windows/JavaScript interoperability.
The most important question is "what JavaScript engine are you using?" as this functionality is determined by that engine. Since 1995, Windows has supported a system standard scripting model originally called OLE Automation or sometimes just COM. Windows-based scripting engines like the JavaScript and VBScript engines built into the Windows Scripting Host use this engine, in addition to IE through version 8 and I think up to 11. However, the IE container implements security restrictions that prevent some of what I'm describing from working. Open-source JavaScript engines like node.js typically do not use COM as this is Windows specific functionality and so cannot do what I am describing.
Given that, to accomplish what you want, you must:
1. Implement a scriptable COM object.
2. Register that object (typically automatic during your build process).
3. In JavaScript, create an instance of that object using new ActiveX object, as mentioned above.
You can write your object in both C# and C++. In both cases, you need to base your object on IDispatch. C# will make the whole process considerably easier. Essentially, you generate a few unique GUIDs for your interface and component using guidgen, then using a few COM-specific attributes in C# to provide these. Here's a link to a great simple example (ignore the Events stuff):
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/interop/example-com-class
The most important thing to know is that you will be limited on what data types you can take as parameters or return to the caller. Things like strings and ints are no problem. For others, you can describe them in C# and send them from C# to JavaScript, but the other way around is not going to work.
Javascript indeed does not support COM. An option is to use JScript and an ActiveX wrapper to a COM object. Also, it will only work in Internet Explorer.
Instantiating a COM class
Calling functions of a COM object in JScript
Other JScript/COM tutorials, including script callbacks