From d101ab9bc4af308ab42a5e9b7c659898b0c4d0e7 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 23 Sep 2022 14:40:58 -0700 Subject: [PATCH] Adapt descriptions of existing tests using Objects as weak values There are many existing tests for WeakMap, WeakSet, WeakRef, and FinalizationRegistry using Objects as weak values. For symbols-as-weakmap- keys, we'll want to write tests that parallel these for Symbol keys. Change the descriptions and filenames of these tests to describe their new scope of only Object weak values. Update the front matter of these tests while we're at it, to reflect the changes to the spec text that the symbols-as-weakmap-keys brings in. (In some cases, remove irrelevant bits of the front matter.) See: #2850 --- ...nce-to-call-cleanupCallback-for-object.js} | 33 +++++----- .../register/heldValue-same-as-target.js | 19 ++++++ .../register/holdings-same-as-target.js | 21 ------ ...js => return-undefined-register-object.js} | 29 +++++---- .../unregister/unregister-cleaned-up-cell.js | 65 ------------------- .../unregister-cleaned-up-object-cell.js | 63 ++++++++++++++++++ ...register.js => unregister-object-token.js} | 24 ++++--- ...erable.js => iterable-with-object-keys.js} | 18 +++-- .../delete/delete-entry-initial-iterable.js | 32 --------- ...-entry-with-object-key-initial-iterable.js | 28 ++++++++ .../delete/delete-entry-with-object-key.js | 28 ++++++++ .../WeakMap/prototype/delete/delete-entry.js | 32 --------- ...urns-false-when-object-key-not-present.js} | 9 +-- ...s => returns-undefined-with-object-key.js} | 20 +++--- ...ue.js => returns-value-with-object-key.js} | 18 ++--- ...urns-false-when-object-key-not-present.js} | 8 +-- ...> returns-true-when-object-key-present.js} | 14 ++-- ...adds-element.js => adds-object-element.js} | 11 ++-- ...turn-target.js => return-object-target.js} | 14 ++-- ...ect-from-constructor-with-object-target.js | 35 ++++++++++ .../returns-new-object-from-constructor.js | 49 -------------- ...able.js => iterable-with-object-values.js} | 12 ++-- ...adds-element.js => adds-object-element.js} | 9 +-- ...delete-entry.js => delete-object-entry.js} | 20 +++--- ...ns-false-when-object-value-not-present.js} | 8 +-- ...returns-true-when-object-value-present.js} | 11 ++-- 26 files changed, 288 insertions(+), 342 deletions(-) rename test/built-ins/FinalizationRegistry/{gc-has-one-chance-to-call-cleanupCallback.js => gc-has-one-chance-to-call-cleanupCallback-for-object.js} (74%) create mode 100644 test/built-ins/FinalizationRegistry/prototype/register/heldValue-same-as-target.js delete mode 100644 test/built-ins/FinalizationRegistry/prototype/register/holdings-same-as-target.js rename test/built-ins/FinalizationRegistry/prototype/register/{return-undefined.js => return-undefined-register-object.js} (59%) delete mode 100644 test/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-cell.js create mode 100644 test/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js rename test/built-ins/FinalizationRegistry/prototype/unregister/{unregister.js => unregister-object-token.js} (74%) rename test/built-ins/WeakMap/{iterable.js => iterable-with-object-keys.js} (67%) delete mode 100644 test/built-ins/WeakMap/prototype/delete/delete-entry-initial-iterable.js create mode 100644 test/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key-initial-iterable.js create mode 100644 test/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key.js delete mode 100644 test/built-ins/WeakMap/prototype/delete/delete-entry.js rename test/built-ins/WeakMap/prototype/delete/{returns-false-when-delete-is-noop.js => returns-false-when-object-key-not-present.js} (75%) rename test/built-ins/WeakMap/prototype/get/{returns-undefined.js => returns-undefined-with-object-key.js} (54%) rename test/built-ins/WeakMap/prototype/get/{returns-value.js => returns-value-with-object-key.js} (52%) rename test/built-ins/WeakMap/prototype/has/{returns-false-when-value-not-present.js => returns-false-when-object-key-not-present.js} (77%) rename test/built-ins/WeakMap/prototype/has/{returns-true-when-value-present.js => returns-true-when-object-key-present.js} (52%) rename test/built-ins/WeakMap/prototype/set/{adds-element.js => adds-object-element.js} (66%) rename test/built-ins/WeakRef/prototype/deref/{return-target.js => return-object-target.js} (65%) create mode 100644 test/built-ins/WeakRef/returns-new-object-from-constructor-with-object-target.js delete mode 100644 test/built-ins/WeakRef/returns-new-object-from-constructor.js rename test/built-ins/WeakSet/{iterable.js => iterable-with-object-values.js} (69%) rename test/built-ins/WeakSet/prototype/add/{adds-element.js => adds-object-element.js} (72%) rename test/built-ins/WeakSet/prototype/delete/{delete-entry.js => delete-object-entry.js} (50%) rename test/built-ins/WeakSet/prototype/has/{returns-false-when-value-not-present.js => returns-false-when-object-value-not-present.js} (76%) rename test/built-ins/WeakSet/prototype/has/{returns-true-when-value-present.js => returns-true-when-object-value-present.js} (56%) diff --git a/test/built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback.js b/test/built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback-for-object.js similarity index 74% rename from test/built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback.js rename to test/built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback-for-object.js index bc9d6f589d..54a482e8c9 100644 --- a/test/built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback.js +++ b/test/built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback-for-object.js @@ -4,27 +4,26 @@ /*--- esid: sec-finalization-registry-target description: > - cleanupCallback has only one optional chance to be called for a GC that cleans up - a registered target. + cleanupCallback has only one optional chance to be called for a GC that cleans + up a registered Object target. info: | - FinalizationRegistry ( cleanupCallback ) - - FinalizationRegistry.prototype.cleanupSome ( [ callback ] ) - - ... - 4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception. - 5. Perform ? CleanupFinalizationRegistry(finalizationRegistry, callback). - 6. Return undefined. + FinalizationRegistry.prototype.cleanupSome ( [ _callback_ ] ) + 3. If _callback_ is present and IsCallable(_callback_) is *false*, throw a + *TypeError* exception. + 4. Perform ? CleanupFinalizationRegistry(_finalizationRegistry_, _callback_). + 5. Return *undefined*. Execution - At any time, if an object obj is not live, an ECMAScript implementation may perform the following steps atomically: + At any time, if a set of objects and/or symbols _S_ is not live, an ECMAScript + implementation may perform the following steps atomically: - 1. For each WeakRef ref such that ref.[[Target]] is obj, - a. Set ref.[[Target]] to empty. - 2. For each FinalizationRegistry finalizationRegistry such that finalizationRegistry.[[Cells]] contains cell, such that cell.[[Target]] is obj, - a. Set cell.[[Target]] to empty. - b. Optionally, perform ! HostCleanupFinalizationRegistry(finalizationRegistry). + 1. For each element _value_ of _S_, do + ... + b. For each FinalizationRegistry _fg_ such that _fg_.[[Cells]] contains a + Record _cell_ such that _cell_.[[WeakRefTarget]] is _value_, + i. Set _cell_.[[WeakRefTarget]] to ~empty~. + ii. Optionally, perform HostEnqueueFinalizationRegistryCleanupJob(_fg_). features: [FinalizationRegistry.prototype.cleanupSome, FinalizationRegistry, async-functions, host-gc-required] flags: [async, non-deterministic] includes: [async-gc.js, compareArray.js] @@ -65,7 +64,7 @@ emptyCells().then(async function() { // optional. Although, we can finally assert it's not gonna be called anymore // for the other executions of the Garbage Collector. // The chance of having it called only happens right after the - // cell.[[Target]] is set to empty. + // cell.[[WeakRefTarget]] is set to empty. assert(cleanupCallback >= 0, 'cleanupCallback might be 0'); assert(cleanupCallback <= 1, 'cleanupCallback might be 1'); diff --git a/test/built-ins/FinalizationRegistry/prototype/register/heldValue-same-as-target.js b/test/built-ins/FinalizationRegistry/prototype/register/heldValue-same-as-target.js new file mode 100644 index 0000000000..24418bc242 --- /dev/null +++ b/test/built-ins/FinalizationRegistry/prototype/register/heldValue-same-as-target.js @@ -0,0 +1,19 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-finalization-registry.prototype.register +description: heldValue may be the same as target +info: | + FinalizationRegistry.prototype.register ( _target_ , _heldValue_ [, _unregisterToken_ ] ) + 1. Let _finalizationRegistry_ be the *this* value. + 2. Perform ? RequireInternalSlot(_finalizationRegistry_, [[Cells]]). + 3. If CanBeHeldWeakly(_target_) is *false*, throw a *TypeError* exception. + 4. If SameValue(_target_, _heldValue_) is *true*, throw a *TypeError* exception. +features: [FinalizationRegistry] +---*/ + +var finalizationRegistry = new FinalizationRegistry(function() {}); + +var target = {}; +assert.throws(TypeError, () => finalizationRegistry.register(target, target)); diff --git a/test/built-ins/FinalizationRegistry/prototype/register/holdings-same-as-target.js b/test/built-ins/FinalizationRegistry/prototype/register/holdings-same-as-target.js deleted file mode 100644 index 0eb126ac05..0000000000 --- a/test/built-ins/FinalizationRegistry/prototype/register/holdings-same-as-target.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2019 Leo Balter. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-finalization-registry.prototype.register -description: holdings may be the same as target -info: | - FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] ) - - 1. Let finalizationRegistry be the this value. - 2. If Type(finalizationRegistry) is not Object, throw a TypeError exception. - 3. If finalizationRegistry 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: [FinalizationRegistry] ----*/ - -var finalizationRegistry = new FinalizationRegistry(function() {}); - -var target = {}; -assert.throws(TypeError, () => finalizationRegistry.register(target, target)); diff --git a/test/built-ins/FinalizationRegistry/prototype/register/return-undefined.js b/test/built-ins/FinalizationRegistry/prototype/register/return-undefined-register-object.js similarity index 59% rename from test/built-ins/FinalizationRegistry/prototype/register/return-undefined.js rename to test/built-ins/FinalizationRegistry/prototype/register/return-undefined-register-object.js index 0df688827b..c409b78ae7 100644 --- a/test/built-ins/FinalizationRegistry/prototype/register/return-undefined.js +++ b/test/built-ins/FinalizationRegistry/prototype/register/return-undefined-register-object.js @@ -3,20 +3,21 @@ /*--- esid: sec-finalization-registry.prototype.register -description: Return undefined after registering +description: Return undefined after registering an Object info: | - FinalizationRegistry.prototype.register ( target , holdings [, unregisterToken ] ) - - 1. Let finalizationRegistry be the this value. - 2. If Type(finalizationRegistry) is not Object, throw a TypeError exception. - 3. If Type(target) is not Object, throw a TypeError exception. - 4. If finalizationRegistry 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 finalizationRegistry.[[Cells]]. - 8. Return undefined. + FinalizationRegistry.prototype.register ( _target_ , _heldValue_ [, _unregisterToken_ ] ) + 1. Let _finalizationRegistry_ be the *this* value. + 2. Perform ? RequireInternalSlot(_finalizationRegistry_, [[Cells]]). + 3. If CanBeHeldWeakly(_target_) is *false*, throw a *TypeError* exception. + 4. If SameValue(_target_, _heldValue_) is *true*, throw a *TypeError* + exception. + 5. If CanBeHeldWeakly(_unregisterToken_) is *false*, + a. If _unregisterToken_ is not *undefined*, throw a *TypeError* exception. + b. Set _unregisterToken_ to ~empty~. + 6. Let _cell_ be the Record { [[WeakRefTarget]]: _target_, [[HeldValue]]: + _heldValue_, [[UnregisterToken]]: _unregisterToken_ }. + 7. Append _cell_ to _finalizationRegistry_.[[Cells]]. + 8. Return *undefined*. features: [FinalizationRegistry] ---*/ @@ -24,7 +25,7 @@ var fn = function() {}; var finalizationRegistry = new FinalizationRegistry(fn); var target = {}; -assert.sameValue(finalizationRegistry.register(target), undefined, 'Register a targer'); +assert.sameValue(finalizationRegistry.register(target), undefined, 'Register a target'); assert.sameValue(finalizationRegistry.register(target), undefined, 'Register the same target again'); assert.sameValue(finalizationRegistry.register(target), undefined, 'Register the same target again and again'); diff --git a/test/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-cell.js b/test/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-cell.js deleted file mode 100644 index e303455086..0000000000 --- a/test/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-cell.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2019 Mathieu Hofman. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-finalization-registry.prototype.unregister -description: Cannot unregister a cell that has been cleaned up -info: | - FinalizationRegistry.prototype.cleanupSome ( [ callback ] ) - - 1. Let finalizationRegistry be the this value. - ... - 5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback). - ... - - CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] ) - - ... - 3. While finalizationRegistry.[[Cells]] contains a Record cell such that cell.[[WeakRefTarget]] is ~empty~, then an implementation may perform the following steps, - a. Choose any such cell. - b. Remove cell from finalizationRegistry.[[Cells]]. - c. Perform ? Call(callback, undefined, << cell.[[HeldValue]] >>). - ... - - FinalizationRegistry.prototype.unregister ( unregisterToken ) - - 1. Let removed be false. - 2. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationRegistry.[[Cells]], do - a. If SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then - i. Remove cell from finalizationRegistry.[[Cells]]. - ii. Set removed to true. - 3. Return removed. -features: [FinalizationRegistry.prototype.cleanupSome, FinalizationRegistry, host-gc-required] -includes: [async-gc.js] -flags: [async, non-deterministic] ----*/ - -var value = 'target!'; -var token = {}; -var finalizationRegistry = new FinalizationRegistry(function() {}); - -function emptyCells() { - var target = {}; - finalizationRegistry.register(target, value, token); - - var prom = asyncGC(target); - target = null; - - return prom; -} - -emptyCells().then(function() { - var called = 0; - var holdings = []; - finalizationRegistry.cleanupSome(function cb(holding) { - called += 1; - holdings.push(holding); - }); - - assert.sameValue(called, 1); - assert.sameValue(holdings.length, 1); - assert.sameValue(holdings[0], value); - - var res = finalizationRegistry.unregister(token); - assert.sameValue(res, false, 'unregister after iterating over it in cleanup'); -}).then($DONE, resolveAsyncGC); diff --git a/test/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js b/test/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js new file mode 100644 index 0000000000..89e47291bd --- /dev/null +++ b/test/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js @@ -0,0 +1,63 @@ +// Copyright (C) 2019 Mathieu Hofman. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-finalization-registry.prototype.unregister +description: > + Cannot unregister a cell referring to an Object that has been cleaned up +info: | + FinalizationRegistry.prototype.cleanupSome ( [ _callback_ ] ) + 4. Perform ? CleanupFinalizationRegistry(_finalizationRegistry_, _callback_). + + CleanupFinalizationRegistry ( _finalizationRegistry_ ): + 3. While _finalizationRegistry_.[[Cells]] contains a Record _cell_ such that + _cell_.[[WeakRefTarget]] is ~empty~, then an implementation may perform the + following steps: + a. Choose any such _cell_. + b. Remove _cell_ from _finalizationRegistry_.[[Cells]]. + c. Perform ? HostCallJobCallback(_callback_, *undefined*, + « _cell_.[[HeldValue]] »). + + FinalizationRegistry.prototype.unregister ( _unregisterToken_ ) + 4. Let _removed_ be *false*. + 5. For each Record { [[WeakRefTarget]], [[HeldValue]], [[UnregisterToken]] } + _cell_ of _finalizationRegistry_.[[Cells]], do + a. If _cell_.[[UnregisterToken]] is not ~empty~ and + SameValue(_cell_.[[UnregisterToken]], _unregisterToken_) is *true*, then + i. Remove _cell_ from _finalizationRegistry_.[[Cells]]. + ii. Set _removed_ to *true*. + 6. Return _removed_. +features: [FinalizationRegistry.prototype.cleanupSome, FinalizationRegistry, host-gc-required] +includes: [async-gc.js] +flags: [async, non-deterministic] +---*/ + +var value = 'target!'; +var token = {}; +var finalizationRegistry = new FinalizationRegistry(function() {}); + +function emptyCells() { + var target = {}; + finalizationRegistry.register(target, value, token); + + var prom = asyncGC(target); + target = null; + + return prom; +} + +emptyCells().then(function() { + var called = 0; + var holdings = []; + finalizationRegistry.cleanupSome(function cb(holding) { + called += 1; + holdings.push(holding); + }); + + assert.sameValue(called, 1); + assert.sameValue(holdings.length, 1); + assert.sameValue(holdings[0], value); + + var res = finalizationRegistry.unregister(token); + assert.sameValue(res, false, 'unregister after iterating over it in cleanup'); +}).then($DONE, resolveAsyncGC); diff --git a/test/built-ins/FinalizationRegistry/prototype/unregister/unregister.js b/test/built-ins/FinalizationRegistry/prototype/unregister/unregister-object-token.js similarity index 74% rename from test/built-ins/FinalizationRegistry/prototype/unregister/unregister.js rename to test/built-ins/FinalizationRegistry/prototype/unregister/unregister-object-token.js index d0c96e94f6..ba93559140 100644 --- a/test/built-ins/FinalizationRegistry/prototype/unregister/unregister.js +++ b/test/built-ins/FinalizationRegistry/prototype/unregister/unregister-object-token.js @@ -3,20 +3,18 @@ /*--- esid: sec-finalization-registry.prototype.unregister -description: Return boolean values indicating unregistering of values from given token +description: > + Return boolean values indicating unregistering of values with Object token info: | - FinalizationRegistry.prototype.unregister ( unregisterToken ) - - 1. Let finalizationRegistry be the this value. - 2. If Type(finalizationRegistry) is not Object, throw a TypeError exception. - 3. If finalizationRegistry does not have a [[Cells]] internal slot, throw a TypeError exception. - 4. If Type(unregisterToken) is not Object, throw a TypeError exception. - 5. Let removed be false. - 6. For each Record { [[Target]], [[Holdings]], [[UnregisterToken]] } cell that is an element of finalizationRegistry.[[Cells]], do - a. If SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then - i. Remove cell from finalizationRegistry.[[Cells]]. - ii. Set removed to true. - 7. Return removed. + FinalizationRegistry.prototype.unregister ( _unregisterToken_ ) + 4. Let _removed_ be *false*. + 5. For each Record { [[WeakRefTarget]], [[HeldValue]], [[UnregisterToken]] } + _cell_ of _finalizationRegistry_.[[Cells]], do + a. If _cell_.[[UnregisterToken]] is not ~empty~ and + SameValue(_cell_.[[UnregisterToken]], _unregisterToken_) is *true*, then + i. Remove _cell_ from _finalizationRegistry_.[[Cells]]. + ii. Set _removed_ to *true*. + 6. Return _removed_. features: [FinalizationRegistry] ---*/ diff --git a/test/built-ins/WeakMap/iterable.js b/test/built-ins/WeakMap/iterable-with-object-keys.js similarity index 67% rename from test/built-ins/WeakMap/iterable.js rename to test/built-ins/WeakMap/iterable-with-object-keys.js index 3f316f8ae3..d91f7a03ac 100644 --- a/test/built-ins/WeakMap/iterable.js +++ b/test/built-ins/WeakMap/iterable-with-object-keys.js @@ -3,14 +3,20 @@ /*--- esid: sec-weakmap-iterable description: > - Returns the new WeakMap adding the objects from the iterable parameter. + Returns the new WeakMap adding entries from the iterable parameter, with + Object keys. info: | - WeakMap ( [ iterable ] ) + WeakMap ( [ _iterable_ ] ) + 5. Let _adder_ be ? Get(_map_, *"set"*). + 6. Return ? AddEntriesFromIterable(_map_, _iterable_, _adder_). - ... - 9. Repeat - k. Let status be Call(adder, map, «k.[[value]], v.[[value]]»). - l. If status is an abrupt completion, return IteratorClose(iter, status). + AddEntriesFromIterable: + 3. Repeat, + i. Let _status_ be Completion(Call(_adder_, _target_, « _k_, _v_ »)). + + WeakMap.prototype.set( _key_, _value_ ): + 6. Let _p_ be the Record {[[Key]]: _key_, [[Value]]: _value_}. + 7. Append _p_ as the last element of _entries_. features: [WeakMap] ---*/ diff --git a/test/built-ins/WeakMap/prototype/delete/delete-entry-initial-iterable.js b/test/built-ins/WeakMap/prototype/delete/delete-entry-initial-iterable.js deleted file mode 100644 index 7d3096e2ea..0000000000 --- a/test/built-ins/WeakMap/prototype/delete/delete-entry-initial-iterable.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-weakmap.prototype.delete -description: > - Delete an entry from initial iterable. -info: | - WeakMap.prototype.delete ( value ) - - ... - 5. Let entries be the List that is the value of M’s [[WeakMapData]] internal - slot. - 6. If Type(key) is not Object, return false. - 7. Repeat for each Record {[[key]], [[value]]} p that is an element of - entries, - a. If p.[[key]] is not empty and SameValue(p.[[key]], key) is true, then - i. Set p.[[key]] to empty. - ii. Set p.[[value]] to empty. - iii. Return true. - ... -features: [WeakMap] ----*/ - -var foo = {}; -var map = new WeakMap([ - [foo, 42] -]); - -var result = map.delete(foo); - -assert.sameValue(map.has(foo), false); -assert.sameValue(result, true, 'WeakMap#delete returns true'); diff --git a/test/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key-initial-iterable.js b/test/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key-initial-iterable.js new file mode 100644 index 0000000000..824e041055 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key-initial-iterable.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.delete +description: > + Delete an entry with an Object key, added from initial iterable. +info: | + WeakMap.prototype.delete ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *false*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, then + i. Set _p_.[[Key]] to ~empty~. + ii. Set _p_.[[Value]] to ~empty~. + iii. Return *true*. +features: [WeakMap] +---*/ + +var foo = {}; +var map = new WeakMap([ + [foo, 42] +]); + +var result = map.delete(foo); + +assert.sameValue(map.has(foo), false); +assert.sameValue(result, true, 'WeakMap#delete returns true'); diff --git a/test/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key.js b/test/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key.js new file mode 100644 index 0000000000..509a15955f --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.delete +description: > + Delete an entry with an Object key. +info: | + WeakMap.prototype.delete ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *false*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, then + i. Set _p_.[[Key]] to ~empty~. + ii. Set _p_.[[Value]] to ~empty~. + iii. Return *true*. +features: [WeakMap] +---*/ + +var foo = {}; +var map = new WeakMap(); + +map.set(foo, 42); + +var result = map.delete(foo); + +assert.sameValue(map.has(foo), false); +assert.sameValue(result, true, 'WeakMap#delete returns true'); diff --git a/test/built-ins/WeakMap/prototype/delete/delete-entry.js b/test/built-ins/WeakMap/prototype/delete/delete-entry.js deleted file mode 100644 index 022c435aff..0000000000 --- a/test/built-ins/WeakMap/prototype/delete/delete-entry.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-weakmap.prototype.delete -description: > - Delete an entry. -info: | - WeakMap.prototype.delete ( value ) - - ... - 5. Let entries be the List that is the value of M’s [[WeakMapData]] internal - slot. - 6. If Type(key) is not Object, return false. - 7. Repeat for each Record {[[key]], [[value]]} p that is an element of - entries, - a. If p.[[key]] is not empty and SameValue(p.[[key]], key) is true, then - i. Set p.[[key]] to empty. - ii. Set p.[[value]] to empty. - iii. Return true. - ... -features: [WeakMap] ----*/ - -var foo = {}; -var map = new WeakMap(); - -map.set(foo, 42); - -var result = map.delete(foo); - -assert.sameValue(map.has(foo), false); -assert.sameValue(result, true, 'WeakMap#delete returns true'); diff --git a/test/built-ins/WeakMap/prototype/delete/returns-false-when-delete-is-noop.js b/test/built-ins/WeakMap/prototype/delete/returns-false-when-object-key-not-present.js similarity index 75% rename from test/built-ins/WeakMap/prototype/delete/returns-false-when-delete-is-noop.js rename to test/built-ins/WeakMap/prototype/delete/returns-false-when-object-key-not-present.js index adb9c94971..c619729177 100644 --- a/test/built-ins/WeakMap/prototype/delete/returns-false-when-delete-is-noop.js +++ b/test/built-ins/WeakMap/prototype/delete/returns-false-when-object-key-not-present.js @@ -3,13 +3,10 @@ /*--- esid: sec-weakmap.prototype.delete description: > - Return false if entry is not in the WeakMap. + Return false if an Object key is not in the WeakMap. info: | - WeakMap.prototype.delete ( value ) - - ... - 7. Return false. - + WeakMap.prototype.delete ( _key_ ) + 6. Return *false*. features: [WeakMap] ---*/ diff --git a/test/built-ins/WeakMap/prototype/get/returns-undefined.js b/test/built-ins/WeakMap/prototype/get/returns-undefined-with-object-key.js similarity index 54% rename from test/built-ins/WeakMap/prototype/get/returns-undefined.js rename to test/built-ins/WeakMap/prototype/get/returns-undefined-with-object-key.js index 0723ccda81..052fc7134f 100644 --- a/test/built-ins/WeakMap/prototype/get/returns-undefined.js +++ b/test/built-ins/WeakMap/prototype/get/returns-undefined-with-object-key.js @@ -3,19 +3,15 @@ /*--- esid: sec-weakmap.prototype.get description: > - Returns undefined when key is not on the WeakMap object. + Returns undefined when an Object key is not on the WeakMap object. info: | - WeakMap.prototype.get ( key ) - - 4. Let entries be the List that is the value of M’s [[WeakMapData]] internal - slot. - 5. If Type(key) is not Object, return undefined. - 6. Repeat for each Record {[[key]], [[value]]} p that is an element of - entries, - a. If p.[[key]] is not empty and SameValue(p.[[key]], key) is true, return - p.[[value]]. - 7. Return undefined. - ... + WeakMap.prototype.get ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *undefined*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not empty and SameValue(_p_.[[Key]], _key_) is *true*, + return _p_.[[Value]]. + 6. Return *undefined*. features: [WeakMap] ---*/ diff --git a/test/built-ins/WeakMap/prototype/get/returns-value.js b/test/built-ins/WeakMap/prototype/get/returns-value-with-object-key.js similarity index 52% rename from test/built-ins/WeakMap/prototype/get/returns-value.js rename to test/built-ins/WeakMap/prototype/get/returns-value-with-object-key.js index 3c4f160ad1..c8ddcee648 100644 --- a/test/built-ins/WeakMap/prototype/get/returns-value.js +++ b/test/built-ins/WeakMap/prototype/get/returns-value-with-object-key.js @@ -3,18 +3,14 @@ /*--- esid: sec-weakmap.prototype.get description: > - Returns the value from the specified key + Returns the value from the specified Object key info: | - WeakMap.prototype.get ( key ) - - 4. Let entries be the List that is the value of M’s [[WeakMapData]] internal - slot. - 5. If Type(key) is not Object, return undefined. - 6. Repeat for each Record {[[key]], [[value]]} p that is an element of - entries, - a. If p.[[key]] is not empty and SameValue(p.[[key]], key) is true, return - p.[[value]]. - ... + WeakMap.prototype.get ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *undefined*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, return _p_.[[Value]]. features: [WeakMap] ---*/ diff --git a/test/built-ins/WeakMap/prototype/has/returns-false-when-value-not-present.js b/test/built-ins/WeakMap/prototype/has/returns-false-when-object-key-not-present.js similarity index 77% rename from test/built-ins/WeakMap/prototype/has/returns-false-when-value-not-present.js rename to test/built-ins/WeakMap/prototype/has/returns-false-when-object-key-not-present.js index 6698f3884a..7ec1b4e91b 100644 --- a/test/built-ins/WeakMap/prototype/has/returns-false-when-value-not-present.js +++ b/test/built-ins/WeakMap/prototype/has/returns-false-when-object-key-not-present.js @@ -3,12 +3,10 @@ /*--- esid: sec-weakmap.prototype.has description: > - Return false when value is not present in the WeakMap entries. + Return false when an Object key is not present in the WeakMap entries. info: | - WeakMap.prototype.has ( value ) - - ... - 7. Return false. + WeakMap.prototype.has ( _key_ ) + 6. Return *false*. features: [WeakMap] ---*/ diff --git a/test/built-ins/WeakMap/prototype/has/returns-true-when-value-present.js b/test/built-ins/WeakMap/prototype/has/returns-true-when-object-key-present.js similarity index 52% rename from test/built-ins/WeakMap/prototype/has/returns-true-when-value-present.js rename to test/built-ins/WeakMap/prototype/has/returns-true-when-object-key-present.js index bdc01de69c..b3e82a23dd 100644 --- a/test/built-ins/WeakMap/prototype/has/returns-true-when-value-present.js +++ b/test/built-ins/WeakMap/prototype/has/returns-true-when-object-key-present.js @@ -3,16 +3,12 @@ /*--- esid: sec-weakmap.prototype.has description: > - Returns true when value is present in the WeakMap entries list. + Returns true when an Object key is present in the WeakMap entries list. info: | - WeakMap.prototype.has ( value ) - - ... - 6. Repeat for each Record {[[key]], [[value]]} p that is an element of - entries, - a. If p.[[key]] is not empty and SameValue(p.[[key]], key) is true, return - true. - ... + WeakMap.prototype.has ( _key_ ) + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, return *true*. features: [WeakMap] ---*/ diff --git a/test/built-ins/WeakMap/prototype/set/adds-element.js b/test/built-ins/WeakMap/prototype/set/adds-object-element.js similarity index 66% rename from test/built-ins/WeakMap/prototype/set/adds-element.js rename to test/built-ins/WeakMap/prototype/set/adds-object-element.js index 4c2d382c48..f3093a6f10 100644 --- a/test/built-ins/WeakMap/prototype/set/adds-element.js +++ b/test/built-ins/WeakMap/prototype/set/adds-object-element.js @@ -3,14 +3,11 @@ /*--- esid: sec-weakmap.prototype.set description: > - Appends value as the last element of entries. + Adds a value with an Object key. info: | - WeakMap.prototype.set ( key, value ) - - ... - 7. Let p be the Record {[[key]]: key, [[value]]: value}. - 8. Append p as the last element of entries. - ... + WeakMap.prototype.set ( _key_, _value_ ) + 6. Let _p_ be the Record {[[Key]]: _key_, [[Value]]: _value_}. + 7. Append _p_ as the last element of _entries_. features: [WeakMap] ---*/ diff --git a/test/built-ins/WeakRef/prototype/deref/return-target.js b/test/built-ins/WeakRef/prototype/deref/return-object-target.js similarity index 65% rename from test/built-ins/WeakRef/prototype/deref/return-target.js rename to test/built-ins/WeakRef/prototype/deref/return-object-target.js index 19bb5e6204..2c3634cca5 100644 --- a/test/built-ins/WeakRef/prototype/deref/return-target.js +++ b/test/built-ins/WeakRef/prototype/deref/return-object-target.js @@ -3,16 +3,16 @@ /*--- esid: sec-weak-ref.prototype.deref -description: Return target if weakRef.[[Target]] is not empty +description: Return an Object target if weakRef.[[Target]] is not empty info: | WeakRef.prototype.deref () + 3. Return WeakRefDeref(_weakRef_). - ... - 4. Let target be the value of weakRef.[[Target]]. - 5. If target is not empty, - a. Perform ! KeepDuringJob(target). - b. Return target. - 6. Return undefined. + WeakRefDeref( _weakRef_ ): + 1. Let _target_ be _weakRef_.[[WeakRefTarget]]. + 2. If _target_ is not ~empty~, + a. Perform AddToKeptObjects(_target_). + b. Return _target_. features: [WeakRef] ---*/ diff --git a/test/built-ins/WeakRef/returns-new-object-from-constructor-with-object-target.js b/test/built-ins/WeakRef/returns-new-object-from-constructor-with-object-target.js new file mode 100644 index 0000000000..4150cb5332 --- /dev/null +++ b/test/built-ins/WeakRef/returns-new-object-from-constructor-with-object-target.js @@ -0,0 +1,35 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-weak-ref-target +description: > + Returns a new ordinary object from the WeakRef constructor when called with an + Object target +info: | + WeakRef ( _target_ ) + 3. Let _weakRef_ be ? OrdinaryCreateFromConstructor(NewTarget, + *"%WeakRefPrototype%"*, « [[WeakRefTarget]] »). + 4. Perfom AddToKeptObjects(_target_). + 5. Set _weakRef_.[[WeakRefTarget]] to _target_. + 6. Return _weakRef_. +features: [WeakRef] +---*/ + +var target = {}; +var wr = new WeakRef(target); + +assert.notSameValue(wr, target, 'does not return the same object'); +assert.sameValue(wr instanceof WeakRef, true, 'instanceof'); + +for (let key of Object.getOwnPropertyNames(wr)) { + assert(false, `should not set any own named properties: ${key}`); +} + +for (let key of Object.getOwnPropertySymbols(wr)) { + assert(false, `should not set any own symbol properties: ${String(key)}`); +} + +assert.sameValue(Object.getPrototypeOf(wr), WeakRef.prototype); + + diff --git a/test/built-ins/WeakRef/returns-new-object-from-constructor.js b/test/built-ins/WeakRef/returns-new-object-from-constructor.js deleted file mode 100644 index 9e52f88d6b..0000000000 --- a/test/built-ins/WeakRef/returns-new-object-from-constructor.js +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2019 Leo Balter. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-weak-ref-target -description: > - Returns a new ordinary object from the WeakRef constructor -info: | - WeakRef ( target ) - - ... - 3. Let weakRef be ? OrdinaryCreateFromConstructor(NewTarget, "%WeakRefPrototype%", « [[Target]] »). - 4. Perfom ! KeepDuringJob(target). - 5. Set weakRef.[[Target]] to target. - 6. Return weakRef. - - OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) - - ... - 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). - 3. Return ObjectCreate(proto, internalSlotsList). - - GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) - - 3. Let proto be ? Get(constructor, 'prototype'). - 4. If Type(proto) is not Object, then - a. Let realm be ? GetFunctionRealm(constructor). - b. Set proto to realm's intrinsic object named intrinsicDefaultProto. - 5. Return proto. -features: [WeakRef] ----*/ - -var target = {}; -var wr = new WeakRef(target); - -assert.notSameValue(wr, target, 'does not return the same object'); -assert.sameValue(wr instanceof WeakRef, true, 'instanceof'); - -for (let key of Object.getOwnPropertyNames(wr)) { - assert(false, `should not set any own named properties: ${key}`); -} - -for (let key of Object.getOwnPropertySymbols(wr)) { - assert(false, `should not set any own symbol properties: ${String(key)}`); -} - -assert.sameValue(Object.getPrototypeOf(wr), WeakRef.prototype); - - diff --git a/test/built-ins/WeakSet/iterable.js b/test/built-ins/WeakSet/iterable-with-object-values.js similarity index 69% rename from test/built-ins/WeakSet/iterable.js rename to test/built-ins/WeakSet/iterable-with-object-values.js index 51b0117507..a141b67c5e 100644 --- a/test/built-ins/WeakSet/iterable.js +++ b/test/built-ins/WeakSet/iterable-with-object-values.js @@ -3,14 +3,14 @@ /*--- esid: sec-weakset-iterable description: > - Returns the new WeakSet adding the objects from the iterable parameter. + Returns the new WeakSet adding Object values from the iterable parameter. info: | - WeakSet ( [ iterable ] ) + WeakSet ( [ _iterable_ ] ) + 8. Repeat, + d. Let _status_ be Completion(Call(_adder_, _set_, « _nextValue_ »)). - ... - 9. Repeat - f. Let status be Call(adder, set, «nextValue»). - g. If status is an abrupt completion, return IteratorClose(iter, status). + WeakSet.prototype.add ( _value_ ): + 6. Append _value_ as the last element of _entries_. features: [WeakSet] ---*/ diff --git a/test/built-ins/WeakSet/prototype/add/adds-element.js b/test/built-ins/WeakSet/prototype/add/adds-object-element.js similarity index 72% rename from test/built-ins/WeakSet/prototype/add/adds-element.js rename to test/built-ins/WeakSet/prototype/add/adds-object-element.js index cb9e71a1e3..f30a2463ce 100644 --- a/test/built-ins/WeakSet/prototype/add/adds-element.js +++ b/test/built-ins/WeakSet/prototype/add/adds-object-element.js @@ -3,13 +3,10 @@ /*--- esid: sec-weakset.prototype.add description: > - Appends value as the last element of entries. + Adds an Object value. info: | - WeakSet.prototype.add ( value ) - - ... - 7. Append value as the last element of entries. - ... + WeakSet.prototype.add ( _value_ ) + 6. Append _value_ as the last element of _entries_. features: [WeakSet] ---*/ diff --git a/test/built-ins/WeakSet/prototype/delete/delete-entry.js b/test/built-ins/WeakSet/prototype/delete/delete-object-entry.js similarity index 50% rename from test/built-ins/WeakSet/prototype/delete/delete-entry.js rename to test/built-ins/WeakSet/prototype/delete/delete-object-entry.js index 2655674927..8f029e6757 100644 --- a/test/built-ins/WeakSet/prototype/delete/delete-entry.js +++ b/test/built-ins/WeakSet/prototype/delete/delete-object-entry.js @@ -3,19 +3,15 @@ /*--- esid: sec-weakset.prototype.delete description: > - Delete an entry. + Delete an entry that is an Object info: | - WeakSet.prototype.delete ( value ) - - ... - 5. Let entries be the List that is the value of S’s [[WeakSetData]] internal - slot. - 6. Repeat for each e that is an element of entries, - a. If e is not empty and SameValue(e, value) is true, then - i. Replace the element of entries whose value is e with an element whose - value is empty. - ii. Return true. - ... + WeakSet.prototype.delete ( _value_ ) + 4. Let _entries_ be the List that is _S_.[[WeakSetData]]. + 5. For each element _e_ of _entries_, do + a. If _e_ is not ~empty~ and SameValue(_e_, _value_) is *true*, then + i. Replace the element of _entries_ whose value is _e_ with an element + whose value is ~empty~. + ii. Return *true*. features: [WeakSet] ---*/ diff --git a/test/built-ins/WeakSet/prototype/has/returns-false-when-value-not-present.js b/test/built-ins/WeakSet/prototype/has/returns-false-when-object-value-not-present.js similarity index 76% rename from test/built-ins/WeakSet/prototype/has/returns-false-when-value-not-present.js rename to test/built-ins/WeakSet/prototype/has/returns-false-when-object-value-not-present.js index 7748e5e7c3..63a03f863d 100644 --- a/test/built-ins/WeakSet/prototype/has/returns-false-when-value-not-present.js +++ b/test/built-ins/WeakSet/prototype/has/returns-false-when-object-value-not-present.js @@ -3,12 +3,10 @@ /*--- esid: sec-weakset.prototype.has description: > - Return false when value is not present in the WeakSet entries. + Return false when an Object value is not present in the WeakSet entries. info: | - WeakSet.prototype.has ( value ) - - ... - 7. Return false. + WeakSet.prototype.has ( _value_ ) + 6. Return *false*. features: [WeakSet] ---*/ diff --git a/test/built-ins/WeakSet/prototype/has/returns-true-when-value-present.js b/test/built-ins/WeakSet/prototype/has/returns-true-when-object-value-present.js similarity index 56% rename from test/built-ins/WeakSet/prototype/has/returns-true-when-value-present.js rename to test/built-ins/WeakSet/prototype/has/returns-true-when-object-value-present.js index 12faddcdac..08c7dd1609 100644 --- a/test/built-ins/WeakSet/prototype/has/returns-true-when-value-present.js +++ b/test/built-ins/WeakSet/prototype/has/returns-true-when-object-value-present.js @@ -3,14 +3,11 @@ /*--- esid: sec-weakset.prototype.has description: > - Returns true when value is present in the WeakSet entries list. + Returns true when an Object value is present in the WeakSet entries list. info: | - WeakSet.prototype.has ( value ) - - ... - 6. Repeat for each e that is an element of entries, - a. If e is not empty and SameValue(e, value) is true, return true. - ... + WeakSet.prototype.has ( _value_ ) + 5. For each element _e_ of _entries_, do + a. If _e_ is not ~empty~ and SameValue(_e_, _value_) is *true*, return *true*. features: [WeakSet] ---*/