Home | History | Annotate | Download | only in Eval
      1 /* The contents of this file are subject to the Netscape Public
      2  * License Version 1.1 (the "License"); you may not use this file
      3  * except in compliance with the License. You may obtain a copy of
      4  * the License at http://www.mozilla.org/NPL/
      5  *
      6  * Software distributed under the License is distributed on an "AS
      7  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
      8  * implied. See the License for the specific language governing
      9  * rights and limitations under the License.
     10  *
     11  * The Original Code is Mozilla Communicator client code, released March
     12  * 31, 1998.
     13  *
     14  * The Initial Developer of the Original Code is Netscape Communications
     15  * Corporation. Portions created by Netscape are
     16  * Copyright (C) 1998 Netscape Communications Corporation. All
     17  * Rights Reserved.
     18  *
     19  * Contributor(s):
     20  *
     21  */
     22 /**
     23  *  File Name:    eval-003.js
     24  *  Description:  (SEE REVISED DESCRIPTION FURTHER BELOW)
     25  *
     26  *  The global eval function may not be accessed indirectly and then called.
     27  *  This feature will continue to work in JavaScript 1.3 but will result in an
     28  *  error in JavaScript 1.4. This restriction is also in place for the With and
     29  *  Closure constructors.
     30  *
     31  *  http://scopus.mcom.com/bugsplat/show_bug.cgi?id=324451
     32  *
     33  *  Author:          christine (at) netscape.com
     34  *  Date:               11 August 1998
     35  *
     36  *
     37  *  REVISION:    05  February 2001
     38  *  Author:          pschwartau (at) netscape.com
     39  *
     40  *  Indirect eval IS NOT ILLEGAL per ECMA3!!!  See
     41  *
     42  *  http://bugzilla.mozilla.org/show_bug.cgi?id=38512
     43  *
     44  *  ------- Additional Comments From Brendan Eich 2001-01-30 17:12 -------
     45  * ECMA-262 Edition 3 doesn't require implementations to throw EvalError,
     46  * see the short, section-less Chapter 16.  It does say an implementation that
     47  * doesn't throw EvalError must allow assignment to eval and indirect calls
     48  * of the evalnative method.
     49  *
     50  */
     51     var SECTION = "eval-003.js";
     52     var VERSION = "JS1_4";
     53     var TITLE   = "Calling eval indirectly should NOT fail in version 140";
     54     var BUGNUMBER="38512";
     55 
     56     startTest();
     57     writeHeaderToLog( SECTION + " "+ TITLE);
     58 
     59     var testcases = new Array();
     60 
     61     var MY_EVAL = eval;
     62     var RESULT = "";
     63     var EXPECT= "";
     64     var h = function f(x,y){var g = function(z){return Math.exp(z);}; return g(x+y);};
     65 
     66 
     67     new EvalTest();
     68 
     69     test();
     70 
     71 function EvalTest()
     72 {
     73   with( this )
     74   {
     75       MY_EVAL( "RESULT = h(-1, 1)" );
     76       EXPECT = 1;  //The base e to the power (-1 + 1),  i.e. the power 0,  equals 1 ....
     77 
     78       testcases[tc++] = new TestCase(
     79           SECTION,
     80           "Call eval indirectly",
     81           EXPECT,
     82           RESULT );
     83   }
     84 }
     85 
     86