js/src/tests/js1_5/Regress/regress-315974.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Regress/regress-315974.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     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 +/*
    1.12 +  This test case uses String.quote(), because that method uses the JS printf()
    1.13 +  functions internally. The printf() functions print to a char* buffer, causing
    1.14 +  conversion to and from UTF-8 if UTF-8 is enabled. If not, UTF-8 sequences are
    1.15 +  converted to ASCII \uXXXX sequences. Thus, both return values are acceptable.
    1.16 +*/
    1.17 +
    1.18 +var BUGNUMBER = 315974;
    1.19 +var summary = 'Test internal printf() for wide characters';
    1.20 +
    1.21 +printBugNumber(BUGNUMBER);
    1.22 +printStatus (summary);
    1.23 +
    1.24 +enterFunc (String (BUGNUMBER));
    1.25 +
    1.26 +var goodSurrogatePair = '\uD841\uDC42';
    1.27 +var badSurrogatePair = '\uD841badbad';
    1.28 +
    1.29 +var goodSurrogatePairQuotedUtf8 = '"\uD841\uDC42"';
    1.30 +var badSurrogatePairQuotedUtf8 = 'no error thrown!';
    1.31 +var goodSurrogatePairQuotedNoUtf8 = '"\\uD841\\uDC42"';
    1.32 +var badSurrogatePairQuotedNoUtf8 = '"\\uD841badbad"';
    1.33 +
    1.34 +var status = summary + ': String.quote() should pay respect to surrogate pairs';
    1.35 +var actual = goodSurrogatePair.quote();
    1.36 +/* Result in case UTF-8 is enabled. */
    1.37 +var expect = goodSurrogatePairQuotedUtf8;
    1.38 +/* Result in case UTF-8 is disabled. */
    1.39 +if (actual != expect && actual == goodSurrogatePairQuotedNoUtf8)
    1.40 +  expect = actual;
    1.41 +reportCompare(expect, actual, status);
    1.42 +
    1.43 +/*
    1.44 + * A malformed surrogate pair throws an out-of-memory error,
    1.45 + * but only if UTF-8 is enabled.
    1.46 + */
    1.47 +status = summary + ': String.quote() should throw error on bad surrogate pair';
    1.48 +/* Out of memory is not catchable. */
    1.49 +actual = badSurrogatePair.quote();
    1.50 +/* Come here only if UTF-8 is disabled. */
    1.51 +reportCompare(badSurrogatePairQuotedNoUtf8, actual, status);
    1.52 +
    1.53 +exitFunc (String (BUGNUMBER));

mercurial