From 4c98d138b9b2fbdd4041071048708742db21cc58 Mon Sep 17 00:00:00 2001 From: rwaldron Date: Fri, 16 Jul 2021 13:58:16 -0400 Subject: [PATCH] fix: Realm.prototype.evaluate semantics --- .../evaluate/coerces-arg-to-string.js | 25 ------------------- .../throws-when-argument-is-not-a-string.js | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 test/built-ins/Realm/prototype/evaluate/coerces-arg-to-string.js create mode 100644 test/built-ins/Realm/prototype/evaluate/throws-when-argument-is-not-a-string.js diff --git a/test/built-ins/Realm/prototype/evaluate/coerces-arg-to-string.js b/test/built-ins/Realm/prototype/evaluate/coerces-arg-to-string.js deleted file mode 100644 index 5cb8001873..0000000000 --- a/test/built-ins/Realm/prototype/evaluate/coerces-arg-to-string.js +++ /dev/null @@ -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); \ No newline at end of file diff --git a/test/built-ins/Realm/prototype/evaluate/throws-when-argument-is-not-a-string.js b/test/built-ins/Realm/prototype/evaluate/throws-when-argument-is-not-a-string.js new file mode 100644 index 0000000000..5186f3f19c --- /dev/null +++ b/test/built-ins/Realm/prototype/evaluate/throws-when-argument-is-not-a-string.js @@ -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)); \ No newline at end of file