|
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 |
|
7 /** |
|
8 File Name: 8.6.2.1-1.js |
|
9 ECMA Section: 8.6.2.1 Get (Value) |
|
10 Description: |
|
11 |
|
12 When the [[Get]] method of O is called with property name P, the following |
|
13 steps are taken: |
|
14 |
|
15 1. If O doesn't have a property with name P, go to step 4. |
|
16 2. Get the value of the property. |
|
17 3. Return Result(2). |
|
18 4. If the [[Prototype]] of O is null, return undefined. |
|
19 5. Call the [[Get]] method of [[Prototype]] with property name P. |
|
20 6. Return Result(5). |
|
21 |
|
22 This tests [[Get]] (Value). |
|
23 |
|
24 Author: christine@netscape.com |
|
25 Date: 12 november 1997 |
|
26 */ |
|
27 var SECTION = "8.6.2.1-1"; |
|
28 var VERSION = "ECMA_1"; |
|
29 startTest(); |
|
30 |
|
31 writeHeaderToLog( SECTION + " [[Get]] (Value)"); |
|
32 |
|
33 new TestCase( SECTION, "var OBJ = new MyValuelessObject(true); OBJ.valueOf()", true, eval("var OBJ = new MyValuelessObject(true); OBJ.valueOf()") ); |
|
34 // new TestCase( SECTION, "var OBJ = new MyProtoValuelessObject(true); OBJ + ''", "undefined", eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") ); |
|
35 new TestCase( SECTION, "var OBJ = new MyProtolessObject(true); OBJ.valueOf()", true, eval("var OBJ = new MyProtolessObject(true); OBJ.valueOf()") ); |
|
36 |
|
37 new TestCase( SECTION, "var OBJ = new MyValuelessObject(Number.POSITIVE_INFINITY); OBJ.valueOf()", Number.POSITIVE_INFINITY, eval("var OBJ = new MyValuelessObject(Number.POSITIVE_INFINITY); OBJ.valueOf()") ); |
|
38 // new TestCase( SECTION, "var OBJ = new MyProtoValuelessObject(Number.POSITIVE_INFINITY); OBJ + ''", "undefined", eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") ); |
|
39 new TestCase( SECTION, "var OBJ = new MyProtolessObject(Number.POSITIVE_INFINITY); OBJ.valueOf()", Number.POSITIVE_INFINITY, eval("var OBJ = new MyProtolessObject(Number.POSITIVE_INFINITY); OBJ.valueOf()") ); |
|
40 |
|
41 new TestCase( SECTION, "var OBJ = new MyValuelessObject('string'); OBJ.valueOf()", 'string', eval("var OBJ = new MyValuelessObject('string'); OBJ.valueOf()") ); |
|
42 // new TestCase( SECTION, "var OBJ = new MyProtoValuelessObject('string'); OJ + ''", "undefined", eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") ); |
|
43 new TestCase( SECTION, "var OBJ = new MyProtolessObject('string'); OBJ.valueOf()", 'string', eval("var OBJ = new MyProtolessObject('string'); OBJ.valueOf()") ); |
|
44 |
|
45 test(); |
|
46 |
|
47 function MyProtoValuelessObject(value) { |
|
48 this.valueOf = new Function ( "" ); |
|
49 this.__proto__ = null; |
|
50 } |
|
51 |
|
52 function MyProtolessObject( value ) { |
|
53 this.valueOf = new Function( "return this.value" ); |
|
54 this.__proto__ = null; |
|
55 this.value = value; |
|
56 } |
|
57 function MyValuelessObject(value) { |
|
58 this.__proto__ = new MyPrototypeObject(value); |
|
59 } |
|
60 function MyPrototypeObject(value) { |
|
61 this.valueOf = new Function( "return this.value;" ); |
|
62 this.toString = new Function( "return (this.value + '');" ); |
|
63 this.value = value; |
|
64 } |