Forum Discussion

simon_glet's avatar
simon_glet
Regular Contributor
11 years ago
Solved

Turn off JScript implicit variable declaration

Greetings,



JScript has the annoying feature to implicitly allow variable declarations. Like VB without the Option Strict or Explicit.



The problem is that a mistyped variable becomes a new one ... automatically. Not good.



On the Microsoft JScript site there is a mention of a fast mode that raises an exception during compilation if a variable is used without explicit declaration.



Is there a way with TestComplete to configure that ?



Thanks 

  • Hi Simon,


     


    The article you sent describes the approach for JScript.NET. TestComplete uses JScript for Windows Script Host. So, it won't work here.


     

7 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Simon,


     


    The article you sent describes the approach for JScript.NET. TestComplete uses JScript for Windows Script Host. So, it won't work here.


     

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Simon,


     


    This article is about IE 10's JavaScript. A description of the script engine that is used by TestComplete can be found here.


     


    BTW, as for PowerShell, we have a suggestion to support PowerShell in TestComplete - I've increased its rating. At the moment, you can use this approach posted by Helen.


     

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Simon,


     


    TestComplete uses the JScript library as it is. Could you please provide us with the link to the site where this mode is described - I'll consult with our R&D team on whether it is possible to be done in TC?


     

  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Tanya,



    The info can be found at MSDN JScript and the part of interest is:


    Declaring Variables Without var




    You can declare a variable without using the var keyword in the declaration and assign a value to it. This is known as an implicit declaration, and it is not recommended. An implicit declaration creates a property of the global object with the assigned name; the property behaves like a variable with global scope visibility. When you declare a variable at the procedure level, though, you typically do not want it to be visible at the global scope. In this case, youmust use the var keyword in your variable declaration.




     




     





    noStringAtAll = ""; // The variable noStringAtAll is declared implicitly.






    You cannot use a variable that has never been declared.




     




     





    var volume = length * width; // Error - length and width do not yet exist.
















    NoteNote


    Declaring variables without the var keyword generates a compile-time error when running in fast mode, the default mode for JScript. To compile a program from the command line that does not use the var keyword, you must turn off the fast option by using /fast-. It is not safe to turn off the fast option in ASP.NET because of threading issues.



    Sincerely





  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Tanya,



    Well, that's just too bad ...



    Any plans to add Poweshell as a TC scripting language ?



    Sincerely
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Tanya,



    I did a little digging about JScript for Windows Script Host and found that there is way to control variable declaration (complete document):



    "use strict";

    function testFunction(){

        var testvar = 4;

        return testvar;

    }

    testvar = 5;



    The code above would raise an exception at testvar=5;



    The problem is that "use strict"; has no effect in TC. The JScript Engine version I am running is 5.8.16982.



    Is there a way to enable this directive ?



    Thanks
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Tanya,



    Support has reproduced the JScript issue and moved it to R&D (M0115693).



    As for powershell, thanks for the reference and I hope you get more requests to have it as a native TC language !



    Sincerely