js/src/tests/ecma_2/extensions/instanceof-002.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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:          instanceof-002.js
     9    Section:
    10    Description:        Determining Instance Relationships
    12    This test is the same as js1_3/inherit/proto-002, except that it uses
    13    the builtin instanceof operator rather than a user-defined function
    14    called InstanceOf.
    16    This tests Object Hierarchy and Inheritance, as described in the document
    17    Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97
    18    15:19:34 on http://devedge.netscape.com/.  Current URL:
    19    http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm
    21    This tests the syntax ObjectName.prototype = new PrototypeObject using the
    22    Employee example in the document referenced above.
    24    Author:             christine@netscape.com
    25    Date:               12 november 1997
    26 */
    27 //    onerror = err;
    29 var SECTION = "instanceof-002";
    30 var VERSION = "ECMA_2";
    31 var TITLE   = "Determining Instance Relationships";
    33 startTest();
    34 writeHeaderToLog( SECTION + " "+ TITLE);
    36 function InstanceOf( object, constructor ) {
    37   while ( object != null ) {
    38     if ( object == constructor.prototype ) {
    39       return true;
    40     }
    41     object = object.__proto__;
    42   }
    43   return false;
    44 }
    46 function Employee ( name, dept ) {
    47   this.name = name || "";
    48   this.dept = dept || "general";
    49 }
    51 function Manager () {
    52   this.reports = [];
    53 }
    54 Manager.prototype = new Employee();
    56 function WorkerBee ( name, dept, projs ) {
    57   this.base = Employee;
    58   this.base( name, dept)
    59     this.projects = projs || new Array();
    60 }
    61 WorkerBee.prototype = new Employee();
    63 function SalesPerson () {
    64   this.dept = "sales";
    65   this.quota = 100;
    66 }
    67 SalesPerson.prototype = new WorkerBee();
    69 function Engineer ( name, projs, machine ) {
    70   this.base = WorkerBee;
    71   this.base( name, "engineering", projs )
    72     this.machine = machine || "";
    73 }
    74 Engineer.prototype = new WorkerBee();
    76 var pat = new Engineer();
    78 new TestCase( SECTION,
    79 	      "pat.__proto__ == Engineer.prototype",
    80 	      true,
    81 	      pat.__proto__ == Engineer.prototype );
    83 new TestCase( SECTION,
    84 	      "pat.__proto__.__proto__ == WorkerBee.prototype",
    85 	      true,
    86 	      pat.__proto__.__proto__ == WorkerBee.prototype );
    88 new TestCase( SECTION,
    89 	      "pat.__proto__.__proto__.__proto__ == Employee.prototype",
    90 	      true,
    91 	      pat.__proto__.__proto__.__proto__ == Employee.prototype );
    93 new TestCase( SECTION,
    94 	      "pat.__proto__.__proto__.__proto__.__proto__ == Object.prototype",
    95 	      true,
    96 	      pat.__proto__.__proto__.__proto__.__proto__ == Object.prototype );
    98 new TestCase( SECTION,
    99 	      "pat.__proto__.__proto__.__proto__.__proto__.__proto__ == null",
   100 	      true,
   101 	      pat.__proto__.__proto__.__proto__.__proto__.__proto__ == null );
   103 new TestCase( SECTION,
   104 	      "pat instanceof Engineer",
   105 	      true,
   106 	      pat instanceof Engineer );
   108 new TestCase( SECTION,
   109 	      "pat instanceof WorkerBee )",
   110 	      true,
   111 	      pat instanceof WorkerBee );
   113 new TestCase( SECTION,
   114 	      "pat instanceof Employee )",
   115 	      true,
   116 	      pat instanceof Employee );
   118 new TestCase( SECTION,
   119 	      "pat instanceof Object )",
   120 	      true,
   121 	      pat instanceof Object );
   123 new TestCase( SECTION,
   124 	      "pat instanceof SalesPerson )",
   125 	      false,
   126 	      pat instanceof SalesPerson );
   127 test();

mercurial