From 43b0c7650de40ddaf4ae2dda41a942044d816494 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Thu, 14 Nov 2019 17:13:32 +0100 Subject: [PATCH] Update tests for FinalizationGroup#register (#2424) FinalizationGroup#register should throw if called with target and holdings being the same value. This change happenend in: https://github.com/tc39/proposal-weakrefs/pull/165 --- .../register/holdings-same-as-target.js | 13 ++++--------- .../return-undefined-register-itself.js | 18 ++++++++++-------- ...egisterToken-same-as-holdings-and-target.js | 15 ++++++++------- .../target-not-callable-throws.js | 2 +- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/test/built-ins/FinalizationGroup/prototype/register/holdings-same-as-target.js b/test/built-ins/FinalizationGroup/prototype/register/holdings-same-as-target.js index d38d8884b9..7c6fa2b180 100644 --- a/test/built-ins/FinalizationGroup/prototype/register/holdings-same-as-target.js +++ b/test/built-ins/FinalizationGroup/prototype/register/holdings-same-as-target.js @@ -9,18 +9,13 @@ info: | 1. Let finalizationGroup be the this value. 2. If Type(finalizationGroup) is not Object, throw a TypeError exception. - 3. If Type(target) is not Object, throw a TypeError exception. - 4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. - 5. If Type(unregisterToken) is not Object, - a. If unregisterToken is not undefined, throw a TypeError exception. - b. Set unregisterToken to empty. - 6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }. - 7. Append cell to finalizationGroup.[[Cells]]. - 8. Return undefined. + 3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. + 4. If Type(target) is not Object, throw a TypeError exception. + 5. If SameValue(target, holdings), throw a TypeError exception. features: [FinalizationGroup] ---*/ var fg = new FinalizationGroup(function() {}); var target = {}; -assert.sameValue(fg.register(target, target), undefined); +assert.throws(TypeError, () => fg.register(target, target)); diff --git a/test/built-ins/FinalizationGroup/prototype/register/return-undefined-register-itself.js b/test/built-ins/FinalizationGroup/prototype/register/return-undefined-register-itself.js index a507f6eb17..aafdc05481 100644 --- a/test/built-ins/FinalizationGroup/prototype/register/return-undefined-register-itself.js +++ b/test/built-ins/FinalizationGroup/prototype/register/return-undefined-register-itself.js @@ -9,20 +9,22 @@ info: | 1. Let finalizationGroup be the this value. 2. If Type(finalizationGroup) is not Object, throw a TypeError exception. - 3. If Type(target) is not Object, throw a TypeError exception. - 4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. - 5. If Type(unregisterToken) is not Object, + 3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. + 4. If Type(target) is not Object, throw a TypeError exception. + 5. If SameValue(target, holdings), throw a TypeError exception. + 6. If Type(unregisterToken) is not Object, a. If unregisterToken is not undefined, throw a TypeError exception. b. Set unregisterToken to empty. - 6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }. - 7. Append cell to finalizationGroup.[[Cells]]. - 8. Return undefined. + 7. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }. + 8. Append cell to finalizationGroup.[[Cells]]. + 9. Return undefined. features: [FinalizationGroup] ---*/ var fn = function() {}; var fg = new FinalizationGroup(fn); +var holdings = {}; assert.sameValue(fg.register(fg), undefined, 'Register itself'); -assert.sameValue(fg.register(fg, fg), undefined, 'Register itself with holdings'); -assert.sameValue(fg.register(fg, fg, fg), undefined, 'Register itself with holdings and unregisterToken'); +assert.sameValue(fg.register(fg, holdings), undefined, 'Register itself with holdings'); +assert.sameValue(fg.register(fg, holdings, fg), undefined, 'Register itself with holdings and unregisterToken'); diff --git a/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-holdings-and-target.js b/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-holdings-and-target.js index f1dc302f4d..bd19feb025 100644 --- a/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-holdings-and-target.js +++ b/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-holdings-and-target.js @@ -9,18 +9,19 @@ info: | 1. Let finalizationGroup be the this value. 2. If Type(finalizationGroup) is not Object, throw a TypeError exception. - 3. If Type(target) is not Object, throw a TypeError exception. - 4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. - 5. If Type(unregisterToken) is not Object, + 3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. + 4. If Type(target) is not Object, throw a TypeError exception. + 5. If SameValue(target, holdings), throw a TypeError exception. + 6. If Type(unregisterToken) is not Object, a. If unregisterToken is not undefined, throw a TypeError exception. b. Set unregisterToken to empty. - 6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }. - 7. Append cell to finalizationGroup.[[Cells]]. - 8. Return undefined. + 7. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }. + 8. Append cell to finalizationGroup.[[Cells]]. + 9. Return undefined. features: [FinalizationGroup] ---*/ var fg = new FinalizationGroup(function() {}); var target = {}; -assert.sameValue(fg.register(target, target, target), undefined); +assert.throws(TypeError, () => fg.register(target, target, target)); diff --git a/test/built-ins/FinalizationGroup/target-not-callable-throws.js b/test/built-ins/FinalizationGroup/target-not-callable-throws.js index d71fbe5582..7b1ed4b6e0 100644 --- a/test/built-ins/FinalizationGroup/target-not-callable-throws.js +++ b/test/built-ins/FinalizationGroup/target-not-callable-throws.js @@ -11,7 +11,7 @@ info: | 1. If NewTarget is undefined, throw a TypeError exception. 2. If IsCallable(cleanupCallback) is false, throw a TypeError exception. ... -features: [FinalizationGroup] +features: [FinalizationGroup, WeakRef] ---*/ assert.sameValue(