summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Function/function-name-method.js
blob: 3b2eeee793d40490c62ab65f824a7a4ade6dbe1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var BUGNUMBER = 883377;
var summary = "Anonymous function name should be set based on method definition";

print(BUGNUMBER + ": " + summary);

var fooSymbol = Symbol("foo");
var emptySymbol = Symbol("");
var undefSymbol = Symbol();

function testMethod(prefix, classPrefix="", prototype=false) {
    var param = (prefix == "set" || prefix == "static set") ? "v" : "";
    var sep = classPrefix ? "" : ",";
    var objOrClass = eval(`(${classPrefix}{
        ${prefix} prop(${param}) {} ${sep}
        ${prefix} "literal"(${param}) {} ${sep}
        ${prefix} ""(${param}) {} ${sep}
        ${prefix} 5(${param}) {} ${sep}
        ${prefix} [Symbol.iterator](${param}) {} ${sep}
        ${prefix} [fooSymbol](${param}) {} ${sep}
        ${prefix} [emptySymbol](${param}) {} ${sep}
        ${prefix} [undefSymbol](${param}) {} ${sep}
        ${prefix} [/a/](${param}) {} ${sep}
    })`);

    var target = prototype ? objOrClass.prototype : objOrClass;

    function testOne(methodName, expectedName) {
        var f;
        if (prefix == "get" || prefix == "static get") {
            f = Object.getOwnPropertyDescriptor(target, methodName).get;
            expectedName = "get " + expectedName;
        } else if (prefix == "set" || prefix == "static set") {
            f = Object.getOwnPropertyDescriptor(target, methodName).set;
            expectedName = "set " + expectedName;
        } else {
            f = Object.getOwnPropertyDescriptor(target, methodName).value;
        }

        assertEq(f.name, expectedName);
    }
    testOne("prop", "prop");
    testOne("literal", "literal");
    testOne("", "");
    testOne(5, "5");
    testOne(Symbol.iterator, "[Symbol.iterator]");
    testOne(fooSymbol, "[foo]");
    testOne(emptySymbol, "[]");
    testOne(undefSymbol, "");
    testOne(/a/, "/a/");
}
testMethod("");
testMethod("*");
testMethod("async");
testMethod("get");
testMethod("set");

testMethod("", "class", true);
testMethod("*", "class", true);
testMethod("async", "class", true);
testMethod("get", "class", true);
testMethod("set", "class", true);

testMethod("static", "class");
testMethod("static *", "class");
testMethod("static async", "class");
testMethod("static get", "class");
testMethod("static set", "class");

if (typeof reportCompare === "function")
    reportCompare(0, 0);