Symbol.prototype.description: Assertion messages and additional tests

This commit is contained in:
Rick Waldron 2018-06-07 22:08:52 -04:00
parent 5d58479827
commit cd4371b5a7
7 changed files with 151 additions and 35 deletions

View File

@ -0,0 +1,32 @@
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// Copyright (C) 2018 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-symbol.prototype.description
description: >
SymbolDescriptiveString(sym) via Symbol.prototype.toString()
info: |
SymbolDescriptiveString ( sym )
Assert: Type(sym) is Symbol.
Let desc be sym's [[Description]] value.
If desc is undefined, let desc be the empty string.
Assert: Type(desc) is String.
Return the string-concatenation of "Symbol(", desc, and ")".
includes: [propertyHelper.js]
features: [Symbol.prototype.description]
---*/
const symbol = Symbol('foo');
assert.sameValue(
symbol.description,
'foo',
'The value of symbol.description is "foo"'
);
assert.sameValue(
symbol.toString(),
`Symbol(${symbol.description})`,
`symbol.toString() returns "Symbol(${symbol.description})"`
);

View File

@ -15,9 +15,23 @@ features: [Symbol.prototype.description]
var desc = Object.getOwnPropertyDescriptor(Symbol.prototype, 'description');
assert.sameValue(desc.set, undefined);
assert.sameValue(desc.writable, undefined);
assert.sameValue(typeof desc.get, 'function');
assert.sameValue(
desc.set,
undefined,
'The value of desc.set is `undefined`'
);
assert.sameValue(
desc.writable,
undefined,
'The value of desc.writable is `undefined`'
);
assert.sameValue(
typeof desc.get,
'function',
'The value of `typeof desc.get` is "function"'
);
verifyProperty(Symbol.prototype, 'description', {
enumerable: false,

View File

@ -13,17 +13,29 @@ features: [Symbol.prototype.description]
---*/
const symbol = Symbol('test');
assert.sameValue(symbol.description, 'test');
assert.sameValue(symbol.hasOwnProperty('description'), false);
assert.sameValue(
symbol.description,
'test',
'The value of symbol.description is "test"'
);
const empty = Symbol();
assert.sameValue(empty.description, undefined);
assert.sameValue(empty.hasOwnProperty('description'), false);
assert.sameValue(
empty.description,
undefined,
'The value of empty.description is `undefined`'
);
const undef = Symbol(undefined);
assert.sameValue(undef.description, undefined);
assert.sameValue(undef.hasOwnProperty('description'), false);
assert.sameValue(
undef.description,
undefined,
'The value of undef.description is `undefined`'
);
const emptyStr = Symbol('');
assert.sameValue(emptyStr.description, '');
assert.sameValue(emptyStr.hasOwnProperty('description'), false);
assert.sameValue(
emptyStr.description,
'',
'The value of emptyStr.description is ""'
);

View File

@ -0,0 +1,14 @@
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-symbol.prototype.description
description: Ensure that 'description' is not an own property of Symbols
features: [Symbol.prototype.description]
---*/
assert.sameValue(
Symbol().hasOwnProperty('description'),
false,
'Symbol().hasOwnProperty("description") returns false'
);

View File

@ -4,7 +4,7 @@
/*---
esid: sec-symbol.prototype.description
description: >
Behavior when `this` value is an object without a [[SymbolData]] internal
Behavior when "this" value is an object without a [[SymbolData]] internal
slot.
info: |
1. Let s be the this value.
@ -19,28 +19,28 @@ const getter = Object.getOwnPropertyDescriptor(
assert.throws(TypeError, function() {
getter.call(null);
});
}, 'getter.call(null) throws TypeError');
assert.throws(TypeError, function() {
getter.call(123);
});
}, 'getter.call(123) throws TypeError');
assert.throws(TypeError, function() {
getter.call('test');
});
}, 'getter.call("test") throws TypeError');
assert.throws(TypeError, function() {
getter.call(true);
});
}, 'getter.call(true) throws TypeError');
assert.throws(TypeError, function() {
getter.call(undefined);
});
}, 'getter.call(undefined) throws TypeError');
assert.throws(TypeError, function() {
getter.call(new Proxy({}, {}));
});
}, 'getter.call(new Proxy({}, {})) throws TypeError');
assert.throws(TypeError, function() {
getter.call({});
});
}, 'getter.call({}) throws TypeError');

View File

@ -17,17 +17,49 @@ const getter = Object.getOwnPropertyDescriptor(
).get;
const symbol = Symbol('test');
assert.sameValue(getter.call(symbol), 'test');
assert.sameValue(getter.call(Object(symbol)), 'test');
assert.sameValue(
getter.call(symbol),
'test',
'getter.call(symbol) returns "test"'
);
assert.sameValue(
getter.call(Object(symbol)),
'test',
'getter.call(Object(symbol)) returns "test"'
);
const empty = Symbol();
assert.sameValue(getter.call(empty), undefined);
assert.sameValue(getter.call(Object(empty)), undefined);
assert.sameValue(
getter.call(empty),
undefined,
'getter.call(empty) returns `undefined`'
);
assert.sameValue(
getter.call(Object(empty)),
undefined,
'getter.call(Object(empty)) returns `undefined`'
);
const undef = Symbol(undefined);
assert.sameValue(getter.call(undef), undefined);
assert.sameValue(getter.call(Object(undef)), undefined);
assert.sameValue(
getter.call(undef),
undefined,
'getter.call(undef) returns `undefined`'
);
assert.sameValue(
getter.call(Object(undef)),
undefined,
'getter.call(Object(undef)) returns `undefined`'
);
const emptyStr = Symbol('');
assert.sameValue(getter.call(emptyStr), '');
assert.sameValue(getter.call(Object(emptyStr)), '');
assert.sameValue(
getter.call(emptyStr),
'',
'getter.call(emptyStr) returns ""'
);
assert.sameValue(
getter.call(Object(emptyStr)),
'',
'getter.call(Object(emptyStr)) returns ""'
);

View File

@ -13,17 +13,29 @@ features: [Symbol.prototype.description]
---*/
const symbol = Object(Symbol('test'));
assert.sameValue(symbol.description, 'test');
assert.sameValue(symbol.hasOwnProperty('description'), false);
assert.sameValue(
symbol.description,
'test',
'The value of symbol.description is "test"'
);
const empty = Object(Symbol());
assert.sameValue(empty.description, undefined);
assert.sameValue(empty.hasOwnProperty('description'), false);
assert.sameValue(
empty.description,
undefined,
'The value of empty.description is `undefined`'
);
const undef = Object(Symbol(undefined));
assert.sameValue(undef.description, undefined);
assert.sameValue(undef.hasOwnProperty('description'), false);
assert.sameValue(
undef.description,
undefined,
'The value of undef.description is `undefined`'
);
const emptyStr = Object(Symbol(''));
assert.sameValue(emptyStr.description, '');
assert.sameValue(emptyStr.hasOwnProperty('description'), false);
assert.sameValue(
emptyStr.description,
'',
'The value of emptyStr.description is ""'
);