js/src/tests/ecma_5/misc/new-with-non-constructor.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/misc/new-with-non-constructor.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,39 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/licenses/publicdomain/
     1.7 + */
     1.8 +
     1.9 +function checkConstruct(thing, buggy) {
    1.10 +    try {
    1.11 +        new thing();
    1.12 +        assertEq(0, 1, "not reached " + thing);
    1.13 +    } catch (e) {
    1.14 +        if (buggy)
    1.15 +            assertEq(String(e.message).indexOf("is not a constructor") === -1, false);
    1.16 +        else
    1.17 +            assertEq(String(e.message).indexOf("thing is not a constructor") === -1, false);
    1.18 +    }
    1.19 +}
    1.20 +
    1.21 +var re = /aaa/
    1.22 +checkConstruct(re, false);
    1.23 +
    1.24 +var boundFunctionPrototype = Function.prototype.bind();
    1.25 +checkConstruct(boundFunctionPrototype, true);
    1.26 +
    1.27 +var boundBuiltin = Math.sin.bind();
    1.28 +checkConstruct(boundBuiltin, true);
    1.29 +
    1.30 +/* We set the proxies construct trap to undefined,
    1.31 + * so the call trap is used as constructor.
    1.32 + */
    1.33 +
    1.34 +var proxiedFunctionPrototype = Proxy.create({}, Function.prototype, undefined);
    1.35 +checkConstruct(proxiedFunctionPrototype, false);
    1.36 +
    1.37 +var proxiedBuiltin = Proxy.create({}, parseInt, undefined);
    1.38 +checkConstruct(proxiedBuiltin, false);
    1.39 +
    1.40 +
    1.41 +if (typeof reportCompare == 'function')
    1.42 +    reportCompare(0, 0, "ok");

mercurial