From f554f68ae9c595b2880970ec87d4064844d614d6 Mon Sep 17 00:00:00 2001 From: jugglinmike <mike@mikepennisi.com> Date: Tue, 5 Jul 2016 17:04:31 -0400 Subject: [PATCH] Improve coverage for section 21: String (#712) This changeset increases coverage for section 21, specifically "21.1 String Objects". * Add tests for "this" validation of String methods * Add tests for ToNumber as used by String methods * Add test for `length` prop of exotic String objs * fixup! Add test for `length` prop of exotic String objs --- test/built-ins/String/length.js | 29 ++++++++++++++++ .../String/prototype/charAt/pos-coerce-err.js | 21 ++++++++++++ .../prototype/charAt/pos-coerce-string.js | 17 ++++++++++ .../String/prototype/charAt/pos-rounding.js | 26 +++++++++++++++ .../charAt/this-value-not-obj-coercible.js | 21 ++++++++++++ .../prototype/charCodeAt/pos-coerce-err.js | 21 ++++++++++++ .../prototype/charCodeAt/pos-coerce-string.js | 19 +++++++++++ .../prototype/charCodeAt/pos-rounding.js | 29 ++++++++++++++++ .../this-value-not-obj-coercible.js | 21 ++++++++++++ .../concat/this-value-not-obj-coercible.js | 21 ++++++++++++ .../indexOf/this-value-not-obj-coercible.js | 21 ++++++++++++ .../this-value-not-obj-coercible.js | 21 ++++++++++++ .../this-value-not-obj-coercible.js | 21 ++++++++++++ .../match/this-value-not-obj-coercible.js | 21 ++++++++++++ .../replace/this-value-not-obj-coercible.js | 21 ++++++++++++ .../search/this-value-not-obj-coercible.js | 21 ++++++++++++ .../slice/this-value-not-obj-coercible.js | 21 ++++++++++++ .../split/this-value-not-obj-coercible.js | 21 ++++++++++++ .../substring/this-value-not-obj-coercible.js | 21 ++++++++++++ .../this-value-not-obj-coercible.js | 27 +++++++++++++++ .../this-value-not-obj-coercible.js | 33 +++++++++++++++++++ .../this-value-not-obj-coercible.js | 21 ++++++++++++ .../this-value-not-obj-coercible.js | 27 +++++++++++++++ 23 files changed, 522 insertions(+) create mode 100644 test/built-ins/String/length.js create mode 100644 test/built-ins/String/prototype/charAt/pos-coerce-err.js create mode 100644 test/built-ins/String/prototype/charAt/pos-coerce-string.js create mode 100644 test/built-ins/String/prototype/charAt/pos-rounding.js create mode 100644 test/built-ins/String/prototype/charAt/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/charCodeAt/pos-coerce-err.js create mode 100644 test/built-ins/String/prototype/charCodeAt/pos-coerce-string.js create mode 100644 test/built-ins/String/prototype/charCodeAt/pos-rounding.js create mode 100644 test/built-ins/String/prototype/charCodeAt/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/concat/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/indexOf/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/lastIndexOf/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/localeCompare/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/match/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/replace/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/search/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/slice/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/split/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/substring/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/toLocaleLowerCase/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/toLocaleUpperCase/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/toLowerCase/this-value-not-obj-coercible.js create mode 100644 test/built-ins/String/prototype/toUpperCase/this-value-not-obj-coercible.js diff --git a/test/built-ins/String/length.js b/test/built-ins/String/length.js new file mode 100644 index 0000000000..839a7cdf8e --- /dev/null +++ b/test/built-ins/String/length.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-properties-of-string-instances-length +es6id: 21.1.4.1 +description: The "length" property of String objects +info: | + [...] + 4. Return ? StringCreate(s, ? GetPrototypeFromConstructor(NewTarget, + "%StringPrototype%")). +includes: [propertyHelper.js] +---*/ + +var str = new String(''); + +verifyNotEnumerable(str, 'length'); +verifyNotWritable(str, 'length'); +verifyNotConfigurable(str, 'length'); + +assert.sameValue(str.length, 0, 'empty string'); + +str = new String(' '); +assert.sameValue(str.length, 1, 'whitespace'); + +str = new String(' \b '); +assert.sameValue(str.length, 3, 'character escape (U+008, "backspace")'); + +str = new String('\ud834\udf06'); +assert.sameValue(str.length, 2, 'Unicode escape (surrogate pair)'); diff --git a/test/built-ins/String/prototype/charAt/pos-coerce-err.js b/test/built-ins/String/prototype/charAt/pos-coerce-err.js new file mode 100644 index 0000000000..a1c48a00e3 --- /dev/null +++ b/test/built-ins/String/prototype/charAt/pos-coerce-err.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.charat +es6id: 21.1.3.1 +description: Error when attempting to coerce providec "pos" to a Number +info: | + [...] + 3. Let position be ? ToInteger(pos). + [...] + + 7.1.4 ToInteger + + 1. Let number be ? ToNumber(argument). +---*/ + +var noCoerce = Object.create(null); + +assert.throws(TypeError, function() { + ''.charAt(noCoerce); +}); diff --git a/test/built-ins/String/prototype/charAt/pos-coerce-string.js b/test/built-ins/String/prototype/charAt/pos-coerce-string.js new file mode 100644 index 0000000000..53825a15a0 --- /dev/null +++ b/test/built-ins/String/prototype/charAt/pos-coerce-string.js @@ -0,0 +1,17 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.charat +es6id: 21.1.3.1 +description: Coercion of "pos" string value into number +info: | + [...] + 3. Let position be ? ToInteger(pos). + [...] + + 7.1.4 ToInteger + + 1. Let number be ? ToNumber(argument). +---*/ + +assert.sameValue('abcd'.charAt(' +00200.0000E-0002 '), 'c'); diff --git a/test/built-ins/String/prototype/charAt/pos-rounding.js b/test/built-ins/String/prototype/charAt/pos-rounding.js new file mode 100644 index 0000000000..10615e2e7b --- /dev/null +++ b/test/built-ins/String/prototype/charAt/pos-rounding.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.charat +es6id: 21.1.3.1 +description: Rounding of the provided "pos" number +info: | + [...] + 3. Let position be ? ToInteger(pos). + [...] + + 7.1.4 ToInteger + + 1. Let number be ? ToNumber(argument). + 2. If number is NaN, return +0. + 3. If number is +0, -0, +∞, or -∞, return number. + 4. Return the number value that is the same sign as number and whose + magnitude is floor(abs(number)). +---*/ + +assert.sameValue('abc'.charAt(-0.99999), 'a', '-0.99999'); +assert.sameValue('abc'.charAt(-0.00001), 'a', '-0.00001'); +assert.sameValue('abc'.charAt(0.00001), 'a', '0.00001'); +assert.sameValue('abc'.charAt(0.99999), 'a', '0.99999'); +assert.sameValue('abc'.charAt(1.00001), 'b', '1.00001'); +assert.sameValue('abc'.charAt(1.99999), 'b', '1.99999'); diff --git a/test/built-ins/String/prototype/charAt/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/charAt/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..46029419c5 --- /dev/null +++ b/test/built-ins/String/prototype/charAt/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.charat +es6id: 21.1.3.1 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var charAt = String.prototype.charAt; + +assert.sameValue(typeof charAt, 'function'); + +assert.throws(TypeError, function() { + charAt.call(undefined, 0); +}, 'undefined'); + +assert.throws(TypeError, function() { + charAt.call(null, 0); +}, 'null'); diff --git a/test/built-ins/String/prototype/charCodeAt/pos-coerce-err.js b/test/built-ins/String/prototype/charCodeAt/pos-coerce-err.js new file mode 100644 index 0000000000..801a8baaa6 --- /dev/null +++ b/test/built-ins/String/prototype/charCodeAt/pos-coerce-err.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.charcodeat +es6id: 21.1.3.2 +description: Error when attempting to coerce providec "pos" to a Number +info: | + [...] + 3. Let position be ? ToInteger(pos). + [...] + + 7.1.4 ToInteger + + 1. Let number be ? ToNumber(argument). +---*/ + +var noCoerce = Object.create(null); + +assert.throws(TypeError, function() { + ''.charCodeAt(noCoerce); +}); diff --git a/test/built-ins/String/prototype/charCodeAt/pos-coerce-string.js b/test/built-ins/String/prototype/charCodeAt/pos-coerce-string.js new file mode 100644 index 0000000000..9d11a7f46a --- /dev/null +++ b/test/built-ins/String/prototype/charCodeAt/pos-coerce-string.js @@ -0,0 +1,19 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.charcodeat +es6id: 21.1.3.2 +description: Coercion of "pos" string value into number +info: | + [...] + 3. Let position be ? ToInteger(pos). + [...] + + 7.1.4 ToInteger + + 1. Let number be ? ToNumber(argument). +---*/ + +var cCode = 99; + +assert.sameValue('abcd'.charCodeAt(' +00200.0000E-0002 '), cCode); diff --git a/test/built-ins/String/prototype/charCodeAt/pos-rounding.js b/test/built-ins/String/prototype/charCodeAt/pos-rounding.js new file mode 100644 index 0000000000..32bd2ac7a6 --- /dev/null +++ b/test/built-ins/String/prototype/charCodeAt/pos-rounding.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.charcodeat +es6id: 21.1.3.2 +description: Rounding of the provided "pos" number +info: | + [...] + 3. Let position be ? ToInteger(pos). + [...] + + 7.1.4 ToInteger + + 1. Let number be ? ToNumber(argument). + 2. If number is NaN, return +0. + 3. If number is +0, -0, +∞, or -∞, return number. + 4. Return the number value that is the same sign as number and whose + magnitude is floor(abs(number)). +---*/ + +var aCode = 97; +var bCode = 98; + +assert.sameValue('abc'.charCodeAt(-0.99999), aCode, '-0.99999'); +assert.sameValue('abc'.charCodeAt(-0.00001), aCode, '-0.00001'); +assert.sameValue('abc'.charCodeAt(0.00001), aCode, '0.00001'); +assert.sameValue('abc'.charCodeAt(0.99999), aCode, '0.99999'); +assert.sameValue('abc'.charCodeAt(1.00001), bCode, '1.00001'); +assert.sameValue('abc'.charCodeAt(1.99999), bCode, '1.99999'); diff --git a/test/built-ins/String/prototype/charCodeAt/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/charCodeAt/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..1ec966f79f --- /dev/null +++ b/test/built-ins/String/prototype/charCodeAt/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.charcodeat +es6id: 21.1.3.2 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var charCodeAt = String.prototype.charCodeAt; + +assert.sameValue(typeof charCodeAt, 'function'); + +assert.throws(TypeError, function() { + charCodeAt.call(undefined, 0); +}, 'undefined'); + +assert.throws(TypeError, function() { + charCodeAt.call(null, 0); +}, 'null'); diff --git a/test/built-ins/String/prototype/concat/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/concat/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..23901e886c --- /dev/null +++ b/test/built-ins/String/prototype/concat/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.concat +es6id: 21.1.3.4 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var concat = String.prototype.concat; + +assert.sameValue(typeof concat, 'function'); + +assert.throws(TypeError, function() { + concat.call(undefined, ''); +}, 'undefined'); + +assert.throws(TypeError, function() { + concat.call(null, ''); +}, 'null'); diff --git a/test/built-ins/String/prototype/indexOf/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/indexOf/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..4efca6cffe --- /dev/null +++ b/test/built-ins/String/prototype/indexOf/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.indexof +es6id: 21.1.3.8 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var indexOf = String.prototype.indexOf; + +assert.sameValue(typeof indexOf, 'function'); + +assert.throws(TypeError, function() { + indexOf.call(undefined, ''); +}, 'undefined'); + +assert.throws(TypeError, function() { + indexOf.call(null, ''); +}, 'null'); diff --git a/test/built-ins/String/prototype/lastIndexOf/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/lastIndexOf/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..4eae545b44 --- /dev/null +++ b/test/built-ins/String/prototype/lastIndexOf/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.lastindexof +es6id: 21.1.3.9 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var lastIndexOf = String.prototype.lastIndexOf; + +assert.sameValue(typeof lastIndexOf, 'function'); + +assert.throws(TypeError, function() { + lastIndexOf.call(undefined, ''); +}, 'undefined'); + +assert.throws(TypeError, function() { + lastIndexOf.call(null, ''); +}, 'null'); diff --git a/test/built-ins/String/prototype/localeCompare/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/localeCompare/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..7adac196a5 --- /dev/null +++ b/test/built-ins/String/prototype/localeCompare/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.localecompare +es6id: 21.1.3.10 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var localeCompare = String.prototype.localeCompare; + +assert.sameValue(typeof localeCompare, 'function'); + +assert.throws(TypeError, function() { + localeCompare.call(undefined, ''); +}, 'undefined'); + +assert.throws(TypeError, function() { + localeCompare.call(null, ''); +}, 'null'); diff --git a/test/built-ins/String/prototype/match/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/match/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..e7e9fac2f0 --- /dev/null +++ b/test/built-ins/String/prototype/match/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.match +es6id: 21.1.3.11 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var match = String.prototype.match; + +assert.sameValue(typeof match, 'function'); + +assert.throws(TypeError, function() { + match.call(undefined, /./); +}, 'undefined'); + +assert.throws(TypeError, function() { + match.call(null, /./); +}, 'null'); diff --git a/test/built-ins/String/prototype/replace/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/replace/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..858dce314e --- /dev/null +++ b/test/built-ins/String/prototype/replace/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.replace +es6id: 21.1.3.14 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var replace = String.prototype.replace; + +assert.sameValue(typeof replace, 'function'); + +assert.throws(TypeError, function() { + replace.call(undefined, '', ''); +}, 'undefined'); + +assert.throws(TypeError, function() { + replace.call(null, '', ''); +}, 'null'); diff --git a/test/built-ins/String/prototype/search/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/search/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..461a347cac --- /dev/null +++ b/test/built-ins/String/prototype/search/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.search +es6id: 21.1.3.15 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var search = String.prototype.search; + +assert.sameValue(typeof search, 'function'); + +assert.throws(TypeError, function() { + search.call(undefined, /./); +}, 'undefined'); + +assert.throws(TypeError, function() { + search.call(null, /./); +}, 'null'); diff --git a/test/built-ins/String/prototype/slice/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/slice/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..b80ffd81ee --- /dev/null +++ b/test/built-ins/String/prototype/slice/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.slice +es6id: 21.1.3.16 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var slice = String.prototype.slice; + +assert.sameValue(typeof slice, 'function'); + +assert.throws(TypeError, function() { + slice.call(undefined, 0); +}, 'undefined'); + +assert.throws(TypeError, function() { + slice.call(null, 0); +}, 'null'); diff --git a/test/built-ins/String/prototype/split/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/split/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..f769cb747c --- /dev/null +++ b/test/built-ins/String/prototype/split/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.split +es6id: 21.1.3.17 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var split = String.prototype.split; + +assert.sameValue(typeof split, 'function'); + +assert.throws(TypeError, function() { + split.call(undefined, ''); +}, 'undefined'); + +assert.throws(TypeError, function() { + split.call(null, ''); +}, 'null'); diff --git a/test/built-ins/String/prototype/substring/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/substring/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..b10927b819 --- /dev/null +++ b/test/built-ins/String/prototype/substring/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.substring +es6id: 21.1.3.19 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var substring = String.prototype.substring; + +assert.sameValue(typeof substring, 'function'); + +assert.throws(TypeError, function() { + substring.call(undefined, 0, 1); +}, 'undefined'); + +assert.throws(TypeError, function() { + substring.call(null, 0, 1); +}, 'null'); diff --git a/test/built-ins/String/prototype/toLocaleLowerCase/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/toLocaleLowerCase/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..e058b14f32 --- /dev/null +++ b/test/built-ins/String/prototype/toLocaleLowerCase/this-value-not-obj-coercible.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.tolocalelowercase +es6id: 21.1.3.20 +description: The "this" value must be object-coercible +info: | + This function works exactly the same as toLowerCase except that its result is + intended to yield the correct result for the host environment's current + locale, rather than a locale-independent result. + + 21.1.3.24 String.prototype.toLowerCase + + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var toLocaleLowerCase = String.prototype.toLocaleLowerCase; + +assert.sameValue(typeof toLocaleLowerCase, 'function'); + +assert.throws(TypeError, function() { + toLocaleLowerCase.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + toLocaleLowerCase.call(null); +}, 'null'); diff --git a/test/built-ins/String/prototype/toLocaleUpperCase/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/toLocaleUpperCase/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..fb9d816fec --- /dev/null +++ b/test/built-ins/String/prototype/toLocaleUpperCase/this-value-not-obj-coercible.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.tolocaleuppercase +es6id: 21.1.3.21 +description: The "this" value must be object-coercible +info: | + This function works exactly the same as toUpperCase except that its result is + intended to yield the correct result for the host environment's current + locale, rather than a locale-independent result. + + 21.1.3.26 String.prototype.toUpperCase + + This function behaves in exactly the same way as + String.prototype.toLowerCase, except that code points are mapped to their + uppercase equivalents as specified in the Unicode Character Database. + + 21.1.3.24 String.prototype.toLowerCase + + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var toLocaleUpperCase = String.prototype.toLocaleUpperCase; + +assert.sameValue(typeof toLocaleUpperCase, 'function'); + +assert.throws(TypeError, function() { + toLocaleUpperCase.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + toLocaleUpperCase.call(null); +}, 'null'); diff --git a/test/built-ins/String/prototype/toLowerCase/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/toLowerCase/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..17638ca4e9 --- /dev/null +++ b/test/built-ins/String/prototype/toLowerCase/this-value-not-obj-coercible.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.tolowercase +es6id: 21.1.3.22 +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var toLowerCase = String.prototype.toLowerCase; + +assert.sameValue(typeof toLowerCase, 'function'); + +assert.throws(TypeError, function() { + toLowerCase.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + toLowerCase.call(null); +}, 'null'); diff --git a/test/built-ins/String/prototype/toUpperCase/this-value-not-obj-coercible.js b/test/built-ins/String/prototype/toUpperCase/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..757aa5d57e --- /dev/null +++ b/test/built-ins/String/prototype/toUpperCase/this-value-not-obj-coercible.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.touppercase +es6id: 21.1.3.24 +description: The "this" value must be object-coercible +info: | + This function behaves in exactly the same way as + String.prototype.toLowerCase, except that code points are mapped to their + uppercase equivalents as specified in the Unicode Character Database. + + 21.1.3.24 String.prototype.toLowerCase + + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var toUpperCase = String.prototype.toUpperCase; + +assert.sameValue(typeof toUpperCase, 'function'); + +assert.throws(TypeError, function() { + toUpperCase.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + toUpperCase.call(null); +}, 'null'); -- GitLab