Debian Codegraph @

rhino/testsrc/tests/ecma/TypeConversion/9.9-1.js

raw symbols SCIP
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/. */
5
6 gTestfile = '9.9-1.js';
7
8 /**
9 File Name: 9.9-1.js
10 ECMA Section: 9.9 Type Conversion: ToObject
11 Description:
12
13 undefined generate a runtime error
14 null generate a runtime error
15 boolean create a new Boolean object whose default
16 value is the value of the boolean.
17 number Create a new Number object whose default
18 value is the value of the number.
19 string Create a new String object whose default
20 value is the value of the string.
21 object Return the input argument (no conversion).
22 Author: [email protected]
23 Date: 17 july 1997
24 */
25
26 var VERSION = "ECMA_1";
27 startTest();
28 var SECTION = "9.9-1";
29
30 writeHeaderToLog( SECTION + " Type Conversion: ToObject" );
31
32 new TestCase( SECTION, "Object(true).valueOf()", true, (Object(true)).valueOf() );
33 new TestCase( SECTION, "typeof Object(true)", "object", typeof Object(true) );
34
35 new TestCase( SECTION, "Object(false).valueOf()", false, (Object(false)).valueOf() );
36 new TestCase( SECTION, "typeof Object(false)", "object", typeof Object(false) );
37
38 new TestCase( SECTION, "Object(0).valueOf()", 0, (Object(0)).valueOf() );
39 new TestCase( SECTION, "typeof Object(0)", "object", typeof Object(0) );
40
41 new TestCase( SECTION, "Object(-0).valueOf()", -0, (Object(-0)).valueOf() );
42 new TestCase( SECTION, "typeof Object(-0)", "object", typeof Object(-0) );
43
44 new TestCase( SECTION, "Object(1).valueOf()", 1, (Object(1)).valueOf() );
45 new TestCase( SECTION, "typeof Object(1)", "object", typeof Object(1) );
46
47 new TestCase( SECTION, "Object(-1).valueOf()", -1, (Object(-1)).valueOf() );
48 new TestCase( SECTION, "typeof Object(-1)", "object", typeof Object(-1) );
49
50 new TestCase( SECTION, "Object(Number.MAX_VALUE).valueOf()", 1.7976931348623157e308, (Object(Number.MAX_VALUE)).valueOf() );
51 new TestCase( SECTION, "typeof Object(Number.MAX_VALUE)", "object", typeof Object(Number.MAX_VALUE) );
52
53 new TestCase( SECTION, "Object(Number.MIN_VALUE).valueOf()", 5e-324, (Object(Number.MIN_VALUE)).valueOf() );
54 new TestCase( SECTION, "typeof Object(Number.MIN_VALUE)", "object", typeof Object(Number.MIN_VALUE) );
55
56 new TestCase( SECTION, "Object(Number.POSITIVE_INFINITY).valueOf()", Number.POSITIVE_INFINITY, (Object(Number.POSITIVE_INFINITY)).valueOf() );
57 new TestCase( SECTION, "typeof Object(Number.POSITIVE_INFINITY)", "object", typeof Object(Number.POSITIVE_INFINITY) );
58
59 new TestCase( SECTION, "Object(Number.NEGATIVE_INFINITY).valueOf()", Number.NEGATIVE_INFINITY, (Object(Number.NEGATIVE_INFINITY)).valueOf() );
60 new TestCase( SECTION, "typeof Object(Number.NEGATIVE_INFINITY)", "object", typeof Object(Number.NEGATIVE_INFINITY) );
61
62 new TestCase( SECTION, "Object(Number.NaN).valueOf()", Number.NaN, (Object(Number.NaN)).valueOf() );
63 new TestCase( SECTION, "typeof Object(Number.NaN)", "object", typeof Object(Number.NaN) );
64
65 new TestCase( SECTION, "Object('a string').valueOf()", "a string", (Object("a string")).valueOf() );
66 new TestCase( SECTION, "typeof Object('a string')", "object", typeof (Object("a string")) );
67
68 new TestCase( SECTION, "Object('').valueOf()", "", (Object("")).valueOf() );
69 new TestCase( SECTION, "typeof Object('')", "object", typeof (Object("")) );
70
71 new TestCase( SECTION, "Object('\\r\\t\\b\\n\\v\\f').valueOf()", "\r\t\b\n\v\f", (Object("\r\t\b\n\v\f")).valueOf() );
72 new TestCase( SECTION, "typeof Object('\\r\\t\\b\\n\\v\\f')", "object", typeof (Object("\\r\\t\\b\\n\\v\\f")) );
73
74 new TestCase( SECTION, "Object( '\\\'\\\"\\' ).valueOf()", "\'\"\\", (Object("\'\"\\")).valueOf() );
75 new TestCase( SECTION, "typeof Object( '\\\'\\\"\\' )", "object", typeof Object("\'\"\\") );
76
77 new TestCase( SECTION, "Object( new MyObject(true) ).valueOf()", true, eval("Object( new MyObject(true) ).valueOf()") );
78 new TestCase( SECTION, "typeof Object( new MyObject(true) )", "object", eval("typeof Object( new MyObject(true) )") );
79 new TestCase( SECTION, "(Object( new MyObject(true) )).toString()", "[object Object]", eval("(Object( new MyObject(true) )).toString()") );
80
81 test();
82
83 function MyObject( value ) {
84 this.value = value;
85 this.valueOf = new Function ( "return this.value" );
86 }