From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../eslint/eslint-plugin-mozilla/tests/globals.js | 161 +++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 tools/lint/eslint/eslint-plugin-mozilla/tests/globals.js (limited to 'tools/lint/eslint/eslint-plugin-mozilla/tests/globals.js') diff --git a/tools/lint/eslint/eslint-plugin-mozilla/tests/globals.js b/tools/lint/eslint/eslint-plugin-mozilla/tests/globals.js new file mode 100644 index 0000000000..1098cb8a34 --- /dev/null +++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/globals.js @@ -0,0 +1,161 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +var { getGlobalsForCode } = require("../lib/globals"); +var assert = require("assert"); + +/* global describe, it */ + +describe("globals", function () { + it("should reflect top-level this property assignment", function () { + const globals = getGlobalsForCode(` +this.foo = 10; +`); + assert.deepEqual(globals, [{ name: "foo", writable: true }]); + }); + + it("should reflect this property assignment inside block", function () { + const globals = getGlobalsForCode(` +{ + this.foo = 10; +} +`); + assert.deepEqual(globals, [{ name: "foo", writable: true }]); + }); + + it("should ignore this property assignment inside function declaration", function () { + const globals = getGlobalsForCode(` +function f() { + this.foo = 10; +} +`); + assert.deepEqual(globals, [{ name: "f", writable: true }]); + }); + + it("should ignore this property assignment inside function expression", function () { + const globals = getGlobalsForCode(` +(function f() { + this.foo = 10; +}); +`); + assert.deepEqual(globals, []); + }); + + it("should ignore this property assignment inside method", function () { + const globals = getGlobalsForCode(` +({ + method() { + this.foo = 10; + } +}); +`); + assert.deepEqual(globals, []); + }); + + it("should ignore this property assignment inside accessor", function () { + const globals = getGlobalsForCode(` +({ + get x() { + this.foo = 10; + }, + set x(v) { + this.bar = 10; + } +}); +`); + assert.deepEqual(globals, []); + }); + + it("should reflect this property assignment inside arrow function", function () { + const globals = getGlobalsForCode(` +() => { + this.foo = 10; +}; +`); + assert.deepEqual(globals, [{ name: "foo", writable: true }]); + }); + + it("should ignore this property assignment inside arrow function inside function expression", function () { + const globals = getGlobalsForCode(` +(function f() { + () => { + this.foo = 10; + }; +}); +`); + assert.deepEqual(globals, []); + }); + + it("should ignore this property assignment inside class static", function () { + const globals = getGlobalsForCode(` +class A { + static { + this.foo = 10; + (() => { + this.bar = 10; + })(); + } +} +`); + assert.deepEqual(globals, [{ name: "A", writable: true }]); + }); + + it("should ignore this property assignment inside class property", function () { + const globals = getGlobalsForCode(` +class A { + a = this.foo = 10; + b = (() => { + this.bar = 10; + })(); +} +`); + assert.deepEqual(globals, [{ name: "A", writable: true }]); + }); + + it("should ignore this property assignment inside class static property", function () { + const globals = getGlobalsForCode(` +class A { + static a = this.foo = 10; + static b = (() => { + this.bar = 10; + })(); +} +`); + assert.deepEqual(globals, [{ name: "A", writable: true }]); + }); + + it("should ignore this property assignment inside class private property", function () { + const globals = getGlobalsForCode(` +class A { + #a = this.foo = 10; + #b = (() => { + this.bar = 10; + })(); +} +`); + assert.deepEqual(globals, [{ name: "A", writable: true }]); + }); + + it("should ignore this property assignment inside class static private property", function () { + const globals = getGlobalsForCode(` +class A { + static #a = this.foo = 10; + static #b = (() => { + this.bar = 10; + })(); +} +`); + assert.deepEqual(globals, [{ name: "A", writable: true }]); + }); + + it("should reflect lazy getters", function () { + const globals = getGlobalsForCode(` +ChromeUtils.defineESModuleGetters(this, { + A: "B", +}); +`); + assert.deepEqual(globals, [{ name: "A", writable: true, explicit: true }]); + }); +}); -- cgit v1.2.3