Add coverage on ShadowRealm.prototype.importValue onRejected

This commit is contained in:
legendecas 2021-12-08 01:04:32 +08:00 committed by Rick Waldron
parent 04cd6da021
commit 2000e858ff
4 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,4 @@
// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
This is an invalid JavaScript Module file.

View File

@ -0,0 +1,4 @@
// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
throw new Error('foobar');

View File

@ -0,0 +1,34 @@
// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-realmimportvalue
description: >
ShadowRealm.prototype.importValue rejects with TypeError when the imported script unable to be parsed.
info: |
RealmImportValue ( specifierString, exportNameString, callerRealm, evalRealm, evalContext )
...
17. Return ! PerformPromiseThen(innerCapability.[[Promise]], onFulfilled, callerRealm.[[Intrinsics]].[[%ThrowTypeError%]], promiseCapability).
flags: [async, module]
features: [ShadowRealm]
---*/
assert.sameValue(
typeof ShadowRealm.prototype.importValue,
'function',
'This test must fail if ShadowRealm.prototype.importValue is not a function'
);
const r = new ShadowRealm();
r.importValue('./import-value_FIXTURE_syntax_error.js', 'y')
.then(
() => {
throw "(unreachable)";
},
err => {
assert.sameValue(Object.getPrototypeOf(err), TypeError.prototype, 'should be rejected with TypeError');
}
)
.then($DONE, $DONE);

View File

@ -0,0 +1,34 @@
// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-realmimportvalue
description: >
ShadowRealm.prototype.importValue rejects with TypeError when the imported script throws.
info: |
RealmImportValue ( specifierString, exportNameString, callerRealm, evalRealm, evalContext )
...
17. Return ! PerformPromiseThen(innerCapability.[[Promise]], onFulfilled, callerRealm.[[Intrinsics]].[[%ThrowTypeError%]], promiseCapability).
flags: [async, module]
features: [ShadowRealm]
---*/
assert.sameValue(
typeof ShadowRealm.prototype.importValue,
'function',
'This test must fail if ShadowRealm.prototype.importValue is not a function'
);
const r = new ShadowRealm();
r.importValue('./import-value_FIXTURE_throws.js', 'y')
.then(
() => {
throw "(unreachable)";
},
err => {
assert.sameValue(Object.getPrototypeOf(err), TypeError.prototype, 'should be rejected with TypeError');
}
)
.then($DONE, $DONE);