tests: Realm.prototype.importValue semantics

This commit is contained in:
rwaldron 2021-07-16 13:58:47 -04:00 committed by Rick Waldron
parent 8b7c610232
commit 843b1baf7b
7 changed files with 138 additions and 2 deletions

View File

@ -0,0 +1,25 @@
// Copyright (C) 2021 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-realm.prototype.importvalue
description: >
Realm.prototype.importValue is not a constructor.
includes: [isConstructor.js]
features: [callable-boundary-realms]
---*/
assert.sameValue(
typeof Realm.prototype.importValue,
'function',
'This test must fail if Realm.prototype.importValue is not a function'
);
assert.sameValue(
isConstructor(Realm.prototype.importValue),
false,
'isConstructor(Realm.prototype.importValue) must return false'
);
assert.throws(TypeError, () => {
new Realm.prototype.importValue("");
}, '`let value = new Realm.prototype.importValue("")` throws TypeError');

View File

@ -0,0 +1,31 @@
// Copyright (C) 2021 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-realm.prototype.importvalue
description: >
Realm.prototype.importValue coerces exportName to string.
includes: [isConstructor.js]
features: [callable-boundary-realms]
---*/
assert.sameValue(
typeof Realm.prototype.importValue,
'function',
'This test must fail if Realm.prototype.importValue is not a function'
);
const r = new Realm();
let count = 0;
const exportName = {
toString() {
count += 1;
throw new Test262Error();
}
};
assert.throws(Test262Error, () => {
r.importValue('', exportName);
});
assert.sameValue(count, 1);

View File

@ -0,0 +1,24 @@
// Copyright (C) 2021 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-realm.prototype.importvalue
description: >
Realm.prototype.importValue can import a value.
flags: [async, module]
includes: [isConstructor.js]
features: [callable-boundary-realms]
---*/
assert.sameValue(
typeof Realm.prototype.importValue,
'function',
'This test must fail if Realm.prototype.importValue is not a function'
);
const r = new Realm();
r.importValue('./import-value_FIXTURE.js', 'x').then(x => {
assert.sameValue(x, 1);
}).then($DONE, $DONE);

View File

@ -0,0 +1,4 @@
// Copyright (C) 2021 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
export var x = 1;

View File

@ -9,8 +9,7 @@ info: |
has the Function prototype object, which is the initial value of the expression has the Function prototype object, which is the initial value of the expression
Function.prototype, as the value of its [[Prototype]] internal slot. Function.prototype, as the value of its [[Prototype]] internal slot.
includes: [hidden-constructors.js]
features: [callable-boundary-realms] features: [callable-boundary-realms]
---*/ ---*/
assert.sameValue(Object.getPrototypeOf(Realm.prototype.importValue), AsyncFunction.prototype); assert.sameValue(Object.getPrototypeOf(Realm.prototype.importValue), Function.prototype);

View File

@ -0,0 +1,31 @@
// Copyright (C) 2021 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-realm.prototype.importvalue
description: >
Realm.prototype.importValue coerces specifier to string.
includes: [isConstructor.js]
features: [callable-boundary-realms]
---*/
assert.sameValue(
typeof Realm.prototype.importValue,
'function',
'This test must fail if Realm.prototype.importValue is not a function'
);
const r = new Realm();
let count = 0;
const specifier = {
toString() {
count += 1;
throw new Test262Error();
}
};
assert.throws(Test262Error, () => {
r.importValue(specifier);
});
assert.sameValue(count, 1);

View File

@ -0,0 +1,22 @@
// Copyright (C) 2021 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-realm.prototype.importvalue
description: >
Realm.prototype.importValue validates realm object.
includes: [isConstructor.js]
features: [callable-boundary-realms]
---*/
assert.sameValue(
typeof Realm.prototype.importValue,
'function',
'This test must fail if Realm.prototype.importValue is not a function'
);
const r = new Realm();
const bogus = {};
assert.throws(TypeError, function() {
r.importValue.call(bogus);
}, 'throws a TypeError if this is not a Realm object');