js/src/tests/test262/intl402/ch11/11.3/11.3_b.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3_b.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,33 @@
     1.4 +// Copyright 2012 Mozilla Corporation. All rights reserved.
     1.5 +// This code is governed by the BSD license found in the LICENSE file.
     1.6 +
     1.7 +/**
     1.8 + * @description Tests that Intl.NumberFormat.prototype functions throw a
     1.9 + *     TypeError if called on a non-object value or an object that hasn't been
    1.10 + *     initialized as a NumberFormat.
    1.11 + * @author Norbert Lindenberg
    1.12 + */
    1.13 +
    1.14 +var functions = {
    1.15 +    "format getter": Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get,
    1.16 +    resolvedOptions: Intl.NumberFormat.prototype.resolvedOptions
    1.17 +};
    1.18 +var invalidTargets = [undefined, null, true, 0, "NumberFormat", [], {}];
    1.19 +
    1.20 +Object.getOwnPropertyNames(functions).forEach(function (functionName) {
    1.21 +    var f = functions[functionName];
    1.22 +    invalidTargets.forEach(function (target) {
    1.23 +        var error;
    1.24 +        try {
    1.25 +            f.call(target);
    1.26 +        } catch (e) {
    1.27 +            error = e;
    1.28 +        }
    1.29 +        if (error === undefined) {
    1.30 +            $ERROR("Calling " + functionName + " on " + target + " was not rejected.");
    1.31 +        } else if (error.name !== "TypeError") {
    1.32 +            $ERROR("Calling " + functionName + " on " + target + " was rejected with wrong error " + error.name + ".");
    1.33 +        }
    1.34 +    });
    1.35 +});
    1.36 +

mercurial