From d90061929a571778f5391cc3adbca49f68b4a72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Wed, 30 Apr 2025 14:16:43 +0200 Subject: [PATCH] Replace SpiderMonkey-specific parseModule in expressions/optional-chain-first-expression.js --- .../optional-chain-first-expression-module.js | 43 +++++++++++++++++++ ...l-chain-first-expression-module_FIXTURE.js | 4 ++ .../optional-chain-first-expression.js | 26 +---------- 3 files changed, 49 insertions(+), 24 deletions(-) create mode 100644 test/staging/sm/expressions/optional-chain-first-expression-module.js create mode 100644 test/staging/sm/expressions/optional-chain-first-expression-module_FIXTURE.js diff --git a/test/staging/sm/expressions/optional-chain-first-expression-module.js b/test/staging/sm/expressions/optional-chain-first-expression-module.js new file mode 100644 index 0000000000..fb2183476d --- /dev/null +++ b/test/staging/sm/expressions/optional-chain-first-expression-module.js @@ -0,0 +1,43 @@ +// Copyright (C) 2024 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + pending +esid: pending +flags: + - module +---*/ +// Verify bytecode emitter accepts all valid optional chain first expressions. + +// Evaluate `import.meta` in an expression context. +assert.throws(TypeError, function() { + void (import.meta?.()); +}); +assert.throws(TypeError, function() { + void (import.meta?.p()); +}); + +// Also try `import.meta` parenthesized. +assert.throws(TypeError, function() { + void ((import.meta)?.()); +}); +assert.throws(TypeError, function() { + void ((import.meta)?.p()); +}); + +// Evaluate `import()` in an expression context. +assert.throws(TypeError, function() { + void (import("./optional-chain-first-expression-module_FIXTURE.js")?.()); +}); +assert.throws(TypeError, function() { + void (import("./optional-chain-first-expression-module_FIXTURE.js")?.p()); +}); + +// Also try `import()` parenthesized. +assert.throws(TypeError, function() { + void ((import("./optional-chain-first-expression-module_FIXTURE.js"))?.()); +}); +assert.throws(TypeError, function() { + void ((import("./optional-chain-first-expression-module_FIXTURE.js"))?.p()); +}); diff --git a/test/staging/sm/expressions/optional-chain-first-expression-module_FIXTURE.js b/test/staging/sm/expressions/optional-chain-first-expression-module_FIXTURE.js new file mode 100644 index 0000000000..4af0a1e03e --- /dev/null +++ b/test/staging/sm/expressions/optional-chain-first-expression-module_FIXTURE.js @@ -0,0 +1,4 @@ +// Copyright (C) 2024 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Intentionally left empty. diff --git a/test/staging/sm/expressions/optional-chain-first-expression.js b/test/staging/sm/expressions/optional-chain-first-expression.js index 412cd99dc4..ad897c2e49 100644 --- a/test/staging/sm/expressions/optional-chain-first-expression.js +++ b/test/staging/sm/expressions/optional-chain-first-expression.js @@ -47,12 +47,8 @@ const expressions = [ "a?.``", ]; -function tryParse(s, f = Function) { - try { f(s); } catch {} -} - -function tryRun(s, f = Function) { - try { f(s)(); } catch {} +function tryRun(s) { + try { Function(s)(); } catch {} } for (let expr of expressions) { @@ -78,21 +74,3 @@ for (let expr of ["super[a]", "super.a", "super()"]) { tryRun(inClassConstructor(`void ((${expr})?.());`)); tryRun(inClassConstructor(`void ((${expr})?.p());`)); } - -if (typeof parseModule === "function") { - const expressions = [ - "import.meta", - "import('')", - ]; - - for (let expr of expressions) { - // Evaluate in an expression context. - tryParse(`void (${expr}?.());`, parseModule); - tryParse(`void (${expr}?.p());`, parseModule); - - // Also try parenthesized. - tryParse(`void ((${expr})?.());`, parseModule); - tryParse(`void ((${expr})?.p());`, parseModule); - } -} -