js/src/tests/ecma/ObjectObjects/15.2.2.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.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /**
michael@0 8 File Name: 15.2.2.1.js
michael@0 9 ECMA Section: 15.2.2.1 The Object Constructor: new Object( value )
michael@0 10
michael@0 11 1.If the type of the value is not Object, go to step 4.
michael@0 12 2.If the value is a native ECMAScript object, do not create a new object; simply return value.
michael@0 13 3.If the value is a host object, then actions are taken and a result is returned in an
michael@0 14 implementation-dependent manner that may depend on the host object.
michael@0 15 4.If the type of the value is String, return ToObject(value).
michael@0 16 5.If the type of the value is Boolean, return ToObject(value).
michael@0 17 6.If the type of the value is Number, return ToObject(value).
michael@0 18 7.(The type of the value must be Null or Undefined.) Create a new native ECMAScript object.
michael@0 19 The [[Prototype]] property of the newly constructed object is set to the Object prototype object.
michael@0 20 The [[Class]] property of the newly constructed object is set to "Object".
michael@0 21 The newly constructed object has no [[Value]] property.
michael@0 22 Return the newly created native object.
michael@0 23
michael@0 24 Description: This does not test cases where the object is a host object.
michael@0 25 Author: christine@netscape.com
michael@0 26 Date: 7 october 1997
michael@0 27 */
michael@0 28
michael@0 29 var SECTION = "15.2.2.1";
michael@0 30 var VERSION = "ECMA_1";
michael@0 31 startTest();
michael@0 32 var TITLE = "new Object( value )";
michael@0 33
michael@0 34 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 35
michael@0 36
michael@0 37 new TestCase( SECTION, "typeof new Object(null)", "object", typeof new Object(null) );
michael@0 38 new TestCase( SECTION, "MYOB = new Object(null); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Object]", eval("MYOB = new Object(null); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 39
michael@0 40 new TestCase( SECTION, "typeof new Object(void 0)", "object", typeof new Object(void 0) );
michael@0 41 new TestCase( SECTION, "MYOB = new Object(new Object(void 0)); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Object]", eval("MYOB = new Object(new Object(void 0)); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 42
michael@0 43 new TestCase( SECTION, "typeof new Object('string')", "object", typeof new Object('string') );
michael@0 44 new TestCase( SECTION, "MYOB = (new Object('string'); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object String]", eval("MYOB = new Object('string'); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 45 new TestCase( SECTION, "(new Object('string').valueOf()", "string", (new Object('string')).valueOf() );
michael@0 46
michael@0 47 new TestCase( SECTION, "typeof new Object('')", "object", typeof new Object('') );
michael@0 48 new TestCase( SECTION, "MYOB = (new Object(''); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object String]", eval("MYOB = new Object(''); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 49 new TestCase( SECTION, "(new Object('').valueOf()", "", (new Object('')).valueOf() );
michael@0 50
michael@0 51 new TestCase( SECTION, "typeof new Object(Number.NaN)", "object", typeof new Object(Number.NaN) );
michael@0 52 new TestCase( SECTION, "MYOB = (new Object(Number.NaN); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Number]", eval("MYOB = new Object(Number.NaN); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 53 new TestCase( SECTION, "(new Object(Number.NaN).valueOf()", Number.NaN, (new Object(Number.NaN)).valueOf() );
michael@0 54
michael@0 55 new TestCase( SECTION, "typeof new Object(0)", "object", typeof new Object(0) );
michael@0 56 new TestCase( SECTION, "MYOB = (new Object(0); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Number]", eval("MYOB = new Object(0); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 57 new TestCase( SECTION, "(new Object(0).valueOf()", 0, (new Object(0)).valueOf() );
michael@0 58
michael@0 59 new TestCase( SECTION, "typeof new Object(-0)", "object", typeof new Object(-0) );
michael@0 60 new TestCase( SECTION, "MYOB = (new Object(-0); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Number]", eval("MYOB = new Object(-0); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 61 new TestCase( SECTION, "(new Object(-0).valueOf()", -0, (new Object(-0)).valueOf() );
michael@0 62
michael@0 63 new TestCase( SECTION, "typeof new Object(1)", "object", typeof new Object(1) );
michael@0 64 new TestCase( SECTION, "MYOB = (new Object(1); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Number]", eval("MYOB = new Object(1); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 65 new TestCase( SECTION, "(new Object(1).valueOf()", 1, (new Object(1)).valueOf() );
michael@0 66
michael@0 67 new TestCase( SECTION, "typeof new Object(-1)", "object", typeof new Object(-1) );
michael@0 68 new TestCase( SECTION, "MYOB = (new Object(-1); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Number]", eval("MYOB = new Object(-1); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 69 new TestCase( SECTION, "(new Object(-1).valueOf()", -1, (new Object(-1)).valueOf() );
michael@0 70
michael@0 71 new TestCase( SECTION, "typeof new Object(true)", "object", typeof new Object(true) );
michael@0 72 new TestCase( SECTION, "MYOB = (new Object(true); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Boolean]", eval("MYOB = new Object(true); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 73 new TestCase( SECTION, "(new Object(true).valueOf()", true, (new Object(true)).valueOf() );
michael@0 74
michael@0 75 new TestCase( SECTION, "typeof new Object(false)", "object", typeof new Object(false) );
michael@0 76 new TestCase( SECTION, "MYOB = (new Object(false); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Boolean]", eval("MYOB = new Object(false); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 77 new TestCase( SECTION, "(new Object(false).valueOf()", false, (new Object(false)).valueOf() );
michael@0 78
michael@0 79 new TestCase( SECTION, "typeof new Object(Boolean())", "object", typeof new Object(Boolean()) );
michael@0 80 new TestCase( SECTION, "MYOB = (new Object(Boolean()); MYOB.toString = Object.prototype.toString; MYOB.toString()", "[object Boolean]", eval("MYOB = new Object(Boolean()); MYOB.toString = Object.prototype.toString; MYOB.toString()") );
michael@0 81 new TestCase( SECTION, "(new Object(Boolean()).valueOf()", Boolean(), (new Object(Boolean())).valueOf() );
michael@0 82
michael@0 83
michael@0 84 var myglobal = this;
michael@0 85 var myobject = new Object( "my new object" );
michael@0 86 var myarray = new Array();
michael@0 87 var myboolean = new Boolean();
michael@0 88 var mynumber = new Number();
michael@0 89 var mystring = new String();
michael@0 90 var myobject = new Object();
michael@0 91 var myfunction = new Function( "x", "return x");
michael@0 92 var mymath = Math;
michael@0 93
michael@0 94 new TestCase( SECTION, "myglobal = new Object( this )", myglobal, new Object(this) );
michael@0 95 new TestCase( SECTION, "myobject = new Object('my new object'); new Object(myobject)", myobject, new Object(myobject) );
michael@0 96 new TestCase( SECTION, "myarray = new Array(); new Object(myarray)", myarray, new Object(myarray) );
michael@0 97 new TestCase( SECTION, "myboolean = new Boolean(); new Object(myboolean)", myboolean, new Object(myboolean) );
michael@0 98 new TestCase( SECTION, "mynumber = new Number(); new Object(mynumber)", mynumber, new Object(mynumber) );
michael@0 99 new TestCase( SECTION, "mystring = new String9); new Object(mystring)", mystring, new Object(mystring) );
michael@0 100 new TestCase( SECTION, "myobject = new Object(); new Object(mynobject)", myobject, new Object(myobject) );
michael@0 101 new TestCase( SECTION, "myfunction = new Function(); new Object(myfunction)", myfunction, new Object(myfunction) );
michael@0 102 new TestCase( SECTION, "mymath = Math; new Object(mymath)", mymath, new Object(mymath) );
michael@0 103
michael@0 104 test();

mercurial