js/src/tests/test262/intl402/ch12/12.1/12.1.1_1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,43 @@
     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 an object can't be re-initialized as a DateTimeFormat.
     1.9 + * @author Norbert Lindenberg
    1.10 + */
    1.11 +
    1.12 +$INCLUDE("testIntl.js");
    1.13 +
    1.14 +testWithIntlConstructors(function (Constructor) {
    1.15 +    var obj, error;
    1.16 +    
    1.17 +    // variant 1: use constructor in a "new" expression
    1.18 +    obj = new Constructor();
    1.19 +    try {
    1.20 +        Intl.DateTimeFormat.call(obj);
    1.21 +    } catch (e) {
    1.22 +        error = e;
    1.23 +    }
    1.24 +    if (error === undefined) {
    1.25 +        $ERROR("Re-initializing object created with \"new\" as DateTimeFormat was not rejected.");
    1.26 +    } else if (error.name !== "TypeError") {
    1.27 +        $ERROR("Re-initializing object created with \"new\" as DateTimeFormat was rejected with wrong error " + error.name + ".");
    1.28 +    }
    1.29 +    
    1.30 +    // variant 2: use constructor as a function
    1.31 +    obj = Constructor.call({});
    1.32 +    error = undefined;
    1.33 +    try {
    1.34 +        Intl.DateTimeFormat.call(obj);
    1.35 +    } catch (e) {
    1.36 +        error = e;
    1.37 +    }
    1.38 +    if (error === undefined) {
    1.39 +        $ERROR("Re-initializing object created with constructor as function as DateTimeFormat was not rejected.");
    1.40 +    } else if (error.name !== "TypeError") {
    1.41 +        $ERROR("Re-initializing object created with constructor as function as DateTimeFormat was rejected with wrong error " + error.name + ".");
    1.42 +    }
    1.43 +    
    1.44 +    return true;
    1.45 +});
    1.46 +

mercurial