fix: Realm.prototype.evaluate semantics

This commit is contained in:
rwaldron 2021-07-16 13:58:16 -04:00 committed by Rick Waldron
parent b2f34c0894
commit 4c98d138b9
2 changed files with 25 additions and 25 deletions

View File

@ -1,25 +0,0 @@
// 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.evaluate
description: >
Realm.prototype.evaluate coerces the argument to a string.
includes: [isConstructor.js]
features: [callable-boundary-realms]
---*/
assert.sameValue(
typeof Realm.prototype.evaluate,
'function',
'This test must fail if Realm.prototype.evaluate is not a function'
);
const r = new Realm();
assert.sameValue(r.evaluate(['1+1']), 2);
assert.sameValue(r.evaluate({ [Symbol.toPrimitive]() { return '1+1'; }}), 2);
assert.sameValue(r.evaluate(1), 1);
assert.sameValue(r.evaluate(null), null);
assert.sameValue(r.evaluate(undefined), undefined);
assert.sameValue(r.evaluate(true), true);
assert.sameValue(r.evaluate(false), false);

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.evaluate
description: >
Realm.prototype.evaluate throws when argument is not a string.
includes: [isConstructor.js]
features: [callable-boundary-realms]
---*/
assert.sameValue(
typeof Realm.prototype.evaluate,
'function',
'This test must fail if Realm.prototype.evaluate is not a function'
);
const r = new Realm();
assert.throws(TypeError, () => r.evaluate(['1+1']));
assert.throws(TypeError, () => r.evaluate({ [Symbol.toPrimitive]() { return '1+1'; }}));
assert.throws(TypeError, () => r.evaluate(1));
assert.throws(TypeError, () => r.evaluate(null));
assert.throws(TypeError, () => r.evaluate(undefined));
assert.throws(TypeError, () => r.evaluate(true));
assert.throws(TypeError, () => r.evaluate(false));