From cc53f64325599bf0c583dd034b762282b9485976 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 7 Jun 2018 21:39:02 +0800 Subject: [PATCH 1/3] Add tests for Symbol.prototype.description --- features.txt | 4 ++ .../prototype/description/descriptor.js | 19 +++++++++ .../Symbol/prototype/description/get.js | 21 ++++++++++ .../description/this-val-non-symbol.js | 42 +++++++++++++++++++ .../Symbol/prototype/description/wrapper.js | 21 ++++++++++ 5 files changed, 107 insertions(+) create mode 100644 test/built-ins/Symbol/prototype/description/descriptor.js create mode 100644 test/built-ins/Symbol/prototype/description/get.js create mode 100644 test/built-ins/Symbol/prototype/description/this-val-non-symbol.js create mode 100644 test/built-ins/Symbol/prototype/description/wrapper.js diff --git a/features.txt b/features.txt index 257f379ee65..a0b1565d3d4 100644 --- a/features.txt +++ b/features.txt @@ -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 diff --git a/test/built-ins/Symbol/prototype/description/descriptor.js b/test/built-ins/Symbol/prototype/description/descriptor.js new file mode 100644 index 00000000000..0b3d2db3c32 --- /dev/null +++ b/test/built-ins/Symbol/prototype/description/descriptor.js @@ -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); +assert.sameValue(desc.enumerable, false); +assert.sameValue(desc.configurable, true); diff --git a/test/built-ins/Symbol/prototype/description/get.js b/test/built-ins/Symbol/prototype/description/get.js new file mode 100644 index 00000000000..64c18dced0f --- /dev/null +++ b/test/built-ins/Symbol/prototype/description/get.js @@ -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(); +assert.sameValue(empty.description, undefined); +assert.sameValue(empty.hasOwnProperty('description'), false); diff --git a/test/built-ins/Symbol/prototype/description/this-val-non-symbol.js b/test/built-ins/Symbol/prototype/description/this-val-non-symbol.js new file mode 100644 index 00000000000..89e222d444d --- /dev/null +++ b/test/built-ins/Symbol/prototype/description/this-val-non-symbol.js @@ -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); +}); + +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({}); +}); diff --git a/test/built-ins/Symbol/prototype/description/wrapper.js b/test/built-ins/Symbol/prototype/description/wrapper.js new file mode 100644 index 00000000000..4acb78fe6ab --- /dev/null +++ b/test/built-ins/Symbol/prototype/description/wrapper.js @@ -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); From 28a66ceb75b5b4061e10c23437c985247c49659c Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 8 Jun 2018 04:54:24 +0800 Subject: [PATCH 2/3] Use propertyHelper, add more tests, fix getter calls --- .../Symbol/prototype/description/descriptor.js | 14 ++++++++++---- .../Symbol/prototype/description/get.js | 8 ++++++++ .../description/this-val-non-symbol.js | 18 +++++++++++------- .../Symbol/prototype/description/wrapper.js | 8 ++++++++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/test/built-ins/Symbol/prototype/description/descriptor.js b/test/built-ins/Symbol/prototype/description/descriptor.js index 0b3d2db3c32..bc66519624d 100644 --- a/test/built-ins/Symbol/prototype/description/descriptor.js +++ b/test/built-ins/Symbol/prototype/description/descriptor.js @@ -8,12 +8,18 @@ description: > info: | `Symbol.prototype.description` is an accessor property whose set accessor function is undefined. +includes: [propertyHelper.js] 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.writable, undefined); -assert.sameValue(desc.enumerable, false); -assert.sameValue(desc.configurable, true); +assert.sameValue(typeof desc.get, 'function'); + +verifyProperty(Symbol.prototype, 'description', { + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/Symbol/prototype/description/get.js b/test/built-ins/Symbol/prototype/description/get.js index 64c18dced0f..54c0fb06b24 100644 --- a/test/built-ins/Symbol/prototype/description/get.js +++ b/test/built-ins/Symbol/prototype/description/get.js @@ -19,3 +19,11 @@ assert.sameValue(symbol.hasOwnProperty('description'), false); const empty = Symbol(); assert.sameValue(empty.description, undefined); 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); diff --git a/test/built-ins/Symbol/prototype/description/this-val-non-symbol.js b/test/built-ins/Symbol/prototype/description/this-val-non-symbol.js index 89e222d444d..0d2fc40b183 100644 --- a/test/built-ins/Symbol/prototype/description/this-val-non-symbol.js +++ b/test/built-ins/Symbol/prototype/description/this-val-non-symbol.js @@ -13,30 +13,34 @@ info: | features: [Symbol.prototype.description] ---*/ +const getter = Object.getOwnPropertyDescriptor( + Symbol.prototype, 'description' +).get; + assert.throws(TypeError, function() { - Symbol.prototype.description.call(null); + getter.call(null); }); assert.throws(TypeError, function() { - Symbol.prototype.description.call(123); + getter.call(123); }); assert.throws(TypeError, function() { - Symbol.prototype.description.call('test'); + getter.call('test'); }); assert.throws(TypeError, function() { - Symbol.prototype.description.call(true); + getter.call(true); }); assert.throws(TypeError, function() { - Symbol.prototype.description.call(undefined); + getter.call(undefined); }); assert.throws(TypeError, function() { - Symbol.prototype.description.call(new Proxy({}, {})); + getter.call(new Proxy({}, {})); }); assert.throws(TypeError, function() { - Symbol.prototype.description.call({}); + getter.call({}); }); diff --git a/test/built-ins/Symbol/prototype/description/wrapper.js b/test/built-ins/Symbol/prototype/description/wrapper.js index 4acb78fe6ab..c117f1b73c6 100644 --- a/test/built-ins/Symbol/prototype/description/wrapper.js +++ b/test/built-ins/Symbol/prototype/description/wrapper.js @@ -19,3 +19,11 @@ assert.sameValue(symbol.hasOwnProperty('description'), false); const empty = Object(Symbol()); assert.sameValue(empty.description, undefined); 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); From 70b97383a8a6cc7f3d837fac769463742fbb7cfa Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 8 Jun 2018 05:35:45 +0800 Subject: [PATCH 3/3] test getter on symbols and wrapper objects --- .../prototype/description/this-val-symbol.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/built-ins/Symbol/prototype/description/this-val-symbol.js diff --git a/test/built-ins/Symbol/prototype/description/this-val-symbol.js b/test/built-ins/Symbol/prototype/description/this-val-symbol.js new file mode 100644 index 00000000000..604e4e47ea0 --- /dev/null +++ b/test/built-ins/Symbol/prototype/description/this-val-symbol.js @@ -0,0 +1,33 @@ +// 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 that calling the getter on a Symbol or a Symbol wrapper object works. +info: | + 1. Let s be the this value. + 2. Let sym be ? thisSymbolValue(s). + 3. Return sym.[[Description]]. +features: [Symbol.prototype.description] +---*/ + +const getter = Object.getOwnPropertyDescriptor( + Symbol.prototype, 'description' +).get; + +const symbol = Symbol('test'); +assert.sameValue(getter.call(symbol), 'test'); +assert.sameValue(getter.call(Object(symbol)), 'test'); + +const empty = Symbol(); +assert.sameValue(getter.call(empty), undefined); +assert.sameValue(getter.call(Object(empty)), undefined); + +const undef = Symbol(undefined); +assert.sameValue(getter.call(undef), undefined); +assert.sameValue(getter.call(Object(undef)), undefined); + +const emptyStr = Symbol(''); +assert.sameValue(getter.call(emptyStr), ''); +assert.sameValue(getter.call(Object(emptyStr)), '');