Skip to content

Commit 18834b2

Browse files
jugglinmikerwaldron
authored andcommitted
Add tests for import assertions
1 parent 219ad6f commit 18834b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1145
-18
lines changed

features.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,7 @@ class-fields-private-in
307307
# Error cause
308308
# https://github.com/tc39/proposal-error-cause
309309
error-cause
310+
311+
# Import Assertions
312+
# https://github.com/tc39/proposal-import-assertions/
313+
import-assertions

src/dynamic-import/not-extensible-args.case

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ desc: ImportCall is not extensible - no arguments list
55
template: syntax/invalid
66
info: |
77
ImportCall :
8-
import( AssignmentExpression[+In, ?Yield] )
8+
import( AssignmentExpression[+In, ?Yield, ?Await] ,opt )
9+
import( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt )
910

1011
Forbidden Extensions
1112

1213
- ImportCall must not be extended.
1314
---*/
1415

1516
//- import
16-
import('', '')
17+
import('./empty_FIXTURE.js', {}, '')

src/dynamic-import/not-extensible-no-trailing-comma.case

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (C) 2018 Leo Balter. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
desc: ImportCall trailing comma following first parameter
5+
template: syntax/valid
6+
info: |
7+
ImportCall :
8+
import( AssignmentExpression[+In, ?Yield, ?Await] ,opt )
9+
import( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt )
10+
features: [import-assertions]
11+
---*/
12+
13+
//- import
14+
import('./empty_FIXTURE.js',)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (C) 2021 V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
desc: ImportCall trailing comma following second parameter
5+
template: syntax/valid
6+
info: |
7+
ImportCall :
8+
import( AssignmentExpression[+In, ?Yield, ?Await] ,opt )
9+
import( AssignmentExpression[+In, ?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ,opt )
10+
features: [import-assertions]
11+
---*/
12+
13+
//- import
14+
import('./empty_FIXTURE.js', {},)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (C) 2021 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
description: Reports abrupt completions produced by assertion enumeration
5+
esid: sec-import-call-runtime-semantics-evaluation
6+
info: |
7+
2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] )
8+
[...]
9+
6. Let promiseCapability be ! NewPromiseCapability(%Promise%).
10+
7. Let specifierString be ToString(specifier).
11+
8. IfAbruptRejectPromise(specifierString, promiseCapability).
12+
9. Let assertions be a new empty List.
13+
10. If options is not undefined, then
14+
a. If Type(options) is not Object,
15+
[...]
16+
b. Let assertionsObj be Get(options, "assert").
17+
c. IfAbruptRejectPromise(assertionsObj, promiseCapability).
18+
d. If assertionsObj is not undefined,
19+
i. If Type(assertionsObj) is not Object,
20+
[...]
21+
ii. Let keys be EnumerableOwnPropertyNames(assertionsObj, key).
22+
iii. IfAbruptRejectPromise(keys, promiseCapability).
23+
[...]
24+
features: [dynamic-import, import-assertions, Proxy]
25+
flags: [async]
26+
---*/
27+
28+
var thrown = new Test262Error();
29+
var options = {
30+
assert: new Proxy({}, {
31+
ownKeys: function() {
32+
throw thrown;
33+
},
34+
})
35+
};
36+
37+
import('./2nd-param_FIXTURE.js', options)
38+
.then(function() {
39+
throw new Test262Error('Expected promise to be rejected, but promise was fulfilled.');
40+
}, function(error) {
41+
assert.sameValue(error, thrown);
42+
})
43+
.then($DONE, $DONE);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (C) 2021 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
description: >
5+
Follows the semantics of the EnumerableOwnPropertyNames abstract operation
6+
during assertion enumeration
7+
esid: sec-import-call-runtime-semantics-evaluation
8+
info: |
9+
2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] )
10+
[...]
11+
6. Let promiseCapability be ! NewPromiseCapability(%Promise%).
12+
7. Let specifierString be ToString(specifier).
13+
8. IfAbruptRejectPromise(specifierString, promiseCapability).
14+
9. Let assertions be a new empty List.
15+
10. If options is not undefined, then
16+
a. If Type(options) is not Object,
17+
[...]
18+
b. Let assertionsObj be Get(options, "assert").
19+
c. IfAbruptRejectPromise(assertionsObj, promiseCapability).
20+
d. If assertionsObj is not undefined,
21+
i. If Type(assertionsObj) is not Object,
22+
[...]
23+
ii. Let keys be EnumerableOwnPropertyNames(assertionsObj, key).
24+
[...]
25+
features: [dynamic-import, import-assertions, Symbol, Proxy]
26+
flags: [async]
27+
---*/
28+
29+
var symbol = Symbol('');
30+
var target = {
31+
enumerable1: '',
32+
enumerable2: '',
33+
[symbol]: '',
34+
unreported: '',
35+
nonEnumerable: ''
36+
};
37+
var descriptors = {
38+
enumerable1: {configurable: true, enumerable: true},
39+
enumerable2: {configurable: true, enumerable: true},
40+
[symbol]: {configurable: true, enumerable: true},
41+
nonEnumerable: {configurable: true, enumerable: false}
42+
};
43+
var log = [];
44+
45+
var options = {
46+
assert: new Proxy({}, {
47+
ownKeys: function() {
48+
return ['enumerable1', symbol, 'nonEnumerable', 'absent', 'enumerable2'];
49+
},
50+
get(_, name) {
51+
log.push(name);
52+
return target[name];
53+
},
54+
getOwnPropertyDescriptor(target, name) {
55+
return descriptors[name];
56+
}
57+
})
58+
};
59+
60+
import('./2nd-param_FIXTURE.js', options)
61+
.then(function(module) {
62+
assert.sameValue(module.default, 262);
63+
})
64+
.then($DONE, $DONE);
65+
66+
assert.sameValue(log.length, 2);
67+
assert.sameValue(log[0], 'enumerable1');
68+
assert.sameValue(log[1], 'enumerable2');
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (C) 2021 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
description: >
5+
Rejects promise when the `assert` property of the second argument is neither
6+
undefined nor an object
7+
esid: sec-import-call-runtime-semantics-evaluation
8+
info: |
9+
2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] )
10+
[...]
11+
6. Let promiseCapability be ! NewPromiseCapability(%Promise%).
12+
7. Let specifierString be ToString(specifier).
13+
8. IfAbruptRejectPromise(specifierString, promiseCapability).
14+
9. Let assertions be a new empty List.
15+
10. If options is not undefined, then
16+
a. If Type(options) is not Object,
17+
[...]
18+
b. Let assertionsObj be Get(options, "assert").
19+
c. IfAbruptRejectPromise(assertionsObj, promiseCapability).
20+
d. If assertionsObj is not undefined,
21+
i. If Type(assertionsObj) is not Object,
22+
1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a
23+
newly created TypeError object »).
24+
2. Return promiseCapability.[[Promise]].
25+
[...]
26+
features: [dynamic-import, import-assertions, Symbol, BigInt]
27+
flags: [async]
28+
---*/
29+
30+
function test(promise, valueType) {
31+
return promise.then(function() {
32+
throw new Test262Error('Promise for ' + valueType + ' was not rejected.');
33+
}, function(error) {
34+
assert.sameValue(error.constructor, TypeError, valueType);
35+
});
36+
}
37+
38+
Promise.all([
39+
test(import('./2nd-param_FIXTURE.js', {assert:null}), 'null'),
40+
test(import('./2nd-param_FIXTURE.js', {assert:false}), 'boolean'),
41+
test(import('./2nd-param_FIXTURE.js', {assert:23}), 'number'),
42+
test(import('./2nd-param_FIXTURE.js', {assert:''}), 'string'),
43+
test(import('./2nd-param_FIXTURE.js', {assert:Symbol('')}), 'symbol'),
44+
test(import('./2nd-param_FIXTURE.js', {assert:23n}), 'bigint')
45+
])
46+
.then(function() {})
47+
.then($DONE, $DONE);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (C) 2021 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
description: Accepts undefined for the `assert` property of the second argument
5+
esid: sec-import-call-runtime-semantics-evaluation
6+
info: |
7+
2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] )
8+
[...]
9+
6. Let promiseCapability be ! NewPromiseCapability(%Promise%).
10+
7. Let specifierString be ToString(specifier).
11+
8. IfAbruptRejectPromise(specifierString, promiseCapability).
12+
9. Let assertions be a new empty List.
13+
10. If options is not undefined, then
14+
a. If Type(options) is not Object,
15+
[...]
16+
b. Let assertionsObj be Get(options, "assert").
17+
c. IfAbruptRejectPromise(assertionsObj, promiseCapability).
18+
d. If assertionsObj is not undefined,
19+
i. If Type(assertionsObj) is not Object,
20+
1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a
21+
newly created TypeError object »).
22+
2. Return promiseCapability.[[Promise]].
23+
[...]
24+
features: [dynamic-import, import-assertions, Symbol, BigInt]
25+
flags: [async]
26+
---*/
27+
28+
Promise.all([
29+
import('./2nd-param_FIXTURE.js', {}),
30+
import('./2nd-param_FIXTURE.js', {assert:undefined}),
31+
])
32+
.then(function(values) {
33+
assert.sameValue(values[0].default, 262);
34+
assert.sameValue(values[1].default, 262);
35+
})
36+
.then($DONE, $DONE);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (C) 2021 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
description: >
5+
Rejects promise when retrieving a value of the `assert` object produces an
6+
abrupt completion
7+
esid: sec-import-call-runtime-semantics-evaluation
8+
info: |
9+
2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] )
10+
[...]
11+
10. If options is not undefined, then
12+
[...]
13+
d. If assertionsObj is not undefined,
14+
[...]
15+
ii. Let keys be EnumerableOwnPropertyNames(assertionsObj, key).
16+
iii. IfAbruptRejectPromise(keys, promiseCapability).
17+
iv. Let supportedAssertions be ! HostGetSupportedImportAssertions().
18+
v. For each String key of keys,
19+
1. Let value be Get(assertionsObj, key).
20+
2. IfAbruptRejectPromise(value, promiseCapability).
21+
[...]
22+
features: [dynamic-import, import-assertions]
23+
flags: [async]
24+
---*/
25+
26+
var thrown = new Test262Error();
27+
28+
import('./2nd-param_FIXTURE.js', {assert:{get ''() { throw thrown; }}})
29+
.then(function() {
30+
throw new Test262Error('Expected promise to be rejected, but it was fulfilled');
31+
}, function(error) {
32+
assert.sameValue(error, thrown);
33+
})
34+
.then($DONE, $DONE);

0 commit comments

Comments
 (0)