The CLSID for the Chakra Javascript engine installed with IE9 is
{16d51579-a30b-4c8b-a276-0ff4dc41e755}
.
The InProcServer32 is %windir%System32jscript9.dll
.
There is no ProgId that I could find. That's a bit odd; normally paired ProgId and CLSID entries refer to each other. For a given COM object, the ProgId key in the registry has a subkey called CLSID, and the CLSID registry key has a subkey called ProgId, and they refer to each other. But the ProgId subkey for the IE9 CLSID is "JScript", which of course refers to the v5.8 Jscript CLSID. Not sure if this was a mistake by Microsoft, or a purposeful bit of obfuscation, because they don't want anyone using the Chakra engine outside of IE9. Looks purposeful to me.
I learned of the CLSID by just searching the registry for jscript9.dll .
If you have .NET code that hosts scripting engines, you can instantiate the IActiveScript object for the IE9 javascript engine ("Chakra") by using the CLSID directly. The code needs to be something like this:
private const string clsIdPattern =
@"^(?<curly>{)?[a-zA-Z0-9]{8}(?:-[a-zA-Z0-9]{4}){3}-[a-zA-Z0-9]{12}(?(curly)})$";
public ScriptEngine(string language)
{
if (language == null)
throw new ArgumentNullException("language");
Type engineType = null;
if (Regex.IsMatch(language, clsIdPattern))
{
// it's a CLSID
var guid = new System.Guid(language);
engineType = Type.GetTypeFromCLSID(guid, true);
}
else
{
// assume vanilla progId
engineType = Type.GetTypeFromProgID(language, true);
}
var engine = Activator.CreateInstance(engineType) as IActiveScript;
In the above, clsIdPattern
is a regular expression that matches the familiar GUID format, either with or without surrounding curlies.
Given the code above, you could pass "jscript", "Javascript", or "ECMAScript" and get the v5.8 JScript engine. Or you could pass "{16d51579-a30b-4c8b-a276-0ff4dc41e755}" and get the IE9 Javascript engine. Obviously you need to have IE9 installed in order for this to work.
I just tried this and it works for simple cases. I'll be playing with that some more, real soon.
If you want to run Chakra from WSH, like from cscript.exe, then you will need a ProgId, I think.
If I create "Chakra" as a Progid in the registry, referring to the correct CLSID, I can run JS files through IE9's engine like this:
cscript.exe module.js //E:Chakra
For example, after inserting the new "Chakra" ProgId, given a script like this:
WScript.Echo( ScriptEngineMajorVersion() + "." +
ScriptEngineMinorVersion() + "." +
ScriptEngineBuildVersion());
...the output is like this:
C:devjs>Version.js
5.8.16982
C:devjs>cscript.exe Version.js //E:Chakra
9.0.16434
And here's the result of a test of AES encryption in Javascript, comparing Chakra with JScript 5.8:
C:devjsSlowAES>cscript.exe test.aes.js
AES encryption in Javascript.
password : Albatros1
salt : saltines (73616c74696e6573)
iterations: 1000
key : 172,52,20,51,98,71,49,195,14,31,141,51,129,8,94,66
iv : 212,27,28,156,83,245,0,35,176,157,45,141,209,143,158,248
plaintext : Hello, /r/javascript.
ciphertext: fdebac9f1ed1a13bac58f3cc6558e8b0367a94245dbbfe53cacc4979799fc182
decrypted : Hello, /r/javascript.
elapsed : 5011ms
C:devjsSlowAES>cscript.exe test.aes.js //E:Chakra
AES encryption in Javascript.
password : Albatros1
salt : saltines (73616c74696e6573)
iterations: 1000
key : 172,52,20,51,98,71,49,195,14,31,141,51,129,8,94,66
iv : 212,27,28,156,83,245,0,35,176,157,45,141,209,143,158,248
plaintext : Hello, /r/javascript.
ciphertext: fdebac9f1ed1a13bac58f3cc6558e8b0367a94245dbbfe53cacc4979799fc182
decrypted : Hello, /r/javascript.
elapsed : 2593ms
To set the ProgId in my registry, I used this:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{16d51579-a30b-4c8b-a276-0ff4dc41e755}ProgID]
@="Chakra"
[HKEY_LOCAL_MACHINESOFTWAREClassesWow6432NodeCLSID{16d51579-a30b-4c8b-a276-0ff4dc41e755}ProgID]
@="Chakra"
[HKEY_LOCAL_MACHINESOFTWAREClassesChakra]
@="JScript Language"
[HKEY_LOCAL_MACHINESOFTWAREClassesChakraCLSID]
@="{16d51579-a30b-4c8b-a276-0ff4dc41e755}"
[HKEY_LOCAL_MACHINESOFTWAREClassesChakraOLEScript]
and to unexpose Chakra, or revert the registry, I did this:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{16d51579-a30b-4c8b-a276-0ff4dc41e755}ProgID]
@="JScript"
[HKEY_LOCAL_MACHINESOFTWAREClassesWow6432NodeCLSID{16d51579-a30b-4c8b-a276-0ff4dc41e755}ProgID]
@="JScript"
[-HKEY_LOCAL_MACHINESOFTWAREClassesChakra]
This registry script worked with x64 Windows; if you don't have x64, then you'll need to remove the WOW6432Node lines.