converting js file into dll

Giganews Newsgroups
Subject: converting js file into dll
Posted by:  rizjabb…@gmail.com
Date: Mon, 9 Jun 2008

I have a js file that is being accessed through an html page. This
requirement is not going to change.
At this time, a need has arisen for access to the functions of these
files from another program that is running in C# / .Net environmet. Is
there any way to convert this file from a js file to dll.
I have access to all the three codes, the only requirement is that we
want to maintain one version of the js file.

Here is an example of the working code:
a) HTML calling code
    <html>
    <head>
        <SCRIPT LANGUAGE="JavaScript" SRC="TEng.js" ></SCRIPT>
    </head>
    <body>
    <script type="text/javascript">
            var fst = 10;
            var snd  = 10000;
            var p = new InitEngine(fst);
        document.write('<BR> random: ' + p.EngineRank(snd) );
    </script>
    </body>
    </html>

b) "TEng.js" file
        function InitEngine(diObj)
        {
            // initialize the member variables for this instance
            this.piObj = diObj;

            // initialize the member function references for the class
prototype
            if (typeof(_InitEngine_prototype_called) == 'undefined')
            {
                _InitEngine_prototype_called = true;
                InitEngine.prototype.EngineRank  = EngineRank;
                InitEngine.prototype.rndm      = rndm;
            }
            ////////////////////////////////////////////////////////////////////////////
            function EngineRank(posObj)
            {
                var sTmp = this.rndm(posObj, this.piObj);
                return sTmp;
            }

            function rndm(a, b)
            {
                return a + Math.floor(Math.random()*(b-a+1));
            }
        }
////-----------------------------------------------

Tried compiling the dll code with visual studio's jsc command but got
the following error.
TEng.js(7,24) : error JS1135: Variable '_InitEngine_prototype_called'
has not b
een declared
TEng.js(1,9) : error JS1234: Only type and package definitions are
allowed insid
e a library

Replies