js/src/tests/ecma/extensions/15.5.4.5-6.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/extensions/15.5.4.5-6.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     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:          15.5.4.5-6.js
    1.12 +   ECMA Section:       15.5.4.5 String.prototype.charCodeAt(pos)
    1.13 +   Description:        Returns a number (a nonnegative integer less than 2^16)
    1.14 +   representing the Unicode encoding of the character at
    1.15 +   position pos in this string.  If there is no character
    1.16 +   at that position, the number is NaN.
    1.17 +
    1.18 +   When the charCodeAt method is called with one argument
    1.19 +   pos, the following steps are taken:
    1.20 +   1. Call ToString, giving it the theis value as its
    1.21 +   argument
    1.22 +   2. Call ToInteger(pos)
    1.23 +   3. Compute the number of characters in result(1).
    1.24 +   4. If Result(2) is less than 0 or is not less than
    1.25 +   Result(3), return NaN.
    1.26 +   5. Return a value of Number type, of positive sign, whose
    1.27 +   magnitude is the Unicode encoding of one character
    1.28 +   from result 1, namely the characer at position Result
    1.29 +   (2), where the first character in Result(1) is
    1.30 +   considered to be at position 0.
    1.31 +
    1.32 +   Note that the charCodeAt function is intentionally
    1.33 +   generic; it does not require that its this value be a
    1.34 +   String object.  Therefore it can be transferred to other
    1.35 +   kinds of objects for use as a method.
    1.36 +
    1.37 +   Author:             christine@netscape.com
    1.38 +   Date:               2 october 1997
    1.39 +*/
    1.40 +var SECTION = "15.5.4.5-6";
    1.41 +var VERSION = "ECMA_2";
    1.42 +startTest();
    1.43 +var TITLE   = "String.prototype.charCodeAt";
    1.44 +
    1.45 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.46 +
    1.47 +
    1.48 +new TestCase( SECTION,
    1.49 +	      "var obj = true; obj.__proto__.charCodeAt = String.prototype.charCodeAt; var s = ''; for ( var i = 0; i < 4; i++ ) s+= String.fromCharCode( obj.charCodeAt(i) ); s",
    1.50 +	      "true",
    1.51 +	      eval("var obj = true; obj.__proto__.charCodeAt = String.prototype.charCodeAt; var s = ''; for ( var i = 0; i < 4; i++ ) s+= String.fromCharCode( obj.charCodeAt(i) ); s") );
    1.52 +
    1.53 +new TestCase( SECTION,
    1.54 +	      "var obj = 1234; obj.__proto__.charCodeAt = String.prototype.charCodeAt; var s = ''; for ( var i = 0; i < 4; i++ ) s+= String.fromCharCode( obj.charCodeAt(i) ); s",
    1.55 +	      "1234",
    1.56 +	      eval("var obj = 1234; obj.__proto__.charCodeAt = String.prototype.charCodeAt; var s = ''; for ( var i = 0; i < 4; i++ ) s+= String.fromCharCode( obj.charCodeAt(i) ); s") );
    1.57 +
    1.58 +new TestCase( SECTION,
    1.59 +	      "var obj = 'hello'; obj.__proto__.charCodeAt = String.prototype.charCodeAt; var s = ''; for ( var i = 0; i < 5; i++ ) s+= String.fromCharCode( obj.charCodeAt(i) ); s",
    1.60 +	      "hello",
    1.61 +	      eval("var obj = 'hello'; obj.__proto__.charCodeAt = String.prototype.charCodeAt; var s = ''; for ( var i = 0; i < 5; i++ ) s+= String.fromCharCode( obj.charCodeAt(i) ); s") );
    1.62 +
    1.63 +test();

mercurial