js/src/tests/ecma/Expressions/11.1.1.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /**
     8    File Name:          11.1.1.js
     9    ECMA Section:       11.1.1 The this keyword
    10    Description:
    12    The this keyword evaluates to the this value of the execution context.
    14    Author:             christine@netscape.com
    15    Date:               12 november 1997
    16 */
    17 var SECTION = "11.1.1";
    18 var VERSION = "ECMA_1";
    19 startTest();
    21 writeHeaderToLog( SECTION + " The this keyword");
    23 var GLOBAL_OBJECT = this.toString();
    25 // this in global code and eval(this) in global code should return the global object.
    27 new TestCase( SECTION,
    28 	      "Global Code: this.toString()",
    29 	      GLOBAL_OBJECT,
    30 	      this.toString() );
    32 new TestCase( SECTION,
    33 	      "Global Code:  eval('this.toString()')",
    34 	      GLOBAL_OBJECT,
    35 	      eval('this.toString()') );
    37 // this in anonymous code called as a function should return the global object.
    39 new TestCase( SECTION,
    40 	      "Anonymous Code: var MYFUNC = new Function('return this.toString()'); MYFUNC()",
    41 	      GLOBAL_OBJECT,
    42 	      eval("var MYFUNC = new Function('return this.toString()'); MYFUNC()") );
    44 // eval( this ) in anonymous code called as a function should return that function's activation object
    46 new TestCase( SECTION,
    47 	      "Anonymous Code: var MYFUNC = new Function('return (eval(\"this.toString()\")'); (MYFUNC()).toString()",
    48 	      GLOBAL_OBJECT,
    49 	      eval("var MYFUNC = new Function('return eval(\"this.toString()\")'); (MYFUNC()).toString()") );
    51 // this and eval( this ) in anonymous code called as a constructor should return the object
    53 new TestCase( SECTION,
    54 	      "Anonymous Code: var MYFUNC = new Function('this.THIS = this'); ((new MYFUNC()).THIS).toString()",
    55 	      "[object Object]",
    56 	      eval("var MYFUNC = new Function('this.THIS = this'); ((new MYFUNC()).THIS).toString()") );
    58 new TestCase( SECTION,
    59 	      "Anonymous Code: var MYFUNC = new Function('this.THIS = this'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1",
    60 	      true,
    61 	      eval("var MYFUNC = new Function('this.THIS = this'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1") );
    63 new TestCase( SECTION,
    64 	      "Anonymous Code: var MYFUNC = new Function('this.THIS = eval(\"this\")'); ((new MYFUNC().THIS).toString()",
    65 	      "[object Object]",
    66 	      eval("var MYFUNC = new Function('this.THIS = eval(\"this\")'); ((new MYFUNC()).THIS).toString()") );
    68 new TestCase( SECTION,
    69 	      "Anonymous Code: var MYFUNC = new Function('this.THIS = eval(\"this\")'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1",
    70 	      true,
    71 	      eval("var MYFUNC = new Function('this.THIS = eval(\"this\")'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1") );
    73 // this and eval(this) in function code called as a function should return the global object.
    74 new TestCase( SECTION,
    75 	      "Function Code:  ReturnThis()",
    76 	      GLOBAL_OBJECT,
    77 	      ReturnThis() );
    79 new TestCase( SECTION,
    80 	      "Function Code:  ReturnEvalThis()",
    81 	      GLOBAL_OBJECT,
    82 	      ReturnEvalThis() );
    84 //  this and eval(this) in function code called as a contructor should return the object.
    85 new TestCase( SECTION,
    86 	      "var MYOBJECT = new ReturnThis(); MYOBJECT.toString()",
    87 	      "[object Object]",
    88 	      eval("var MYOBJECT = new ReturnThis(); MYOBJECT.toString()") );
    90 new TestCase( SECTION,
    91 	      "var MYOBJECT = new ReturnEvalThis(); MYOBJECT.toString()",
    92 	      "[object Object]",
    93 	      eval("var MYOBJECT = new ReturnEvalThis(); MYOBJECT.toString()") );
    95 test();
    97 function ReturnThis() {
    98   return this.toString();
    99 }
   101 function ReturnEvalThis() {
   102   return( eval("this.toString()") );
   103 }

mercurial