Replace SpiderMonkey-specific parseModule in expressions/optional-chain-first-expression.js

This commit is contained in:
André Bargull 2025-04-30 14:16:43 +02:00 committed by Philip Chimento
parent 0ee9b57cba
commit d90061929a
3 changed files with 49 additions and 24 deletions

View File

@ -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());
});

View File

@ -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.

View File

@ -47,12 +47,8 @@ const expressions = [
"a?.``", "a?.``",
]; ];
function tryParse(s, f = Function) { function tryRun(s) {
try { f(s); } catch {} try { Function(s)(); } catch {}
}
function tryRun(s, f = Function) {
try { f(s)(); } catch {}
} }
for (let expr of expressions) { 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})?.());`));
tryRun(inClassConstructor(`void ((${expr})?.p());`)); 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);
}
}