From ab38ce4e84c313fd85b49a5a1f087c58478be001 Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Fri, 7 Jun 2019 15:04:51 -0400 Subject: [PATCH] Add more tests, include deref --- .../WeakRef/prototype/deref/custom-this.js | 27 ++++++++++ .../WeakRef/prototype/deref/length.js | 32 ++++++++++++ .../built-ins/WeakRef/prototype/deref/name.js | 31 +++++++++++ .../WeakRef/prototype/deref/prop-desc.js | 24 +++++++++ .../WeakRef/prototype/deref/return-target.js | 25 +++++++++ ...is-does-not-have-internal-target-throws.js | 45 ++++++++++++++++ .../prototype/deref/this-not-object-throws.js | 52 +++++++++++++++++++ .../returns-new-object-from-constructor.js | 49 +++++++++++++++++ 8 files changed, 285 insertions(+) create mode 100644 test/built-ins/WeakRef/prototype/deref/custom-this.js create mode 100644 test/built-ins/WeakRef/prototype/deref/length.js create mode 100644 test/built-ins/WeakRef/prototype/deref/name.js create mode 100644 test/built-ins/WeakRef/prototype/deref/prop-desc.js create mode 100644 test/built-ins/WeakRef/prototype/deref/return-target.js create mode 100644 test/built-ins/WeakRef/prototype/deref/this-does-not-have-internal-target-throws.js create mode 100644 test/built-ins/WeakRef/prototype/deref/this-not-object-throws.js create mode 100644 test/built-ins/WeakRef/returns-new-object-from-constructor.js diff --git a/test/built-ins/WeakRef/prototype/deref/custom-this.js b/test/built-ins/WeakRef/prototype/deref/custom-this.js new file mode 100644 index 0000000000..44d571d171 --- /dev/null +++ b/test/built-ins/WeakRef/prototype/deref/custom-this.js @@ -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'); diff --git a/test/built-ins/WeakRef/prototype/deref/length.js b/test/built-ins/WeakRef/prototype/deref/length.js new file mode 100644 index 0000000000..f9103c0cf5 --- /dev/null +++ b/test/built-ins/WeakRef/prototype/deref/length.js @@ -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 +}); diff --git a/test/built-ins/WeakRef/prototype/deref/name.js b/test/built-ins/WeakRef/prototype/deref/name.js new file mode 100644 index 0000000000..5d512bb03d --- /dev/null +++ b/test/built-ins/WeakRef/prototype/deref/name.js @@ -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 +}); diff --git a/test/built-ins/WeakRef/prototype/deref/prop-desc.js b/test/built-ins/WeakRef/prototype/deref/prop-desc.js new file mode 100644 index 0000000000..e8d0359149 --- /dev/null +++ b/test/built-ins/WeakRef/prototype/deref/prop-desc.js @@ -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 +}); diff --git a/test/built-ins/WeakRef/prototype/deref/return-target.js b/test/built-ins/WeakRef/prototype/deref/return-target.js new file mode 100644 index 0000000000..19bb5e6204 --- /dev/null +++ b/test/built-ins/WeakRef/prototype/deref/return-target.js @@ -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'); diff --git a/test/built-ins/WeakRef/prototype/deref/this-does-not-have-internal-target-throws.js b/test/built-ins/WeakRef/prototype/deref/this-does-not-have-internal-target-throws.js new file mode 100644 index 0000000000..adc9020dff --- /dev/null +++ b/test/built-ins/WeakRef/prototype/deref/this-does-not-have-internal-target-throws.js @@ -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'); diff --git a/test/built-ins/WeakRef/prototype/deref/this-not-object-throws.js b/test/built-ins/WeakRef/prototype/deref/this-not-object-throws.js new file mode 100644 index 0000000000..cee1e70baf --- /dev/null +++ b/test/built-ins/WeakRef/prototype/deref/this-not-object-throws.js @@ -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'); diff --git a/test/built-ins/WeakRef/returns-new-object-from-constructor.js b/test/built-ins/WeakRef/returns-new-object-from-constructor.js new file mode 100644 index 0000000000..9e52f88d6b --- /dev/null +++ b/test/built-ins/WeakRef/returns-new-object-from-constructor.js @@ -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); + +