Skip to content

Truly independent web browser

38.1 KB
Raw Blame
// The text of a reference comes from the source when an error gets thrown, so that how the source is written matters.
const object = {
    m() {
        return this;
    },
    g: 1,
    K: function () {},
    a2: [1, 2],
    tag() {},
};
object.o = object;

function Constructor() {}
Constructor.prototype = object;
Constructor.nope = undefined;

class Base {}
Base.prototype.m = function () {
    return this;
};

const names = ["o", "u", "nk", "kg", "i0", "a2", "nf", "C", "K0", "f0", "tag", "it"];
const values = [
    object,
    undefined,
    "nope",
    "g",
    0,
    [1, 2],
    5,
    Constructor,
    Base,
    function () {},
    function () {},
    { [Symbol.iterator]: () => ({ next: () => ({ done: true }) }) },
];

function expectMessage(source, message) {
    const f = new Function(...names, source);
    expect(() => f.call(object, ...values)).toThrowWithMessage(TypeError, message);
}

test("calls of members", () => {
    const cases = [
        ["u()", "undefined is not a function (evaluated from 'u')"],
        ["u(\n   )", "undefined is not a function (evaluated from 'u')"],
        ["o.nope()", "undefined is not a function (evaluated from 'o.nope')"],
        ["o\n    .nope(\n   )", "undefined is not a function (evaluated from 'o.nope')"],
        ["o.o.nope()", "undefined is not a function (evaluated from 'o.o.nope')"],
        ["o\n    .o\n    .nope(\n   )", "undefined is not a function (evaluated from 'o.o.nope')"],
        ['o["nope"]()', "undefined is not a function (evaluated from 'o['nope']')"],
        ['o["nope"](\n   )', "undefined is not a function (evaluated from 'o['nope']')"],
        ["o[nk]()", "undefined is not a function (evaluated from 'o[nk]')"],
        ["o[nk](\n   )", "undefined is not a function (evaluated from 'o[nk]')"],
        ["o.m().nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["o\n    .m(\n   )\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ['o.m()["nope"]()', "undefined is not a function (evaluated from '<object>['nope']')"],
        ['o\n    .m(\n   )["nope"](\n   )', "undefined is not a function (evaluated from '<object>['nope']')"],
        ["o?.nope()", "undefined is not a function"],
        ["o?.nope(\n   )", "undefined is not a function"],
        ["o?.o.nope()", "undefined is not a function"],
        ["o?.o\n    .nope(\n   )", "undefined is not a function"],
        ['o?.["nope"]()', "undefined is not a function"],
        ['o?.["nope"](\n   )', "undefined is not a function"],
        ["new o.nope()", "undefined is not a constructor (evaluated from 'o.nope')"],
        ["new o\n    .nope(\n   )", "undefined is not a constructor (evaluated from 'o.nope')"],
        ["new o.nope", "undefined is not a constructor (evaluated from 'o.nope')"],
        ["new o\n    .nope", "undefined is not a constructor (evaluated from 'o.nope')"],
        ["new u()", "undefined is not a constructor (evaluated from 'u')"],
        ["new u(\n   )", "undefined is not a constructor (evaluated from 'u')"],
        ["new o.g()", "1 is not a constructor (evaluated from 'o.g')"],
        ["new o\n    .g(\n   )", "1 is not a constructor (evaluated from 'o.g')"],
        ["new (o.nope)()", "undefined is not a constructor (evaluated from 'o.nope')"],
        ["new (\n   o\n    .nope)(\n   )", "undefined is not a constructor (evaluated from 'o.nope')"],
        ["new (o.m())()", "[object Object] is not a constructor"],
        ["new (\n   o\n    .m(\n   ))()", "[object Object] is not a constructor"],
        ["new (o.m().nope)()", "undefined is not a constructor (evaluated from '<object>.nope')"],
        ["new (\n   o\n    .m(\n   )\n    .nope)()", "undefined is not a constructor (evaluated from '<object>.nope')"],
        ["new nf()", "5 is not a constructor (evaluated from 'nf')"],
        ["new nf(\n   )", "5 is not a constructor (evaluated from 'nf')"],
        ["new o.o.nope()", "undefined is not a constructor (evaluated from 'o.o.nope')"],
        ["new o\n    .o\n    .nope(\n   )", "undefined is not a constructor (evaluated from 'o.o.nope')"],
        ['new o["nope"]()', "undefined is not a constructor (evaluated from 'o['nope']')"],
        ['new o["nope"](\n   )', "undefined is not a constructor (evaluated from 'o['nope']')"],
        ["new o[nk]()", "undefined is not a constructor (evaluated from 'o[nk]')"],
        ["new o[nk](\n   )", "undefined is not a constructor (evaluated from 'o[nk]')"],
        ["nf()", "5 is not a function (evaluated from 'nf')"],
        ["nf(\n   )", "5 is not a function (evaluated from 'nf')"],
        ["1()", "1 is not a function"],
        ["1(\n   )", "1 is not a function"],
        ['"s"()', "s is not a function"],
        ['"s"(\n   )', "s is not a function"],
        ["null()", "null is not a function"],
        ["null(\n   )", "null is not a function"],
        ["o.g()", "1 is not a function (evaluated from 'o.g')"],
        ["o\n    .g(\n   )", "1 is not a function (evaluated from 'o.g')"],
        ["o.o()", "[object Object] is not a function (evaluated from 'o.o')"],
        ["o\n    .o(\n   )", "[object Object] is not a function (evaluated from 'o.o')"],
        ["(o.nope)()", "undefined is not a function (evaluated from 'o.nope')"],
        ["(\n   o\n    .nope)(\n   )", "undefined is not a function (evaluated from 'o.nope')"],
        ["(o.m().nope)()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(\n   o\n    .m(\n   )\n    .nope)()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(o).nope()", "undefined is not a function (evaluated from 'o.nope')"],
        ["(\n   o)\n    .nope(\n   )", "undefined is not a function (evaluated from 'o.nope')"],
        ["((o)).nope()", "undefined is not a function (evaluated from 'o.nope')"],
        ["(\n   (\n   o))\n    .nope()", "undefined is not a function (evaluated from 'o.nope')"],
        ["(o.o).nope()", "undefined is not a function (evaluated from 'o.o.nope')"],
        ["(\n   o\n    .o)\n    .nope(\n   )", "undefined is not a function (evaluated from 'o.o.nope')"],
        ["(0, o.nope)()", "undefined is not a function"],
        ["(\n   0, o\n    .nope)(\n   )", "undefined is not a function"],
        ["(u || o).nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(\n   u || o)\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(u ?? o).nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(\n   u ?? o)\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(1 + 2)()", "3 is not a function"],
        ["(\n   1 + 2)(\n   )", "3 is not a function"],
        ["(o, o).nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(\n   o, o)\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(function () {}).nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(\n   function (\n   ) {})\n    .nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(() => {}).nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(\n   (\n   ) => {})\n    .nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(class {}).nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(\n   class {})\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["[].nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["[]\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["[1, 2].nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["[1, 2]\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["[o][0].nope()", "undefined is not a function (evaluated from '<object>[0].nope')"],
        ["[o][0]\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>[0].nope')"],
        ["({}).nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(\n   {})\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["({a: 1}).nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(\n   {a: 1})\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ['"str".nope()', "undefined is not a function (evaluated from ''str'.nope')"],
        ['"str".nope(\n   )', "undefined is not a function (evaluated from ''str'.nope')"],
        ["'str'.nope()", "undefined is not a function (evaluated from ''str'.nope')"],
        ["'str'.nope(\n   )", "undefined is not a function (evaluated from ''str'.nope')"],
        ['"s\'q".nope()', "undefined is not a function (evaluated from ''s'q'.nope')"],
        ['"s\'q".nope(\n   )', "undefined is not a function (evaluated from ''s'q'.nope')"],
        ["`tpl`.nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["`tpl`.nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["`t${1}`.nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["`t${1}`.nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["1 .nope()", "undefined is not a function (evaluated from '1.nope')"],
        ["1 .nope(\n   )", "undefined is not a function (evaluated from '1.nope')"],
        ["1.5.nope()", "undefined is not a function (evaluated from '1.5.nope')"],
        ["1.5\n    .nope(\n   )", "undefined is not a function (evaluated from '1.5.nope')"],
        ["(1).nope()", "undefined is not a function (evaluated from '1.nope')"],
        ["(\n   1)\n    .nope(\n   )", "undefined is not a function (evaluated from '1.nope')"],
        ["0x10.nope()", "undefined is not a function (evaluated from '16.nope')"],
        ["0x10\n    .nope(\n   )", "undefined is not a function (evaluated from '16.nope')"],
        ["1n.nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["1n\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["true.nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["true\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["/re/.nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["/re/.nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["this.nope()", "undefined is not a function (evaluated from 'this.nope')"],
        ["this\n    .nope(\n   )", "undefined is not a function (evaluated from 'this.nope')"],
        ["this.o.nope()", "undefined is not a function (evaluated from 'this.o.nope')"],
        ["this\n    .o\n    .nope(\n   )", "undefined is not a function (evaluated from 'this.o.nope')"],
        ['this["nope"]()', "undefined is not a function (evaluated from 'this['nope']')"],
        ['this["nope"](\n   )', "undefined is not a function (evaluated from 'this['nope']')"],
        ["new C().nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["new C(\n   )\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["new C().m().nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["new C(\n   )\n    .m(\n   )\n    .nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["new C.nope()", "undefined is not a constructor (evaluated from 'C.nope')"],
        ["new C\n    .nope(\n   )", "undefined is not a constructor (evaluated from 'C.nope')"],
        ["new o.K().nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["new o\n    .K(\n   )\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ['new C()["nope"]()', "undefined is not a function (evaluated from '<object>['nope']')"],
        ['new C(\n   )["nope"](\n   )', "undefined is not a function (evaluated from '<object>['nope']')"],
        ["new C()[nk]()", "undefined is not a function (evaluated from '<object>[nk]')"],
        ["new C(\n   )[nk](\n   )", "undefined is not a function (evaluated from '<object>[nk]')"],
        ["f0()()", "undefined is not a function"],
        ["f0(\n   )(\n   )", "undefined is not a function"],
        ["a2[0].nope()", "undefined is not a function (evaluated from 'a2[0].nope')"],
        ["a2[0]\n    .nope(\n   )", "undefined is not a function (evaluated from 'a2[0].nope')"],
        ["a2[0]()", "1 is not a function (evaluated from 'a2[0]')"],
        ["a2[0](\n   )", "1 is not a function (evaluated from 'a2[0]')"],
        ["a2[1 + 0]()", "2 is not a function (evaluated from 'a2[<object>]')"],
        ["a2[1 + 0](\n   )", "2 is not a function (evaluated from 'a2[<object>]')"],
        ["a2[i0]()", "1 is not a function (evaluated from 'a2[i0]')"],
        ["a2[i0](\n   )", "1 is not a function (evaluated from 'a2[i0]')"],
        ["a2[i0 + 1]()", "2 is not a function (evaluated from 'a2[<object>]')"],
        ["a2[i0 + 1](\n   )", "2 is not a function (evaluated from 'a2[<object>]')"],
        ["a2[f0()]()", "undefined is not a function (evaluated from 'a2[<object>]')"],
        ["a2[f0(\n   )](\n   )", "undefined is not a function (evaluated from 'a2[<object>]')"],
        ["a2[o.g]()", "2 is not a function (evaluated from 'a2[o.g]')"],
        ["a2[o\n    .g](\n   )", "2 is not a function (evaluated from 'a2[o.g]')"],
        ["a2[o.m()]()", "undefined is not a function (evaluated from 'a2[<object>]')"],
        ["a2[o\n    .m(\n   )](\n   )", "undefined is not a function (evaluated from 'a2[<object>]')"],
        ['a2["x"]()', "undefined is not a function (evaluated from 'a2['x']')"],
        ['a2["x"](\n   )', "undefined is not a function (evaluated from 'a2['x']')"],
        ["a2['x']()", "undefined is not a function (evaluated from 'a2['x']')"],
        ["a2['x'](\n   )", "undefined is not a function (evaluated from 'a2['x']')"],
        ["a2[`x`]()", "undefined is not a function (evaluated from 'a2[<object>]')"],
        ["a2[`x`](\n   )", "undefined is not a function (evaluated from 'a2[<object>]')"],
        ["a2[1.5]()", "undefined is not a function (evaluated from 'a2[1.5]')"],
        ["a2[1.5](\n   )", "undefined is not a function (evaluated from 'a2[1.5]')"],
        ["a2[-1]()", "undefined is not a function (evaluated from 'a2[<object>]')"],
        ["a2[-1](\n   )", "undefined is not a function (evaluated from 'a2[<object>]')"],
        ["a2[this]()", "undefined is not a function (evaluated from 'a2[this]')"],
        ["a2[this](\n   )", "undefined is not a function (evaluated from 'a2[this]')"],
        ["o.a2[0]()", "1 is not a function (evaluated from 'o.a2[0]')"],
        ["o\n    .a2[0](\n   )", "1 is not a function (evaluated from 'o.a2[0]')"],
        ["o.a2[0].nope()", "undefined is not a function (evaluated from 'o.a2[0].nope')"],
        ["o\n    .a2[0]\n    .nope(\n   )", "undefined is not a function (evaluated from 'o.a2[0].nope')"],
        ["o.a2[o.g]()", "2 is not a function (evaluated from 'o.a2[o.g]')"],
        ["o\n    .a2[o\n    .g](\n   )", "2 is not a function (evaluated from 'o.a2[o.g]')"],
        ["f0(1)(2)", "undefined is not a function"],
        ["f0(\n   1)(\n   2)", "undefined is not a function"],
        ['o.m(1, "a").nope()', "undefined is not a function (evaluated from '<object>.nope')"],
        ['o\n    .m(\n   1, "a")\n    .nope(\n   )', "undefined is not a function (evaluated from '<object>.nope')"],
        ["o.m(function () {}).nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        [
            "o\n    .m(\n   function (\n   ) {})\n    .nope()",
            "undefined is not a function (evaluated from '<object>.nope')",
        ],
        ["o /* c */ .nope()", "undefined is not a function (evaluated from 'o.nope')"],
        ["o /* c */ .nope(\n   )", "undefined is not a function (evaluated from 'o.nope')"],
        ["o // c\n  .nope()", "undefined is not a function (evaluated from 'o.nope')"],
        ["o // c\n  .nope(\n   )", "undefined is not a function (evaluated from 'o.nope')"],
        ["o\n  .nope()", "undefined is not a function (evaluated from 'o.nope')"],
        ["o\n  .nope(\n   )", "undefined is not a function (evaluated from 'o.nope')"],
        ["o.\n  nope()", "undefined is not a function (evaluated from 'o.nope')"],
        ["o.\n  nope(\n   )", "undefined is not a function (evaluated from 'o.nope')"],
        ["o.m()\n  .nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["o\n    .m(\n   )\n  .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["o . nope ()", "undefined is not a function (evaluated from 'o.nope')"],
        ["o . nope (\n   )", "undefined is not a function (evaluated from 'o.nope')"],
        ["o.nope ()", "undefined is not a function (evaluated from 'o.nope')"],
        ["o\n    .nope (\n   )", "undefined is not a function (evaluated from 'o.nope')"],
        ["o.nope  (1)", "undefined is not a function (evaluated from 'o.nope')"],
        ["o\n    .nope  (\n   1)", "undefined is not a function (evaluated from 'o.nope')"],
        ['o["nope"] ()', "undefined is not a function (evaluated from 'o['nope']')"],
        ['o["nope"] (\n   )', "undefined is not a function (evaluated from 'o['nope']')"],
        ['o[ "nope" ]()', "undefined is not a function (evaluated from 'o['nope']')"],
        ['o[ "nope" ](\n   )', "undefined is not a function (evaluated from 'o['nope']')"],
        ["o[ nk ]()", "undefined is not a function (evaluated from 'o[nk]')"],
        ["o[ nk ](\n   )", "undefined is not a function (evaluated from 'o[nk]')"],
        ["o [nk]()", "undefined is not a function (evaluated from 'o[nk]')"],
        ["o [nk](\n   )", "undefined is not a function (evaluated from 'o[nk]')"],
        [
            "class S1 extends K0 { m() { super.nope() } } new S1().m()",
            "undefined is not a function (evaluated from '<object>.nope')",
        ],
        [
            "class S1 extends K0 { m(\n   ) { super\n    .nope(\n   ) } } new S1()\n    .m()",
            "undefined is not a function (evaluated from '<object>.nope')",
        ],
        [
            'class S2 extends K0 { m() { super["nope"]() } } new S2().m()',
            "undefined is not a function (evaluated from '<object>['nope']')",
        ],
        [
            'class S2 extends K0 { m(\n   ) { super["nope"](\n   ) } } new S2()\n    .m()',
            "undefined is not a function (evaluated from '<object>['nope']')",
        ],
        [
            "class S3 extends K0 { m() { super[nk]() } } new S3().m()",
            "undefined is not a function (evaluated from '<object>[nk]')",
        ],
        [
            "class S3 extends K0 { m(\n   ) { super[nk](\n   ) } } new S3()\n    .m()",
            "undefined is not a function (evaluated from '<object>[nk]')",
        ],
        [
            "class S6 extends K0 { m() { super.m().nope() } } new S6().m()",
            "undefined is not a function (evaluated from '<object>.nope')",
        ],
        [
            "class S6 extends K0 { m(\n   ) { super\n    .m(\n   )\n    .nope() } } new S6()\n    .m()",
            "undefined is not a function (evaluated from '<object>.nope')",
        ],
        ["class S7 extends u { }", "Class extends value undefined is not a constructor or null"],
        ["tag`x``y`", "undefined is not a function"],
        ["o.nope`x`", "undefined is not a function"],
        ["o\n    .nope`x`", "undefined is not a function"],
        ['o["nope"]`x`', "undefined is not a function"],
        ["o.m().nope`x`", "undefined is not a function"],
        ["o\n    .m(\n   )\n    .nope`x`", "undefined is not a function"],
        ["nf`x`", "5 is not a function"],
        ["u`x`", "undefined is not a function"],
        ["new o.nope`x`", "undefined is not a function"],
        ["new o\n    .nope`x`", "undefined is not a function"],
        ["(o.nope)`x`", "undefined is not a function"],
        ["(\n   o\n    .nope)`x`", "undefined is not a function"],
        ["o?.m().nope()", "undefined is not a function"],
        ["o?.m(\n   )\n    .nope(\n   )", "undefined is not a function"],
        ["o?.m()?.nope()", "undefined is not a function"],
        ["o?.m(\n   )?.nope(\n   )", "undefined is not a function"],
        ["o?.m?.().nope()", "undefined is not a function"],
        ["o?.m?.(\n   )\n    .nope(\n   )", "undefined is not a function"],
        ["o.m?.().nope()", "undefined is not a function"],
        ["o\n    .m?.(\n   )\n    .nope(\n   )", "undefined is not a function"],
        ['o?.m()["nope"]()', "undefined is not a function"],
        ['o?.m(\n   )["nope"](\n   )', "undefined is not a function"],
        ['o?.["m"]().nope()', "undefined is not a function"],
        ['o?.["m"](\n   )\n    .nope(\n   )', "undefined is not a function"],
        ["(o?.nope)()", "undefined is not a function"],
        ["(\n   o?.nope)(\n   )", "undefined is not a function"],
        ["(o?.o).nope()", "undefined is not a function (evaluated from '<object>.nope')"],
        ["(\n   o?.o)\n    .nope(\n   )", "undefined is not a function (evaluated from '<object>.nope')"],
        ["o.nope(...[1])", "undefined is not a function (evaluated from 'o.nope')"],
        ["o\n    .nope(\n   ...[1])", "undefined is not a function (evaluated from 'o.nope')"],
        ["o.nope(...it)", "undefined is not a function (evaluated from 'o.nope')"],
        ["o\n    .nope(\n   ...it)", "undefined is not a function (evaluated from 'o.nope')"],
        ["new o.nope(...it)", "undefined is not a constructor (evaluated from 'o.nope')"],
        ["new o\n    .nope(\n   ...it)", "undefined is not a constructor (evaluated from 'o.nope')"],
        ["new nf(...it)", "5 is not a constructor (evaluated from 'nf')"],
        ["new nf(\n   ...it)", "5 is not a constructor (evaluated from 'nf')"],
        ["nf(...it)", "5 is not a function (evaluated from 'nf')"],
        ["nf(\n   ...it)", "5 is not a function (evaluated from 'nf')"],
        ["u(...it)", "undefined is not a function (evaluated from 'u')"],
        ["u(\n   ...it)", "undefined is not a function (evaluated from 'u')"],
        ["o.m().nope(...it)", "undefined is not a function (evaluated from '<object>.nope')"],
        ["o\n    .m(\n   )\n    .nope(\n   ...it)", "undefined is not a function (evaluated from '<object>.nope')"],
        ["f0()(...it)", "undefined is not a function"],
        ["f0(\n   )(\n   ...it)", "undefined is not a function"],
        ["a2[o.g](...it)", "2 is not a function (evaluated from 'a2[o.g]')"],
        ["a2[o\n    .g](\n   ...it)", "2 is not a function (evaluated from 'a2[o.g]')"],
        ["o instanceof o", "[object Object] is not a function"],
        ["o.o.o.nope()", "undefined is not a function (evaluated from 'o.o.o.nope')"],
        ["o\n    .o\n    .o\n    .nope(\n   )", "undefined is not a function (evaluated from 'o.o.o.nope')"],
        ["[u][0]()", "undefined is not a function (evaluated from '<object>[0]')"],
        ["[u][0](\n   )", "undefined is not a function (evaluated from '<object>[0]')"],
        ["({}).x()", "undefined is not a function (evaluated from '<object>.x')"],
        ["(\n   {})\n    .x(\n   )", "undefined is not a function (evaluated from '<object>.x')"],
        ["a2[9]()", "undefined is not a function (evaluated from 'a2[9]')"],
        ["a2[9](\n   )", "undefined is not a function (evaluated from 'a2[9]')"],
        ["new C.x", "undefined is not a constructor (evaluated from 'C.x')"],
        ["new C\n    .x", "undefined is not a constructor (evaluated from 'C.x')"],
    ];
    for (const [source, message] of cases) expectMessage(source, message);
});

test("bases of member accesses", () => {
    const cases = [
        ["u.x", 'Cannot access property "x" on undefined object "u"'],
        ["u\n    .x", 'Cannot access property "x" on undefined object "u"'],
        ["u.x.y", 'Cannot access property "x" on undefined object "u"'],
        ["u\n    .x\n    .y", 'Cannot access property "x" on undefined object "u"'],
        ['u["x"]', 'Cannot access property "x" on undefined object "u"'],
        ["u[kg]", 'Cannot access property "g" on undefined object "u"'],
        ["u.x = 1", 'Cannot access property "x" on undefined object "u"'],
        ["u\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object "u"'],
        ['u["x"] = 1', 'Cannot access property "x" on undefined object "u"'],
        ['u["x"]\n    =\n    1', 'Cannot access property "x" on undefined object "u"'],
        ["u[kg] = 1", 'Cannot access property "g" on undefined object "u"'],
        ["u[kg]\n    =\n    1", 'Cannot access property "g" on undefined object "u"'],
        ["u.x += 1", 'Cannot access property "x" on undefined object "u"'],
        ["u\n    .x += 1", 'Cannot access property "x" on undefined object "u"'],
        ["u.x++", 'Cannot access property "x" on undefined object "u"'],
        ["u\n    .x++", 'Cannot access property "x" on undefined object "u"'],
        ["u.x()", 'Cannot access property "x" on undefined object "u"'],
        ["u\n    .x(\n   )", 'Cannot access property "x" on undefined object "u"'],
        ["o.nope.x", 'Cannot access property "x" on undefined object "o.nope"'],
        ["o\n    .nope\n    .x", 'Cannot access property "x" on undefined object "o.nope"'],
        ["o.nope.x()", 'Cannot access property "x" on undefined object "o.nope"'],
        ["o\n    .nope\n    .x(\n   )", 'Cannot access property "x" on undefined object "o.nope"'],
        ["o.m().nope.x", 'Cannot access property "x" on undefined object ".nope"'],
        ["o\n    .m(\n   )\n    .nope\n    .x", 'Cannot access property "x" on undefined object ".nope"'],
        ["o.m().nope.x = 1", 'Cannot access property "x" on undefined object ".nope"'],
        ["o\n    .m(\n   )\n    .nope\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object ".nope"'],
        ["o.nope.x = 1", 'Cannot access property "x" on undefined object "o.nope"'],
        ["o\n    .nope\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object "o.nope"'],
        ["o.nope[kg] = 1", 'Cannot access property "g" on undefined object "o.nope"'],
        ["o\n    .nope[kg]\n    =\n    1", 'Cannot access property "g" on undefined object "o.nope"'],
        ["o[nk].x", 'Cannot access property "x" on undefined object "o[nk]"'],
        ["o[nk]\n    .x", 'Cannot access property "x" on undefined object "o[nk]"'],
        ["o[nk].x = 1", 'Cannot access property "x" on undefined object "o[nk]"'],
        ["o[nk]\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object "o[nk]"'],
        ["o?.nope.x", 'Cannot access property "x" on undefined object'],
        ["o?.nope\n    .x", 'Cannot access property "x" on undefined object'],
        ["(function () {})().nope()", 'Cannot access property "nope" on undefined object'],
        ["(\n   function (\n   ) {})()\n    .nope()", 'Cannot access property "nope" on undefined object'],
        ["tag`x`.nope()", 'Cannot access property "nope" on undefined object'],
        ["tag`x`.nope(\n   )", 'Cannot access property "nope" on undefined object'],
        ["null.nope()", 'Cannot access property "nope" on null object'],
        ["null\n    .nope(\n   )", 'Cannot access property "nope" on null object'],
        ["new o.K().o.nope()", 'Cannot access property "nope" on undefined object ".o"'],
        ["new o\n    .K(\n   )\n    .o\n    .nope(\n   )", 'Cannot access property "nope" on undefined object ".o"'],
        ["f0().nope()", 'Cannot access property "nope" on undefined object'],
        ["f0(\n   )\n    .nope(\n   )", 'Cannot access property "nope" on undefined object'],
        ["f0()[kg]()", 'Cannot access property "g" on undefined object'],
        ["f0(\n   )[kg](\n   )", 'Cannot access property "g" on undefined object'],
        ["f0().x", 'Cannot access property "x" on undefined object'],
        ["f0(\n   )\n    .x", 'Cannot access property "x" on undefined object'],
        ["f0().x = 1", 'Cannot access property "x" on undefined object'],
        ["f0(\n   )\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object'],
        ["f0().x.y", 'Cannot access property "x" on undefined object'],
        ["f0(\n   )\n    .x\n    .y", 'Cannot access property "x" on undefined object'],
        ["a2[nk].nope()", 'Cannot access property "nope" on undefined object "a2[nk]"'],
        ["a2[nk]\n    .nope(\n   )", 'Cannot access property "nope" on undefined object "a2[nk]"'],
        ["f0(1, 2).nope()", 'Cannot access property "nope" on undefined object'],
        ["f0(\n   1, 2)\n    .nope(\n   )", 'Cannot access property "nope" on undefined object'],
        [
            "class S4 extends K0 { m() { super.nope.x } } new S4().m()",
            'Cannot access property "x" on undefined object ".nope"',
        ],
        [
            "class S4 extends K0 { m(\n   ) { super\n    .nope\n    .x } } new S4(\n   )\n    .m()",
            'Cannot access property "x" on undefined object ".nope"',
        ],
        [
            "class S5 extends K0 { m() { super.nope.x() } } new S5().m()",
            'Cannot access property "x" on undefined object ".nope"',
        ],
        [
            "class S5 extends K0 { m(\n   ) { super\n    .nope\n    .x(\n   ) } } new S5()\n    .m()",
            'Cannot access property "x" on undefined object ".nope"',
        ],
        ["u.x`x`", 'Cannot access property "x" on undefined object "u"'],
        ["u\n    .x`x`", 'Cannot access property "x" on undefined object "u"'],
        ["(o?.nope).x", 'Cannot access property "x" on undefined object'],
        ["(\n   o?.nope)\n    .x", 'Cannot access property "x" on undefined object'],
        ["(o?.nope).x = 1", 'Cannot access property "x" on undefined object'],
        ["(\n   o?.nope)\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object'],
        ["({x: u.y} = {})", 'Cannot access property "y" on undefined object'],
        ["(\n   {x: u\n    .y}\n    =\n    {})", 'Cannot access property "y" on undefined object'],
        ["[u.y] = [1]", 'Cannot access property "y" on undefined object'],
        ["[u\n    .y]\n    =\n    [1]", 'Cannot access property "y" on undefined object'],
        ["for (u.x of [1]);", 'Cannot access property "x" on undefined object'],
        ["for (\n   u\n    .x of [1]);", 'Cannot access property "x" on undefined object'],
        ["for (u.x in {a: 1});", 'Cannot access property "x" on undefined object'],
        ["for (\n   u\n    .x in {a: 1});", 'Cannot access property "x" on undefined object'],
        ["u.x(...it)", 'Cannot access property "x" on undefined object "u"'],
        ["u\n    .x(\n   ...it)", 'Cannot access property "x" on undefined object "u"'],
        ["(1).x.y", 'Cannot access property "y" on undefined object "1.x"'],
        ["(\n   1)\n    .x\n    .y", 'Cannot access property "y" on undefined object "1.x"'],
        ['"s".x.y', 'Cannot access property "y" on undefined object "\'s\'.x"'],
        ['"s".x\n    .y', 'Cannot access property "y" on undefined object "\'s\'.x"'],
        ["o.g.x.y.z", 'Cannot access property "y" on undefined object "o.g.x"'],
        ["o\n    .g\n    .x\n    .y\n    .z", 'Cannot access property "y" on undefined object "o.g.x"'],
        ["o.o.o.nope.x", 'Cannot access property "x" on undefined object "o.o.o.nope"'],
        ["o\n    .o\n    .o\n    .nope\n    .x", 'Cannot access property "x" on undefined object "o.o.o.nope"'],
        ["u.x?.y", 'Cannot access property "x" on undefined object "u"'],
        ["u\n    .x?.y", 'Cannot access property "x" on undefined object "u"'],
        ["(u).x", 'Cannot access property "x" on undefined object "u"'],
        ["(\n   u)\n    .x", 'Cannot access property "x" on undefined object "u"'],
        ["(u.x)", 'Cannot access property "x" on undefined object "u"'],
        ["(\n   u\n    .x)", 'Cannot access property "x" on undefined object "u"'],
        ["(u).x = 1", 'Cannot access property "x" on undefined object "u"'],
        ["(\n   u)\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object "u"'],
        ["((u)).x", 'Cannot access property "x" on undefined object "u"'],
        ["(\n   (\n   u))\n    .x", 'Cannot access property "x" on undefined object "u"'],
        ["(1, u).x", 'Cannot access property "x" on undefined object'],
        ["(\n   1, u)\n    .x", 'Cannot access property "x" on undefined object'],
        ["(u || u).x", 'Cannot access property "x" on undefined object'],
        ["(\n   u || u)\n    .x", 'Cannot access property "x" on undefined object'],
        ["(u ? u : u).x", 'Cannot access property "x" on undefined object'],
        ["(\n   u ? u : u)\n    .x", 'Cannot access property "x" on undefined object'],
        ["(o.nope).x", 'Cannot access property "x" on undefined object "o.nope"'],
        ["(\n   o\n    .nope)\n    .x", 'Cannot access property "x" on undefined object "o.nope"'],
        ["(o.m().nope).x", 'Cannot access property "x" on undefined object ".nope"'],
        ["(\n   o\n    .m(\n   )\n    .nope)\n    .x", 'Cannot access property "x" on undefined object ".nope"'],
        ["(f0()).x", 'Cannot access property "x" on undefined object'],
        ["(\n   f0(\n   ))\n    .x", 'Cannot access property "x" on undefined object'],
        ["(f0()).x = 1", 'Cannot access property "x" on undefined object'],
        ["(\n   f0(\n   ))\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object'],
        ["(function () {})().x", 'Cannot access property "x" on undefined object'],
        ["(\n   function (\n   ) {})()\n    .x", 'Cannot access property "x" on undefined object'],
        ["[][0].x", 'Cannot access property "x" on undefined object "[0]"'],
        ["[][0]\n    .x", 'Cannot access property "x" on undefined object "[0]"'],
        ["[][0].x = 1", 'Cannot access property "x" on undefined object "[0]"'],
        ["[][0]\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object "[0]"'],
        ["[u][0].x", 'Cannot access property "x" on undefined object "[0]"'],
        ["[u][0]\n    .x", 'Cannot access property "x" on undefined object "[0]"'],
        ["({}).x.y", 'Cannot access property "y" on undefined object ".x"'],
        ["(\n   {})\n    .x\n    .y", 'Cannot access property "y" on undefined object ".x"'],
        ['"s"[0].x.y', 'Cannot access property "y" on undefined object "\'s\'[0].x"'],
        ['"s"[0]\n    .x\n    .y', 'Cannot access property "y" on undefined object "\'s\'[0].x"'],
        ["1[0].x", 'Cannot access property "x" on undefined object "1[0]"'],
        ["1[0]\n    .x", 'Cannot access property "x" on undefined object "1[0]"'],
        ['1["x"].y', 'Cannot access property "y" on undefined object "1[\'x\']"'],
        ['1["x"]\n    .y', 'Cannot access property "y" on undefined object "1[\'x\']"'],
        ["a2[9].x", 'Cannot access property "x" on undefined object "a2[9]"'],
        ["a2[9]\n    .x", 'Cannot access property "x" on undefined object "a2[9]"'],
        ["a2[9].x = 1", 'Cannot access property "x" on undefined object "a2[9]"'],
        ["a2[9]\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object "a2[9]"'],
        ["a2[nk].x", 'Cannot access property "x" on undefined object "a2[nk]"'],
        ["a2[nk]\n    .x", 'Cannot access property "x" on undefined object "a2[nk]"'],
        ["a2[i0 + 9].x", 'Cannot access property "x" on undefined object "a2"'],
        ["a2[i0 + 9]\n    .x", 'Cannot access property "x" on undefined object "a2"'],
        ["a2[i0 + 9].x = 1", 'Cannot access property "x" on undefined object "a2"'],
        ["a2[i0 + 9]\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object "a2"'],
        ["a2[f0()].x", 'Cannot access property "x" on undefined object "a2"'],
        ["a2[f0(\n   )]\n    .x", 'Cannot access property "x" on undefined object "a2"'],
        ["a2[f0()].x = 1", 'Cannot access property "x" on undefined object "a2"'],
        ["a2[f0(\n   )]\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object "a2"'],
        ['a2["z"].x', 'Cannot access property "x" on undefined object "a2[\'z\']"'],
        ['a2["z"]\n    .x', 'Cannot access property "x" on undefined object "a2[\'z\']"'],
        ["a2['z'].x", 'Cannot access property "x" on undefined object "a2[\'z\']"'],
        ["a2['z']\n    .x", 'Cannot access property "x" on undefined object "a2[\'z\']"'],
        ["a2[`z`].x", 'Cannot access property "x" on undefined object "a2"'],
        ["a2[`z`]\n    .x", 'Cannot access property "x" on undefined object "a2"'],
        ["a2[this].x", 'Cannot access property "x" on undefined object "a2[this]"'],
        ["a2[this]\n    .x", 'Cannot access property "x" on undefined object "a2[this]"'],
        ["this.u0.x", 'Cannot access property "x" on undefined object "this.u0"'],
        ["this\n    .u0\n    .x", 'Cannot access property "x" on undefined object "this.u0"'],
        ["new C().nope.x", 'Cannot access property "x" on undefined object ".nope"'],
        ["new C(\n   )\n    .nope\n    .x", 'Cannot access property "x" on undefined object ".nope"'],
        ["new C().nope.x = 1", 'Cannot access property "x" on undefined object ".nope"'],
        ["new C(\n   )\n    .nope\n    .x\n    =\n    1", 'Cannot access property "x" on undefined object ".nope"'],
        ["new o.nope.x", 'Cannot access property "x" on undefined object "o.nope"'],
        ["new o\n    .nope\n    .x", 'Cannot access property "x" on undefined object "o.nope"'],
    ];
    for (const [source, message] of cases) expectMessage(source, message);
});

test("references that are longer than what gets looked at", () => {
    const long = "a".repeat(5000);
    expect(new Function(`new '${long}'.nope();`)).toThrow(TypeError);
    expect(new Function(`'${long}'.nope();`)).toThrow(TypeError);
    expect(new Function(`var ${long} = {}; ${long}.nope();`)).toThrow(TypeError);
    expect(new Function(`var ${long}; ${long}.nope = 1;`)).toThrow(TypeError);
    expect(new Function(`[${long}].nope.x = 1; var ${long};`)).toThrow(TypeError);
});

test("source that looks like something else", () => {
    expectMessage("o /* ) */ .nope();", "undefined is not a function (evaluated from 'o.nope')");
    expectMessage("o // )\n  .nope();", "undefined is not a function (evaluated from 'o.nope')");
    expectMessage("o[')'].nope();", `Cannot access property "nope" on undefined object "o[')']"`);
    expectMessage("o[']'].nope();", `Cannot access property "nope" on undefined object "o[']']"`);
});