mirror of https://github.com/tc39/test262.git
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
This commit is contained in:
parent
6291e42a72
commit
d101ab9bc4
|
@ -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');
|
||||
|
19
test/built-ins/FinalizationRegistry/prototype/register/heldValue-same-as-target.js
vendored
Normal file
19
test/built-ins/FinalizationRegistry/prototype/register/heldValue-same-as-target.js
vendored
Normal file
|
@ -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));
|
|
@ -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));
|
|
@ -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');
|
||||
|
|
@ -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);
|
63
test/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js
vendored
Normal file
63
test/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js
vendored
Normal file
|
@ -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);
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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');
|
28
test/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key-initial-iterable.js
vendored
Normal file
28
test/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key-initial-iterable.js
vendored
Normal file
|
@ -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');
|
|
@ -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');
|
|
@ -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');
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
Loading…
Reference in New Issue