Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Symbol.prototype.description #1590

Merged
merged 3 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ numeric-separator-literal
String.prototype.matchAll
Symbol.matchAll

# Symbol.prototype.description
# https://github.com/tc39/proposal-symbol-description
Symbol.prototype.description

# ECMAScript ⊃ JSON
# https://github.com/tc39/proposal-json-superset
json-superset
Expand Down
19 changes: 19 additions & 0 deletions test/built-ins/Symbol/prototype/description/descriptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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: >
Test the descriptor of Symbol.prototype.description.
info: |
`Symbol.prototype.description` is an accessor property whose
set accessor function is undefined.
features: [Symbol.prototype.description]
---*/

const desc = Object.getOwnPropertyDescriptor(Symbol.prototype, 'description');
assert.sameValue(typeof desc.get, 'function');
assert.sameValue(desc.set, undefined);
assert.sameValue(desc.writable, undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s a propertyHelper that could be used here

assert.sameValue(desc.enumerable, false);
assert.sameValue(desc.configurable, true);
21 changes: 21 additions & 0 deletions test/built-ins/Symbol/prototype/description/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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: >
Test the get accessor function of Symbol.prototype.description.
info: |
1. Let s be the this value.
2. Let sym be ? thisSymbolValue(s).
3. Return sym.[[Description]].
features: [Symbol.prototype.description]
---*/

const symbol = Symbol('test');
assert.sameValue(symbol.description, 'test');
assert.sameValue(symbol.hasOwnProperty('description'), false);

const empty = Symbol();

This comment was marked as resolved.

assert.sameValue(empty.description, undefined);
assert.sameValue(empty.hasOwnProperty('description'), false);
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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: >
Behavior when `this` value is an object without a [[SymbolData]] internal
slot.
info: |
1. Let s be the this value.
2. Let sym be ? thisSymbolValue(s).
3. Return sym.[[Description]].
features: [Symbol.prototype.description]
---*/

assert.throws(TypeError, function() {
Symbol.prototype.description.call(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails, but for the wrong reason. The getter is being called on Symbol.prototype. You should instead extract the getter with Object.getOwnPropertyDescriptor.

});

assert.throws(TypeError, function() {
Symbol.prototype.description.call(123);
});

assert.throws(TypeError, function() {
Symbol.prototype.description.call('test');
});

assert.throws(TypeError, function() {
Symbol.prototype.description.call(true);
});

assert.throws(TypeError, function() {
Symbol.prototype.description.call(undefined);
});

assert.throws(TypeError, function() {
Symbol.prototype.description.call(new Proxy({}, {}));
});

assert.throws(TypeError, function() {
Symbol.prototype.description.call({});
});
21 changes: 21 additions & 0 deletions test/built-ins/Symbol/prototype/description/wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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: >
Test Symbol.prototype.description called on wrapper objects.
info: |
1. Let s be the this value.
2. Let sym be ? thisSymbolValue(s).
3. Return sym.[[Description]].
features: [Symbol.prototype.description]
---*/

const symbol = Object(Symbol('test'));
assert.sameValue(symbol.description, 'test');
assert.sameValue(symbol.hasOwnProperty('description'), false);

const empty = Object(Symbol());
assert.sameValue(empty.description, undefined);
assert.sameValue(empty.hasOwnProperty('description'), false);