js/src/tests/ecma/extensions/8.6.2.1-1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/extensions/8.6.2.1-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   File Name:          8.6.2.1-1.js
    1.12 +   ECMA Section:       8.6.2.1 Get (Value)
    1.13 +   Description:
    1.14 +
    1.15 +   When the [[Get]] method of O is called with property name P, the following
    1.16 +   steps are taken:
    1.17 +
    1.18 +   1.  If O doesn't have a property with name P, go to step 4.
    1.19 +   2.  Get the value of the property.
    1.20 +   3.  Return Result(2).
    1.21 +   4.  If the [[Prototype]] of O is null, return undefined.
    1.22 +   5.  Call the [[Get]] method of [[Prototype]] with property name P.
    1.23 +   6.  Return Result(5).
    1.24 +
    1.25 +   This tests [[Get]] (Value).
    1.26 +
    1.27 +   Author:             christine@netscape.com
    1.28 +   Date:               12 november 1997
    1.29 +*/
    1.30 +var SECTION = "8.6.2.1-1";
    1.31 +var VERSION = "ECMA_1";
    1.32 +startTest();
    1.33 +
    1.34 +writeHeaderToLog( SECTION + " [[Get]] (Value)");
    1.35 +
    1.36 +new TestCase( SECTION,  "var OBJ = new MyValuelessObject(true); OBJ.valueOf()",     true,           eval("var OBJ = new MyValuelessObject(true); OBJ.valueOf()") );
    1.37 +//    new TestCase( SECTION,  "var OBJ = new MyProtoValuelessObject(true); OBJ + ''",     "undefined",    eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") );
    1.38 +new TestCase( SECTION,  "var OBJ = new MyProtolessObject(true); OBJ.valueOf()",     true,           eval("var OBJ = new MyProtolessObject(true); OBJ.valueOf()") );
    1.39 +
    1.40 +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()") );
    1.41 +//    new TestCase( SECTION,  "var OBJ = new MyProtoValuelessObject(Number.POSITIVE_INFINITY); OBJ + ''",     "undefined",                        eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") );
    1.42 +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()") );
    1.43 +
    1.44 +new TestCase( SECTION,  "var OBJ = new MyValuelessObject('string'); OBJ.valueOf()",     'string',           eval("var OBJ = new MyValuelessObject('string'); OBJ.valueOf()") );
    1.45 +//    new TestCase( SECTION,  "var OBJ = new MyProtoValuelessObject('string'); OJ + ''",     "undefined",      eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") );
    1.46 +new TestCase( SECTION,  "var OBJ = new MyProtolessObject('string'); OBJ.valueOf()",     'string',           eval("var OBJ = new MyProtolessObject('string'); OBJ.valueOf()") );
    1.47 +
    1.48 +test();
    1.49 +
    1.50 +function MyProtoValuelessObject(value) {
    1.51 +  this.valueOf = new Function ( "" );
    1.52 +  this.__proto__ = null;
    1.53 +}
    1.54 +
    1.55 +function MyProtolessObject( value ) {
    1.56 +  this.valueOf = new Function( "return this.value" );
    1.57 +  this.__proto__ = null;
    1.58 +  this.value = value;
    1.59 +}
    1.60 +function MyValuelessObject(value) {
    1.61 +  this.__proto__ = new MyPrototypeObject(value);
    1.62 +}
    1.63 +function MyPrototypeObject(value) {
    1.64 +  this.valueOf = new Function( "return this.value;" );
    1.65 +  this.toString = new Function( "return (this.value + '');" );
    1.66 +  this.value = value;
    1.67 +}

mercurial