Add a few tweaks

This commit is contained in:
Leo Balter 2021-07-20 13:00:30 -07:00 committed by Rick Waldron
parent b4ff2c76bc
commit d19534c3ce
10 changed files with 96 additions and 7 deletions

View File

@ -0,0 +1,15 @@
// Copyright (C) 2021 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-realm-constructor
description: >
The Realm constructor is extensible
info: |
17 ECMAScript Standard Built-in Objects
Unless specified otherwise, the [[Extensible]] internal slot of a built-in
object initially has the value true.
features: [callable-boundary-realms]
---*/
assert.sameValue(Object.isExtensible(Realm), true);

View File

@ -0,0 +1,43 @@
// Copyright (C) 2021 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-realm
description: >
The new instance is extensible
info: |
Realm ( )
...
2. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Realm.prototype%",
« [[Realm]], [[ExecutionContext]] »).
...
13. Return O.
OrdinaryCreateFromConstructor creates a new ordinary objects including the
internal slots [[Prototype]] and [[Extensible]]. The latter will have its
value set to true.
includes: [propertyHelper.js]
features: [callable-boundary-realms]
---*/
const realm = new Realm();
assert(Object.isExtensible(realm));
Object.defineProperty(realm, 'foo', {});
assert(realm.hasOwnProperty('foo'), 'confirms extensibility adding a new property');
Object.defineProperty(realm, 'foo', {
value: 'bar',
writable: true,
configurable: true,
enumerable: false,
});
verifyProperty(realm, 'foo', {
value: 'bar',
writable: true,
configurable: true,
enumerable: false,
});

View File

@ -4,6 +4,14 @@
esid: sec-realm-constructor
description: >
new Realm() returns a realm instance
info: |
Realm ( )
...
2. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Realm.prototype%",
« [[Realm]], [[ExecutionContext]] »).
...
13. Return O.
features: [callable-boundary-realms]
---*/
assert.sameValue(
@ -12,4 +20,11 @@ assert.sameValue(
'This test must fail if Realm is not a function'
);
assert(new Realm() instanceof Realm);
var realm = new Realm();
assert(realm instanceof Realm);
assert.sameValue(
Object.getPrototypeOf(realm),
Realm.prototype,
'[[Prototype]] is set to %Realm.prototype%'
);

View File

@ -24,3 +24,11 @@ assert.throws(TypeError, () => {
new Realm.prototype.evaluate("");
}, '`new Realm.prototype.evaluate("")` throws TypeError');
const r = new Realm();
r.evaluate('globalThis.x = 0');
assert.throws(TypeError, () => {
new r.evaluate("globalThis.x += 1;");
}, '`new r.evaluate("...")` throws TypeError');
assert.sameValue(r.evaluate('globalThis.x'), 0, 'No code evaluated in the new expression');

View File

@ -22,6 +22,7 @@ assert.sameValue(r.evaluate('undefined'), undefined);
assert.sameValue(r.evaluate('true'), true);
assert.sameValue(r.evaluate('false'), false);
assert.sameValue(r.evaluate('function fn() {}'), undefined, 'fn declaration has empty completion');
assert.sameValue(r.evaluate('-0'), -0);
assert.sameValue(r.evaluate('{}'), undefined, 'Block has empty completion');
assert.sameValue(r.evaluate('-0'), -0);
assert.sameValue(r.evaluate('"str"'), 'str');
assert(Number.isNaN(r.evaluate('NaN')));

View File

@ -22,3 +22,4 @@ assert.throws(TypeError, () => r.evaluate(null));
assert.throws(TypeError, () => r.evaluate(undefined));
assert.throws(TypeError, () => r.evaluate(true));
assert.throws(TypeError, () => r.evaluate(false));
assert.throws(TypeError, () => r.evaluate(new String('nope')));

View File

@ -17,5 +17,5 @@ const r = new Realm();
const bogus = {};
assert.throws(TypeError, function() {
r.evaluate.call(bogus);
r.evaluate.call(bogus, '');
}, 'throws a TypeError if this is not a Realm object');

View File

@ -16,9 +16,9 @@ assert.sameValue(
const r = new Realm();
r.evaluate(`
function fn() {
0, function fn() {
return 42;
}
};
`);
const wrapped = r.evaluate('fn');

View File

@ -21,5 +21,11 @@ assert.sameValue(
);
assert.throws(TypeError, () => {
new Realm.prototype.importValue("");
new Realm.prototype.importValue("", "name");
}, '`new Realm.prototype.importValue("")` throws TypeError');
const r = new Realm();
assert.throws(TypeError, () => {
new r.imporValue("./import-value_FIXTURE.js", "x");
}, '`new r.imporValue("...")` throws TypeError');

View File

@ -17,5 +17,5 @@ const r = new Realm();
const bogus = {};
assert.throws(TypeError, function() {
r.importValue.call(bogus);
r.importValue.call(bogus, "specifier", "name");
}, 'throws a TypeError if this is not a Realm object');