From 2000e858ff72a57688a4c347f9b15db160928822 Mon Sep 17 00:00:00 2001 From: legendecas Date: Wed, 8 Dec 2021 01:04:32 +0800 Subject: [PATCH] Add coverage on ShadowRealm.prototype.importValue onRejected --- .../import-value_FIXTURE_syntax_error.js | 4 +++ .../import-value_FIXTURE_throws.js | 4 +++ .../throws-typeerror-import-syntax-error.js | 34 +++++++++++++++++++ .../throws-typeerror-import-throws.js | 34 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 test/built-ins/ShadowRealm/prototype/importValue/import-value_FIXTURE_syntax_error.js create mode 100644 test/built-ins/ShadowRealm/prototype/importValue/import-value_FIXTURE_throws.js create mode 100644 test/built-ins/ShadowRealm/prototype/importValue/throws-typeerror-import-syntax-error.js create mode 100644 test/built-ins/ShadowRealm/prototype/importValue/throws-typeerror-import-throws.js diff --git a/test/built-ins/ShadowRealm/prototype/importValue/import-value_FIXTURE_syntax_error.js b/test/built-ins/ShadowRealm/prototype/importValue/import-value_FIXTURE_syntax_error.js new file mode 100644 index 0000000000..9367387ae0 --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/importValue/import-value_FIXTURE_syntax_error.js @@ -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. diff --git a/test/built-ins/ShadowRealm/prototype/importValue/import-value_FIXTURE_throws.js b/test/built-ins/ShadowRealm/prototype/importValue/import-value_FIXTURE_throws.js new file mode 100644 index 0000000000..5a05ef70b0 --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/importValue/import-value_FIXTURE_throws.js @@ -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'); diff --git a/test/built-ins/ShadowRealm/prototype/importValue/throws-typeerror-import-syntax-error.js b/test/built-ins/ShadowRealm/prototype/importValue/throws-typeerror-import-syntax-error.js new file mode 100644 index 0000000000..b2b2e49ab4 --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/importValue/throws-typeerror-import-syntax-error.js @@ -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); diff --git a/test/built-ins/ShadowRealm/prototype/importValue/throws-typeerror-import-throws.js b/test/built-ins/ShadowRealm/prototype/importValue/throws-typeerror-import-throws.js new file mode 100644 index 0000000000..31f8f27b5c --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/importValue/throws-typeerror-import-throws.js @@ -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);