mirror of https://github.com/tc39/test262.git
Add more tests, include deref
This commit is contained in:
parent
c2c81409b2
commit
ab38ce4e84
|
@ -0,0 +1,27 @@
|
|||
// 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.prototype.deref
|
||||
description: Return target if weakRef.[[Target]] is not empty (applying custom this)
|
||||
info: |
|
||||
WeakRef.prototype.deref ()
|
||||
|
||||
1. Let weakRef be the this value.
|
||||
...
|
||||
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.
|
||||
features: [WeakRef]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var deref = WeakRef.prototype.deref;
|
||||
var wref = new WeakRef(target);
|
||||
|
||||
assert.sameValue(deref.call(wref), target, 'returns target');
|
||||
assert.sameValue(deref.call(wref), target, '[[Target]] is not emptied #1');
|
||||
assert.sameValue(deref.call(wref), target, '[[Target]] is not emptied #2');
|
||||
assert.sameValue(deref.call(wref), target, '[[Target]] is not emptied #3');
|
|
@ -0,0 +1,32 @@
|
|||
// 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.prototype.deref
|
||||
description: WeakRef.prototype.deref.length property descriptor
|
||||
info: |
|
||||
WeakRef.prototype.deref ()
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
Every built-in function object, including constructors, has a length
|
||||
property whose value is an integer. Unless otherwise specified, this
|
||||
value is equal to the largest number of named arguments shown in the
|
||||
subclause headings for the function description. Optional parameters
|
||||
(which are indicated with brackets: [ ]) or rest parameters (which
|
||||
are shown using the form «...name») are not included in the default
|
||||
argument count.
|
||||
|
||||
Unless otherwise specified, the length property of a built-in
|
||||
function object has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [WeakRef]
|
||||
---*/
|
||||
|
||||
verifyProperty(WeakRef.prototype.deref, 'length', {
|
||||
value: 0,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
// 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.prototype.deref
|
||||
description: WeakRef.prototype.deref.name property descriptor
|
||||
info: |
|
||||
WeakRef.prototype.deref.name value and property descriptor
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
Every built-in function object, including constructors, that is not
|
||||
identified as an anonymous function has a name property whose value
|
||||
is a String. Unless otherwise specified, this value is the name that
|
||||
is given to the function in this specification. For functions that
|
||||
are specified as properties of objects, the name value is the
|
||||
property name string used to access the function. [...]
|
||||
|
||||
Unless otherwise specified, the name property of a built-in function
|
||||
object, if it exists, has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [WeakRef]
|
||||
---*/
|
||||
|
||||
verifyProperty(WeakRef.prototype.deref, 'name', {
|
||||
value: 'deref',
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
// 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.prototype.deref
|
||||
description: >
|
||||
Property descriptor of WeakRef.prototype.deref
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
|
||||
Every other data property described in clauses 18 through 26 and in Annex B.2
|
||||
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
features: [WeakRef]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof WeakRef.prototype.deref, 'function');
|
||||
|
||||
verifyProperty(WeakRef.prototype, 'deref', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
// 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.prototype.deref
|
||||
description: Return target if weakRef.[[Target]] is not empty
|
||||
info: |
|
||||
WeakRef.prototype.deref ()
|
||||
|
||||
...
|
||||
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.
|
||||
features: [WeakRef]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var wref = new WeakRef(target);
|
||||
|
||||
assert.sameValue(wref.deref(), target, 'returns target');
|
||||
assert.sameValue(wref.deref(), target, '[[Target]] is not emptied #1');
|
||||
assert.sameValue(wref.deref(), target, '[[Target]] is not emptied #2');
|
||||
assert.sameValue(wref.deref(), target, '[[Target]] is not emptied #3');
|
45
test/built-ins/WeakRef/prototype/deref/this-does-not-have-internal-target-throws.js
vendored
Normal file
45
test/built-ins/WeakRef/prototype/deref/this-does-not-have-internal-target-throws.js
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
// 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.prototype.deref
|
||||
description: Throws a TypeError if this does not have a [[Target]] internal slot
|
||||
info: |
|
||||
WeakRef.prototype.deref ()
|
||||
|
||||
1. Let weakRef be the this value.
|
||||
2. If Type(weakRef) is not Object, throw a TypeError exception.
|
||||
3. If weakRef does not have a [[Target]] internal slot, throw a TypeError exception.
|
||||
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.
|
||||
features: [WeakRef]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof WeakRef.prototype.deref, 'function');
|
||||
|
||||
var defer = WeakRef.prototype.defer;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call({ ['[[Target]]']: {} });
|
||||
}, 'Ordinary object without [[Target]]');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call(WeakRef.prototype);
|
||||
}, 'WeakRef.prototype does not have a [[Target]] internal slot');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call(WeakRef);
|
||||
}, 'WeakRef does not have a [[Target]] internal slot');
|
||||
|
||||
var wm = new WeakMap();
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call(wm);
|
||||
}, 'WeakMap instance');
|
||||
|
||||
var ws = new WeakSet();
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call(ws);
|
||||
}, 'WeakSet instance');
|
|
@ -0,0 +1,52 @@
|
|||
// 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.prototype.deref
|
||||
description: Throws a TypeError if this is not an Object
|
||||
info: |
|
||||
WeakRef.prototype.deref ()
|
||||
|
||||
1. Let weakRef be the this value.
|
||||
2. If Type(weakRef) is not Object, throw a TypeError exception.
|
||||
3. If weakRef does not have a [[Target]] internal slot, throw a TypeError exception.
|
||||
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.
|
||||
features: [WeakRef]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof WeakRef.prototype.deref, 'function');
|
||||
|
||||
var defer = WeakRef.prototype.defer;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call(undefined);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call(true);
|
||||
}, 'true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call(false);
|
||||
}, 'false');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call(1);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call('object');
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
defer.call(s);
|
||||
}, 'symbol');
|
|
@ -0,0 +1,49 @@
|
|||
// 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);
|
||||
|
||||
|
Loading…
Reference in New Issue