Question

Chakra is the code-name of the updated Javascript engine Microsoft packaged into IE9.

It's possible to use JScript as the development language for an ASP Classic page. This normally runs on the JScript engine built-in to Windows, something that has been present in all versions of Windows since NT4 Option Pack (c.1996).

The question is, it is possible to use Javascript running on the Chakra engine, for ASP purposes?

Was it helpful?

Solution

Apparently not.

I tried with this simple sample script:

<%@ language="Javascript" %>

<script language="Javascript" runat="server" src='json2.js'></script>

<script language="Javascript" runat="server">

(function() {

    scriptEngineInfo = function () {
        var s = {
            engine : ScriptEngine(),
            version: {
                major: ScriptEngineMajorVersion(),
                minor:ScriptEngineMinorVersion()
            },
            build: ScriptEngineBuildVersion()
        };
        return s;
    }

}());

var x = scriptEngineInfo();
x.Timestamp = (new Date()).valueOf();

Response.Write (JSON.stringify(x));

</script>

When "Javascript" is the name of the language, as above, I get this result:

{
  "engine": "JScript",
  "version": {
    "major": 5,
    "minor": 8
  },
  "build": 16982,
  "Timestamp": 1331866901948
}

When I do as suggested in this answer and configure Chakra as a named scripting engine, then replace the three occurrences of "Javascript" in the above script with "Chakra", then run the "page", I get correct, expected results:

{
  "engine": "JScript",
  "version": {
    "major": 9,
    "minor": 0
  },
  "build": 16441,
  "Timestamp": 1331867213695
}

The major version of 9 shows I am using Chakra.

BUT if I then re-request the same script, it fails with a 500 error, saying:

Can't execute code from a freed script

If I try again, it gives me

A trappable error (C0000005) occurred in an external object. The script cannot continue running.

If I try again, I get:

A ScriptEngine threw exception 'C0000005' in 'IActiveScript::GetScriptState()' from 'CActiveScriptEngine::ReuseEngine()'.

This is repeatable, for this script, on my machine.

From this I conclude that Chakra has not been engineered for the ASP environment.

OTHER TIPS

The Active Scripting architecture allows the scripting host (i.e. the ASP.dll) to cache a somehow parsed interims code delivered by the scripting engine. This is heavily used by ASP, and makes it quite fast. We are running huge scripts (multiple 1000 lines of code), and the first call takes multiple seconds before the code is actually executed, while further calls execute the code already after 1/10 second.

Must likely due to the new JIT-Compiler, the scripting interface is not served well, and ASP gets confused. This problem does not exist with the given WSH test case, because WSH does not use the caching, as it does not organize the code to be executed.

It would be interesting to see if the Chakra 9 engine works if the ASP caching is disabled - I can't test it right now, and I assume that for big scripts like ours it will not bring desired effect. But it's worth a try for smaller scripts.

When installing IE9, the installer also deploys an old JavaScript 5.8 Engine (build 16982), and it's installed above the one coming with IE8 (17562). I don't know the significance of this "downgrade", but it seams its better not to installe IE9 on a server running Classic ASP.

Maybe IE 10's Chakra will provide better ActiveScripting architecture support. Let's hope.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top