Use propertyHelper, add more tests, fix getter calls

This commit is contained in:
Joyee Cheung 2018-06-08 04:54:24 +08:00
parent cc53f64325
commit 28a66ceb75
No known key found for this signature in database
GPG Key ID: 92B78A53C8303B8D
4 changed files with 37 additions and 11 deletions

View File

@ -8,12 +8,18 @@ description: >
info: | info: |
`Symbol.prototype.description` is an accessor property whose `Symbol.prototype.description` is an accessor property whose
set accessor function is undefined. set accessor function is undefined.
includes: [propertyHelper.js]
features: [Symbol.prototype.description] features: [Symbol.prototype.description]
---*/ ---*/
const desc = Object.getOwnPropertyDescriptor(Symbol.prototype, 'description');
assert.sameValue(typeof desc.get, 'function'); var desc = Object.getOwnPropertyDescriptor(Symbol.prototype, 'description');
assert.sameValue(desc.set, undefined); assert.sameValue(desc.set, undefined);
assert.sameValue(desc.writable, undefined); assert.sameValue(desc.writable, undefined);
assert.sameValue(desc.enumerable, false); assert.sameValue(typeof desc.get, 'function');
assert.sameValue(desc.configurable, true);
verifyProperty(Symbol.prototype, 'description', {
enumerable: false,
configurable: true,
});

View File

@ -19,3 +19,11 @@ assert.sameValue(symbol.hasOwnProperty('description'), false);
const empty = Symbol(); const empty = Symbol();
assert.sameValue(empty.description, undefined); assert.sameValue(empty.description, undefined);
assert.sameValue(empty.hasOwnProperty('description'), false); assert.sameValue(empty.hasOwnProperty('description'), false);
const undef = Symbol(undefined);
assert.sameValue(undef.description, undefined);
assert.sameValue(undef.hasOwnProperty('description'), false);
const emptyStr = Symbol('');
assert.sameValue(emptyStr.description, '');
assert.sameValue(emptyStr.hasOwnProperty('description'), false);

View File

@ -13,30 +13,34 @@ info: |
features: [Symbol.prototype.description] features: [Symbol.prototype.description]
---*/ ---*/
const getter = Object.getOwnPropertyDescriptor(
Symbol.prototype, 'description'
).get;
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Symbol.prototype.description.call(null); getter.call(null);
}); });
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Symbol.prototype.description.call(123); getter.call(123);
}); });
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Symbol.prototype.description.call('test'); getter.call('test');
}); });
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Symbol.prototype.description.call(true); getter.call(true);
}); });
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Symbol.prototype.description.call(undefined); getter.call(undefined);
}); });
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Symbol.prototype.description.call(new Proxy({}, {})); getter.call(new Proxy({}, {}));
}); });
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Symbol.prototype.description.call({}); getter.call({});
}); });

View File

@ -19,3 +19,11 @@ assert.sameValue(symbol.hasOwnProperty('description'), false);
const empty = Object(Symbol()); const empty = Object(Symbol());
assert.sameValue(empty.description, undefined); assert.sameValue(empty.description, undefined);
assert.sameValue(empty.hasOwnProperty('description'), false); assert.sameValue(empty.hasOwnProperty('description'), false);
const undef = Object(Symbol(undefined));
assert.sameValue(undef.description, undefined);
assert.sameValue(undef.hasOwnProperty('description'), false);
const emptyStr = Object(Symbol(''));
assert.sameValue(emptyStr.description, '');
assert.sameValue(emptyStr.hasOwnProperty('description'), false);