js/src/tests/js1_5/extensions/getset-006.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/. */
     6 /*
     7  * Date: 14 April 2001
     8  *
     9  * SUMMARY: Testing  obj.__lookupGetter__(), obj.__lookupSetter__()
    10  * See http://bugzilla.mozilla.org/show_bug.cgi?id=71992
    11  *
    12  * Brendan: "I see no need to provide more than the minimum:
    13  * o.__lookupGetter__('p') returns the getter function for o.p,
    14  * or undefined if o.p has no getter.  Users can wrap and layer."
    15  */
    16 //-----------------------------------------------------------------------------
    17 var UBound = 0;
    18 var BUGNUMBER = 71992;
    19 var summary = 'Testing  obj.__lookupGetter__(), obj.__lookupSetter__()';
    20 var statprefix = 'Status: ';
    21 var status = '';
    22 var statusitems = [ ];
    23 var actual = '';
    24 var actualvalues = [ ];
    25 var expect= '';
    26 var expectedvalues = [ ];
    27 var cnName = 'name';
    28 var cnColor = 'color';
    29 var cnNonExistingProp = 'ASDF_#_$%';
    30 var cnDEFAULT = 'default name';
    31 var cnFRED = 'Fred';
    32 var cnRED = 'red';
    33 var obj = {};
    34 var obj2 = {};
    35 var s;
    38 // The only setter and getter functions we'll use in the three sections below -
    39 var cnNameSetter = function(newValue) {this._name=newValue; this.nameSETS++;};
    40 var cnNameGetter = function() {this.nameGETS++; return this._name;};
    44 // SECTION1: define getter/setter directly on an object (not its prototype)
    45 obj = new Object();
    46 obj.nameSETS = 0;
    47 obj.nameGETS = 0;
    48 obj.__defineSetter__(cnName, cnNameSetter);
    49 obj.__defineGetter__(cnName, cnNameGetter);
    50 obj.name = cnFRED;
    51 obj.color = cnRED;
    53 status ='In SECTION1 of test; looking up extant getter/setter';
    54 actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)];
    55 expect = [cnNameSetter, cnNameGetter];
    56 addThis();
    58 status = 'In SECTION1 of test; looking up nonexistent getter/setter';
    59 actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)];
    60 expect = [undefined, undefined];
    61 addThis();
    63 status = 'In SECTION1 of test; looking up getter/setter on nonexistent property';
    64 actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)];
    65 expect = [undefined, undefined];
    66 addThis();
    70 // SECTION2: define getter/setter in Object.prototype
    71 Object.prototype.nameSETS = 0;
    72 Object.prototype.nameGETS = 0;
    73 Object.prototype.__defineSetter__(cnName, cnNameSetter);
    74 Object.prototype.__defineGetter__(cnName, cnNameGetter);
    76 obj = new Object();
    77 obj.name = cnFRED;
    78 obj.color = cnRED;
    80 status = 'In SECTION2 of test looking up extant getter/setter';
    81 actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)];
    82 expect = [cnNameSetter, cnNameGetter];
    83 addThis();
    85 status = 'In SECTION2 of test; looking up nonexistent getter/setter';
    86 actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)];
    87 expect = [undefined, undefined];
    88 addThis();
    90 status = 'In SECTION2 of test; looking up getter/setter on nonexistent property';
    91 actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)];
    92 expect = [undefined, undefined];
    93 addThis();
    97 // SECTION 3: define getter/setter in prototype of user-defined constructor
    98 function TestObject()
    99 {
   100 }
   101 TestObject.prototype.nameSETS = 0;
   102 TestObject.prototype.nameGETS = 0;
   103 TestObject.prototype.__defineSetter__(cnName, cnNameSetter);
   104 TestObject.prototype.__defineGetter__(cnName, cnNameGetter);
   105 TestObject.prototype.name = cnDEFAULT;
   107 obj = new TestObject();
   108 obj.name = cnFRED;
   109 obj.color = cnRED;
   111 status = 'In SECTION3 of test looking up extant getter/setter';
   112 actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)];
   113 expect = [cnNameSetter, cnNameGetter];
   114 addThis();
   116 status = 'In SECTION3 of test; looking up nonexistent getter/setter';
   117 actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)];
   118 expect = [undefined, undefined];
   119 addThis();
   121 status = 'In SECTION3 of test; looking up getter/setter on nonexistent property';
   122 actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)];
   123 expect = [undefined, undefined];
   124 addThis();
   128 //---------------------------------------------------------------------------------
   129 test();
   130 //---------------------------------------------------------------------------------
   133 function addThis()
   134 {
   135   statusitems[UBound] = status;
   136   actualvalues[UBound] = actual.toString();
   137   expectedvalues[UBound] = expect.toString();
   138   UBound++;
   139 }
   142 function test()
   143 {
   144   enterFunc ('test');
   145   printBugNumber(BUGNUMBER);
   146   printStatus (summary);
   148   for (var i = 0; i < UBound; i++)
   149   {
   150     reportCompare(expectedvalues[i], actualvalues[i], getStatus(i));
   151   }
   153   exitFunc ('test');
   154 }
   157 function getStatus(i)
   158 {
   159   return statprefix + statusitems[i];
   160 }

mercurial