⬆️ ⬇️

We use Javascript engine from IE9 without IE9

In the wake of my habratopic about testing, ServerSide decided to publish a small informational post about how to use the Microsoft JScript 9.0 engine outside of IE 9. Or rather, in the most accessible way - through Windows Script Host.

What is the use of it? Yes, at least for performance testing only JavaScript, regardless of HTML rendering. You can test your future < substitute your > -killer JavaScript library in a more environment-friendly testing environment. Whether it is not enough applications, a hacker reader for a fresh version of the Javascript engine can come up.

In general, those who are interested, welcome under cat.



For starters, should disappoint users of Windows XP and below. Despite the fact that Microsoft argues that it is impossible to launch IE9 under Windows XP because there is no support for Direct2D, IE9, which doesn’t give a damn about Direct2D, will still not work under Windows XP. It may be possible to compile the engine under Windows XP, but only versions of the engine are available that will only work in Windows Vista and Windows 7.

I also want to warn readers against rash actions with the system. If you do not understand what is being done and why, it is better not to do it.



What exactly is the JScript engine from Microsoft? This is a DLL module, which is usually located along the path % WinDir% \ System32 \ jscript.dll . The module contains the implementation of a set of COM interfaces, according to the Microsoft Active Scripting Engine specification, which means that it can be used not only in IE, but also in any application that implements the Microsoft Active Scripting Host COM interfaces. By implementing all of these interfaces, there are quite a few examples for various programming languages, since the technology is relatively old and advanced. But we don’t have to implement these interfaces, as they are already implemented in Windows Script Host applications that are part of any modern desktop version of Windows. These are wscript.exe and cscript.exe applications. Wscript.exe is a GUI application, and cscript.exe is a console application. However, the behavior of these modules can vary depending on the command line parameters.

You can view all these parameters by calling the Windows console command interpreter.



cmd

')

and typing on the command line



wscript.exe /?



or



cscript.exe / ?.



To see which version of the engine is used in your system, just create a simple getversion.js file with this code:

  1. WScript. Echo ( "Microsoft JScript " + ScriptEngineMajorVersion ( ) + "." + ScriptEngineMinorVersion ( ) + "." + ScriptEngineBuildVersion ( ) ) ;




and execute the command:



cscript.exe getversion.js



From the title it is clear that the Microsoft Active Scripting technology is not limited to the JavaScript engine. There are implementations of VBScript, PHP, Perl and others. Which engine to use for a specific script file, Windows Script Host determines by the extension of the file name that is submitted for execution. The extension is assigned a specific GUID (unique identifier) ​​of the COM object of the script interpreter engine. For JScript, this is:



{f414c260-6ac0-11cf-b6d1-00aa00bbbb58}



If you search the Windows registry for this line, you can see which module is registered as a JScript interpreter in Windows. This is usually% WinDir% \ System32 \ jscript.dll. But you can replace this registry branch, and register a module of another version. Unfortunately, all versions of JScript use the same GUID, so you cannot use multiple versions of JScript engines at the same time. In my javascript performance test , I used registry modifications through * .reg files that replaced the module registration before the corresponding test, and then restored the original engine.

What does this have to do with using IE9? Since IE9 is not yet officially released and is available only in the test version, the IE9 installer does not seem to replace the engine in the system, and IE9 uses its own version of the engine, bypassing the default registry registration. Therefore, version 9 engine is not available in Windows Script Host. We can rectify the situation when the test version of IE9 is installed by changing the registry entry to:



  1. [HKEY_LOCAL_MACHINE \ SOFTWARE \ Classes \ CLSID \ {f414c260-6ac0-11cf-b6d1-00aa00bbbb58} \ InprocServer32]
  2. @ = "C: \\ Windows \\ System32 \\ jscript9.dll" "ThreadingModel" = "Both"




and doing



cscript.exe getversion.js



make sure that the new engine is now used.



Moreover, it is not necessary to install IE9. It is enough to “tear out” the corresponding library from the Microsoft installation package and register it as a JScript engine, which I did.

The installation package for your version of Windows (~ 19 MB) can be downloaded here:



http://windows.microsoft.com/en-RU/internet-explorer/download/ie-9/worldwide



The package can be opened with any Zip archiver. I used 7-zip. We find in it the jscript9.dll file - this is the JScript v9.0 interpreter. Side by side is jscript.dll - this is a JScript v5.8 interpreter from IE8. Why such a mess with versions is also a very interesting question, the answer to which I do not know. Surely do not give rest to the laurels of Google V8?

It is clear that you should not use the new engine in the system on an ongoing basis - this can lead to problems with other applications. Yes, and licensed purity will not be all right. Therefore, after the tests it is necessary to return the settings in the registry to its original form.



References:

Active Scripting on WikiPedia

Microsoft Windows Script Technologies

JavaScript for Internet Explorer 9 Beta

My topic: ServerSide JavaScript testing

Source: https://habr.com/ru/post/110617/



All Articles