Skip to content

Commit

Permalink
Update import attributes assert tests to current semantics (tc39#3919)
Browse files Browse the repository at this point in the history
Co-authored-by: Jordan Harband <ljharb@gmail.com>
  • Loading branch information
nicolo-ribaudo and ljharb authored Sep 13, 2023
1 parent e98bfb3 commit 1bb53ae
Show file tree
Hide file tree
Showing 19 changed files with 261 additions and 171 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Reports abrupt completions produced by assertion enumeration
description: Reports abrupt completions produced by attributes enumeration
esid: sec-import-call-runtime-semantics-evaluation
info: |
2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Follows the semantics of the EnumerableOwnPropertyNames abstract operation
during attributes enumeration
esid: sec-import-call-runtime-semantics-evaluation
info: |
2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] )
[...]
6. Let promiseCapability be ! NewPromiseCapability(%Promise%).
7. Let specifierString be ToString(specifier).
8. IfAbruptRejectPromise(specifierString, promiseCapability).
9. Let assertions be a new empty List.
10. If options is not undefined, then
a. If Type(options) is not Object,
[...]
b. Let assertionsObj be Get(options, "assert").
c. IfAbruptRejectPromise(assertionsObj, promiseCapability).
d. If assertionsObj is not undefined,
i. If Type(assertionsObj) is not Object,
[...]
ii. Let keys be EnumerableOwnPropertyNames(assertionsObj, key).
[...]
features: [dynamic-import, import-assertions, json-modules, Symbol, Proxy]
includes: [compareArray.js]
flags: [async]
---*/

var symbol = Symbol('');
var target = {
type: "json"
};
var descriptors = {
type: {configurable: true, enumerable: true}
};
var log = [];

var options = {
assert: new Proxy({}, {
ownKeys: function() {
return ["type"];
},
get(_, name) {
log.push(name);
return "json";
},
getOwnPropertyDescriptor(target, name) {
return {configurable: true, enumerable: true, value: "json"};
},
})
};

import('./2nd-param_FIXTURE.json', options)
.then(function(module) {
assert.sameValue(module.default, 262);
})
.then($DONE, $DONE);

assert.compareArray(log, ['type']);
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*---
description: >
Follows the semantics of the EnumerableOwnPropertyNames abstract operation
during assertion enumeration
during attributes enumeration
esid: sec-import-call-runtime-semantics-evaluation
info: |
2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] )
Expand All @@ -28,28 +28,22 @@ flags: [async]

var symbol = Symbol('');
var target = {
enumerable1: '',
enumerable2: '',
[symbol]: '',
unreported: '',
nonEnumerable: ''
};
var descriptors = {
enumerable1: {configurable: true, enumerable: true},
enumerable2: {configurable: true, enumerable: true},
[symbol]: {configurable: true, enumerable: true},
nonEnumerable: {configurable: true, enumerable: false}
};
var log = [];

var options = {
assert: new Proxy({}, {
ownKeys: function() {
return ['enumerable1', symbol, 'nonEnumerable', 'absent', 'enumerable2'];
return [symbol, 'nonEnumerable', 'absent'];
},
get(_, name) {
log.push(name);
return target[name];
get() {
throw new Error("Should not be called");
},
getOwnPropertyDescriptor(target, name) {
return descriptors[name];
Expand All @@ -62,7 +56,3 @@ import('./2nd-param_FIXTURE.js', options)
assert.sameValue(module.default, 262);
})
.then($DONE, $DONE);

assert.sameValue(log.length, 2);
assert.sameValue(log[0], 'enumerable1');
assert.sameValue(log[1], 'enumerable2');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
262
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: AssertClause may not have duplicate keys (export declaration)
description: WithClause may not have duplicate keys (export declaration)
esid: sec-modules
info: |
AssertClause:assert{AssertEntries,opt}
WithClause: AttributesKeyword { WithEntries,opt }
- It is a Syntax Error if AssertClauseToAssertions of AssertClause has two
- It is a Syntax Error if WithClauseToAttributes of WithClause has two
entries a and b such that a.[[Key]] is b.[[Key]].
features: [import-assertions]
flags: [module]
Expand All @@ -18,7 +18,6 @@ negative:
$DONOTEVALUATE();

export * from './import-assertion-3_FIXTURE.js' assert {
test262_a: '',
test262_b: '',
'test262_\u0061': ''
type: 'json',
'typ\u0065': ''
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
AssertClause may not have duplicate keys (import declaration without binding)
WithClause may not have duplicate keys (import declaration without binding)
esid: sec-modules
info: |
AssertClause:assert{AssertEntries,opt}
WithClause: AttributesKeyword { WithEntries,opt }
- It is a Syntax Error if AssertClauseToAssertions of AssertClause has two
- It is a Syntax Error if WithClauseToAttributes of WithClause has two
entries a and b such that a.[[Key]] is b.[[Key]].
features: [import-assertions]
flags: [module]
Expand All @@ -19,7 +19,6 @@ negative:
$DONOTEVALUATE();

import './import-assertion-2_FIXTURE.js' assert {
test262_a: '',
test262_b: '',
'test262_\u0061': ''
type: 'json',
'typ\u0065': ''
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
AssertClause may not have duplicate keys (import declaration with binding)
WithClause may not have duplicate keys (import declaration with binding)
esid: sec-modules
info: |
AssertClause:assert{AssertEntries,opt}
WithClause: AttributesKeyword { WithEntries,opt }
- It is a Syntax Error if AssertClauseToAssertions of AssertClause has two
- It is a Syntax Error if WithClauseToAttributes of WithClause has two
entries a and b such that a.[[Key]] is b.[[Key]].
features: [import-assertions]
flags: [module]
Expand All @@ -19,7 +19,6 @@ negative:
$DONOTEVALUATE();

import x from './import-assertion-1_FIXTURE.js' assert {
test262_a: '',
test262_b: '',
'test262_\u0061': ''
type: 'json',
'typ\u0065': ''
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

// When imported, this file will ensure that a linking error happens by
// importing a non-existent binding.
// It can be used to assert that there is a linking error, which means
// that there are no parsing errors.

import { nonExistent } from "./import-assertion-ensure-resolution-error_FIXTURE.js";
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
AssertClause in ImportDeclaration may not be preceded by a line terminator
`assert` AttributesKeyword in WithClause in ImportDeclaration may not
be preceded by a line terminator
esid: sec-modules
info: |
ImportDeclaration:
import ModuleSpecifier[no LineTerminator here] AssertClause;
import ModuleSpecifier[no LineTerminator here] WithClause;
AssertClause:
assert {}
assert {AssertEntries ,opt}
WithClause:
AttributesKeyword {}
AttributesKeyword { WithEntries ,opt }
AssertEntries:
AssertionKey : StringLiteral
AssertionKey : StringLiteral , AssertEntries
AssertionKey:
IdentifierName
StringLiteral
AttributesKeyword:
with
[no LineTerminator here] assert
The restriction LineTerminator could be verified more simply with a negative
syntax test. This test is designed to parse successfully in order to verify
Expand All @@ -37,34 +34,14 @@ Object.defineProperty(globalThis, 'assert', {
}
});

import x from './import-assertion-1_FIXTURE.js'
import * as x from './import-assertion-1_FIXTURE.js'
assert
{test262:''};
{ type: 'json' };

if (x !== 262.1) {
if (x.default !== 262.1) {
throw 'module value incorrectly imported - first declaration';
}

if (callCount !== 1) {
throw 'IdentifierReference not recognized - first declaration';
}

import './import-assertion-2_FIXTURE.js'
assert
{test262:''};

if (globalThis.test262 !== 262.2) {
throw 'module value incorrectly imported - second declaration';
}

if (callCount !== 2) {
throw 'IdentifierReference not recognized - second declaration';
}

export * from './import-assertion-3_FIXTURE.js'
assert
{test262:''};

if (callCount !== 3) {
throw 'IdentifierReference not recognized - third declaration';
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
globalThis.test262 = 262.2;
export default 262.2;
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: AssertClause in ImportDeclaration may be empty
description: WithClause in ImportDeclaration may be empty
esid: sec-modules
info: |
ImportDeclaration:
import ModuleSpecifier[no LineTerminator here] AssertClause;
import ModuleSpecifier[no LineTerminator here] WithClause;
AssertClause:
WithClause:
assert {}
assert {AssertEntries ,opt}
assert {WithEntries ,opt}
AssertEntries:
AssertionKey : StringLiteral
AssertionKey : StringLiteral , AssertEntries
WithEntries:
AttributeKey : StringLiteral
AttributeKey : StringLiteral , WithEntries
AssertionKey:
AttributeKey:
IdentifierName
StringLiteral
features: [import-assertions, globalThis]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,36 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
AssertClause in ImportDeclaration may use any valid IdentifierName as a key
WithClause in ImportDeclaration may use any valid IdentifierName as a key
esid: sec-modules
info: |
ImportDeclaration:
import ModuleSpecifier[no LineTerminator here] AssertClause;
import ModuleSpecifier[no LineTerminator here] WithClause;
AssertClause:
WithClause:
assert {}
assert {AssertEntries ,opt}
assert {WithEntries ,opt}
AssertEntries:
AssertionKey : StringLiteral
AssertionKey : StringLiteral , AssertEntries
WithEntries:
AttributeKey : StringLiteral
AttributeKey : StringLiteral , WithEntries
AssertionKey:
AttributeKey:
IdentifierName
StringLiteral
negative:
phase: resolution
type: SyntaxError
features: [import-assertions]
flags: [module]
---*/

$DONOTEVALUATE();

import "./ensure-linking-error_FIXTURE.js";

import x from './import-assertion-1_FIXTURE.js' assert {if:''};
import './import-assertion-2_FIXTURE.js' assert {if:''};
export * from './import-assertion-3_FIXTURE.js' assert {if:''};

assert.sameValue(x, 262.1);
assert.sameValue(globalThis.test262, 262.2);
Loading

0 comments on commit 1bb53ae

Please sign in to comment.