js/src/tests/ecma_3/Object/8.6.1-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/Object/8.6.1-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     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 +var BUGNUMBER = 315436;
    1.12 +var summary = 'In strict mode, setting a read-only property should generate a warning';
    1.13 +
    1.14 +printBugNumber(BUGNUMBER);
    1.15 +printStatus (summary);
    1.16 +
    1.17 +enterFunc (String (BUGNUMBER));
    1.18 +
    1.19 +// should throw an error in strict mode
    1.20 +var actual = '';
    1.21 +var expect = '"length" is read-only';
    1.22 +var status = summary + ': Throw if STRICT and WERROR is enabled';
    1.23 +
    1.24 +if (!options().match(/strict/))
    1.25 +{
    1.26 +  options('strict');
    1.27 +}
    1.28 +if (!options().match(/werror/))
    1.29 +{
    1.30 +  options('werror');
    1.31 +}
    1.32 +
    1.33 +try
    1.34 +{
    1.35 +  var s = new String ('abc');
    1.36 +  s.length = 0;
    1.37 +}
    1.38 +catch (e)
    1.39 +{
    1.40 +  actual = e.message;
    1.41 +}
    1.42 +
    1.43 +reportCompare(expect, actual, status);
    1.44 +
    1.45 +// should not throw an error if in strict mode and WERROR is false
    1.46 +
    1.47 +actual = 'did not throw';
    1.48 +expect = 'did not throw';
    1.49 +var status = summary + ': Do not throw if STRICT is enabled and WERROR is disabled';
    1.50 +
    1.51 +// toggle werror off
    1.52 +options('werror');
    1.53 +
    1.54 +try
    1.55 +{
    1.56 +  s.length = 0;
    1.57 +}
    1.58 +catch (e)
    1.59 +{
    1.60 +  actual = e.message;
    1.61 +}
    1.62 +
    1.63 +reportCompare(expect, actual, status);
    1.64 +
    1.65 +// should not throw an error if not in strict mode
    1.66 +
    1.67 +actual = 'did not throw';
    1.68 +expect = 'did not throw';
    1.69 +var status = summary + ': Do not throw if not in strict mode';
    1.70 +
    1.71 +// toggle strict off
    1.72 +options('strict');
    1.73 +
    1.74 +try
    1.75 +{
    1.76 +  s.length = 0;
    1.77 +}
    1.78 +catch (e)
    1.79 +{
    1.80 +  actual = e.message;
    1.81 +}
    1.82 +
    1.83 +reportCompare(expect, actual, status);

mercurial