Skip to content

Commit 29abe99

Browse files
JosephPecorarowebkit-commit-queue
authored andcommitted
Make builtin TypeErrors consistent
https://bugs.webkit.org/show_bug.cgi?id=159899 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-07-18 Reviewed by Keith Miller. Source/JavaScriptCore: Converge on the single TypeError for non-coercible this objects in builtins. Also update some other style to be more consistent with-in builtins. * builtins/ArrayIteratorPrototype.js: (next): * builtins/ArrayPrototype.js: (values): (keys): (entries): (reduce): (reduceRight): (every): (forEach): (filter): (map): (some): (fill): (find): (findIndex): (includes): (sort): (concatSlowPath): (copyWithin): * builtins/StringPrototype.js: (match): (repeat): (padStart): (padEnd): (intrinsic.StringPrototypeReplaceIntrinsic.replace): (localeCompare): (search): (split): * tests/es6/String.prototype_methods_String.prototype.padEnd.js: * tests/es6/String.prototype_methods_String.prototype.padStart.js: * tests/stress/array-iterators-next-error-messages.js: (catch): * tests/stress/array-iterators-next-with-call.js: * tests/stress/regexp-match.js: (shouldThrow): * tests/stress/regexp-search.js: (shouldThrow): LayoutTests: * js/array-find-expected.txt: * js/array-findIndex-expected.txt: * js/array-includes-expected.txt: * js/dom/array-prototype-properties-expected.txt: * js/dom/script-tests/string-prototype-properties.js: * js/dom/string-prototype-properties-expected.txt: * js/script-tests/array-find.js: * js/script-tests/array-findIndex.js: * js/script-tests/string-localeCompare.js: * js/string-localeCompare-expected.txt: * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.10_String.prototype.match/S15.5.4.10_A1_T3-expected.txt: * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.11_String.prototype.replace/S15.5.4.11_A1_T3-expected.txt: * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.12_String.prototype.search/S15.5.4.12_A1_T3-expected.txt: * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.14_String.prototype.split/S15.5.4.14_A1_T3-expected.txt: Canonical link: https://commits.webkit.org/178077@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@203393 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent b2c8ebc commit 29abe99

25 files changed

Lines changed: 193 additions & 191 deletions

LayoutTests/ChangeLog

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2016-07-18 Joseph Pecoraro <pecoraro@apple.com>
2+
3+
Make builtin TypeErrors consistent
4+
https://bugs.webkit.org/show_bug.cgi?id=159899
5+
6+
Reviewed by Keith Miller.
7+
8+
* js/array-find-expected.txt:
9+
* js/array-findIndex-expected.txt:
10+
* js/array-includes-expected.txt:
11+
* js/dom/array-prototype-properties-expected.txt:
12+
* js/dom/script-tests/string-prototype-properties.js:
13+
* js/dom/string-prototype-properties-expected.txt:
14+
* js/script-tests/array-find.js:
15+
* js/script-tests/array-findIndex.js:
16+
* js/script-tests/string-localeCompare.js:
17+
* js/string-localeCompare-expected.txt:
18+
* sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.10_String.prototype.match/S15.5.4.10_A1_T3-expected.txt:
19+
* sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.11_String.prototype.replace/S15.5.4.11_A1_T3-expected.txt:
20+
* sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.12_String.prototype.search/S15.5.4.12_A1_T3-expected.txt:
21+
* sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.14_String.prototype.split/S15.5.4.14_A1_T3-expected.txt:
22+
123
2016-07-18 Chris Dumez <cdumez@apple.com>
224

325
EventTarget.dispatchEvent() parameter should not be nullable

LayoutTests/js/array-find-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Modification during search
4242
PASS [0,1,2,3,4,5,6,7,8,9].find(findItemAddedDuringSearch) is undefined
4343
PASS [0,1,2,3,4,5,6,7,8,9].find(findItemRemovedDuringSearch) is undefined
4444
Exceptions
45-
PASS Array.prototype.find.call(undefined, function() {}) threw exception TypeError: Array.prototype.find requires that |this| not be undefined.
46-
PASS Array.prototype.find.call(null, function() {}) threw exception TypeError: Array.prototype.find requires that |this| not be null.
45+
PASS Array.prototype.find.call(undefined, function() {}) threw exception TypeError: Array.prototype.find requires that |this| not be null or undefined.
46+
PASS Array.prototype.find.call(null, function() {}) threw exception TypeError: Array.prototype.find requires that |this| not be null or undefined.
4747
PASS [].find(1) threw exception TypeError: Array.prototype.find callback must be a function.
4848
PASS [].find('hello') threw exception TypeError: Array.prototype.find callback must be a function.
4949
PASS [].find([]) threw exception TypeError: Array.prototype.find callback must be a function.

LayoutTests/js/array-findIndex-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ Modification during search
4343
PASS [0,1,2,3,4,5,6,7,8,9].findIndex(findItemAddedDuringSearch) is -1
4444
PASS [0,1,2,3,4,5,6,7,8,9].findIndex(findItemRemovedDuringSearch) is -1
4545
Exceptions
46-
PASS Array.prototype.findIndex.call(undefined, function() {}) threw exception TypeError: Array.prototype.findIndex requires that |this| not be undefined.
47-
PASS Array.prototype.findIndex.call(null, function() {}) threw exception TypeError: Array.prototype.findIndex requires that |this| not be null.
46+
PASS Array.prototype.findIndex.call(undefined, function() {}) threw exception TypeError: Array.prototype.findIndex requires that |this| not be null or undefined.
47+
PASS Array.prototype.findIndex.call(null, function() {}) threw exception TypeError: Array.prototype.findIndex requires that |this| not be null or undefined.
4848
PASS [].findIndex(1) threw exception TypeError: Array.prototype.findIndex callback must be a function.
4949
PASS [].findIndex('hello') threw exception TypeError: Array.prototype.findIndex callback must be a function.
5050
PASS [].findIndex([]) threw exception TypeError: Array.prototype.findIndex callback must be a function.

LayoutTests/js/array-includes-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ PASS a.includes('egg') is true
2828
PASS a.includes('sausage') is true
2929
PASS a.includes('hashbrown') is false
3030
PASS a.includes('toast') is false
31-
PASS Array.prototype.includes.call(undefined, 1) threw exception TypeError: Array.prototype.includes requires that |this| not be undefined.
32-
PASS Array.prototype.includes.call(null, 1) threw exception TypeError: Array.prototype.includes requires that |this| not be null.
31+
PASS Array.prototype.includes.call(undefined, 1) threw exception TypeError: Array.prototype.includes requires that |this| not be null or undefined.
32+
PASS Array.prototype.includes.call(null, 1) threw exception TypeError: Array.prototype.includes requires that |this| not be null or undefined.
3333
Array-like object with invalid lengths
3434
PASS var obj = { 0: 1, 1: 1, 2: 1, length: 0 }; Array.prototype.includes.call(obj, 1) is false
3535
PASS var obj = { 0: 1, 1: 1, 2: 1, length: -0 }; Array.prototype.includes.call(obj, 1) is false

LayoutTests/js/dom/array-prototype-properties-expected.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
55

66
PASS Array.prototype.toString.call(undefined) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.toString.call(undefined)').
77
PASS Array.prototype.toLocaleString.call(undefined) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.toLocaleString.call(undefined)').
8-
PASS Array.prototype.concat.call(undefined, []) threw exception TypeError: Array.prototype.concat requires that |this| not be undefined.
8+
PASS Array.prototype.concat.call(undefined, []) threw exception TypeError: Array.prototype.concat requires that |this| not be null or undefined.
99
PASS Array.prototype.join.call(undefined, []) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.join.call(undefined, [])').
1010
PASS Array.prototype.pop.call(undefined) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.pop.call(undefined)').
1111
PASS Array.prototype.push.call(undefined, {}) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.push.call(undefined, {})').
1212
PASS Array.prototype.reverse.call(undefined) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.reverse.call(undefined)').
1313
PASS Array.prototype.shift.call(undefined) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.shift.call(undefined)').
1414
PASS Array.prototype.slice.call(undefined, 0, 1) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.slice.call(undefined, 0, 1)').
15-
PASS Array.prototype.sort.call(undefined) threw exception TypeError: Array.prototype.sort requires that |this| not be undefined.
15+
PASS Array.prototype.sort.call(undefined) threw exception TypeError: Array.prototype.sort requires that |this| not be null or undefined.
1616
PASS Array.prototype.splice.call(undefined, 0, 1) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.splice.call(undefined, 0, 1)').
1717
PASS Array.prototype.unshift.call(undefined, {}) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.unshift.call(undefined, {})').
18-
PASS Array.prototype.every.call(undefined, toString) threw exception TypeError: Array.prototype.every requires that |this| not be undefined.
19-
PASS Array.prototype.forEach.call(undefined, toString) threw exception TypeError: Array.prototype.forEach requires that |this| not be undefined.
20-
PASS Array.prototype.some.call(undefined, toString) threw exception TypeError: Array.prototype.some requires that |this| not be undefined.
18+
PASS Array.prototype.every.call(undefined, toString) threw exception TypeError: Array.prototype.every requires that |this| not be null or undefined.
19+
PASS Array.prototype.forEach.call(undefined, toString) threw exception TypeError: Array.prototype.forEach requires that |this| not be null or undefined.
20+
PASS Array.prototype.some.call(undefined, toString) threw exception TypeError: Array.prototype.some requires that |this| not be null or undefined.
2121
PASS Array.prototype.indexOf.call(undefined, 0) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.indexOf.call(undefined, 0)').
2222
PASS Array.prototype.lastIndexOf.call(undefined, 0) threw exception TypeError: undefined is not an object (evaluating 'Array.prototype.lastIndexOf.call(undefined, 0)').
23-
PASS Array.prototype.filter.call(undefined, toString) threw exception TypeError: Array.prototype.filter requires that |this| not be undefined.
24-
PASS Array.prototype.reduce.call(undefined, toString) threw exception TypeError: Array.prototype.reduce requires that |this| not be undefined.
25-
PASS Array.prototype.reduceRight.call(undefined, toString) threw exception TypeError: Array.prototype.reduceRight requires that |this| not be undefined.
26-
PASS Array.prototype.map.call(undefined, toString) threw exception TypeError: Array.prototype.map requires that |this| not be undefined.
23+
PASS Array.prototype.filter.call(undefined, toString) threw exception TypeError: Array.prototype.filter requires that |this| not be null or undefined.
24+
PASS Array.prototype.reduce.call(undefined, toString) threw exception TypeError: Array.prototype.reduce requires that |this| not be null or undefined.
25+
PASS Array.prototype.reduceRight.call(undefined, toString) threw exception TypeError: Array.prototype.reduceRight requires that |this| not be null or undefined.
26+
PASS Array.prototype.map.call(undefined, toString) threw exception TypeError: Array.prototype.map requires that |this| not be null or undefined.
2727
PASS [{toLocaleString:function(){throw 1}},{toLocaleString:function(){throw 2}}].toLocaleString() threw exception 1.
2828
PASS successfullyParsed is true
2929

LayoutTests/js/dom/script-tests/string-prototype-properties.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ shouldThrow("String.prototype.substr.call(undefined, 1, 3)");
2020
shouldThrow("String.prototype.substring.call(undefined, 1, 3)");
2121
shouldThrow("String.prototype.toLowerCase.call(undefined)");
2222
shouldThrow("String.prototype.toUpperCase.call(undefined)");
23-
shouldThrow("String.prototype.localeCompare.call(undefined, '1224')", "'TypeError: String.prototype.localeCompare requires that |this| not be undefined'");
23+
shouldThrow("String.prototype.localeCompare.call(undefined, '1224')", "'TypeError: String.prototype.localeCompare requires that |this| not be null or undefined'");
2424
shouldThrow("String.prototype.toLocaleLowerCase.call(undefined)");
2525
shouldThrow("String.prototype.toLocaleUpperCase.call(undefined)");
2626
shouldThrow("String.prototype.trim.call(undefined)");

LayoutTests/js/dom/string-prototype-properties-expected.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ PASS String.prototype.charCodeAt.call(undefined, 0) threw exception TypeError: T
1010
PASS String.prototype.concat.call(undefined, 'five') threw exception TypeError: Type error.
1111
PASS String.prototype.indexOf.call(undefined, '2') threw exception TypeError: Type error.
1212
PASS String.prototype.lastIndexOf.call(undefined, '2') threw exception TypeError: Type error.
13-
PASS String.prototype.match.call(undefined, /2+/) threw exception TypeError: String.prototype.match requires that |this| not be undefined.
14-
PASS String.prototype.replace.call(undefined, /2+/, '-') threw exception TypeError: String.prototype.replace requires that |this| not be undefined.
15-
PASS String.prototype.search.call(undefined, '4') threw exception TypeError: String.prototype.search requires that |this| not be undefined.
13+
PASS String.prototype.match.call(undefined, /2+/) threw exception TypeError: String.prototype.match requires that |this| not be null or undefined.
14+
PASS String.prototype.replace.call(undefined, /2+/, '-') threw exception TypeError: String.prototype.replace requires that |this| not be null or undefined.
15+
PASS String.prototype.search.call(undefined, '4') threw exception TypeError: String.prototype.search requires that |this| not be null or undefined.
1616
PASS String.prototype.slice.call(undefined, 1, 3) threw exception TypeError: Type error.
17-
PASS String.prototype.split.call(undefined, '2') threw exception TypeError: String.prototype.split requires that |this| not be undefined.
17+
PASS String.prototype.split.call(undefined, '2') threw exception TypeError: String.prototype.split requires that |this| not be null or undefined.
1818
PASS String.prototype.slice.call(undefined, 1, 3) threw exception TypeError: Type error.
1919
PASS String.prototype.substr.call(undefined, 1, 3) threw exception TypeError: Type error.
2020
PASS String.prototype.substring.call(undefined, 1, 3) threw exception TypeError: Type error.
2121
PASS String.prototype.toLowerCase.call(undefined) threw exception TypeError: Type error.
2222
PASS String.prototype.toUpperCase.call(undefined) threw exception TypeError: Type error.
23-
PASS String.prototype.localeCompare.call(undefined, '1224') threw exception TypeError: String.prototype.localeCompare requires that |this| not be undefined.
23+
PASS String.prototype.localeCompare.call(undefined, '1224') threw exception TypeError: String.prototype.localeCompare requires that |this| not be null or undefined.
2424
PASS String.prototype.toLocaleLowerCase.call(undefined) threw exception TypeError: Type error.
2525
PASS String.prototype.toLocaleUpperCase.call(undefined) threw exception TypeError: Type error.
2626
PASS String.prototype.trim.call(undefined) threw exception TypeError: Type error.

LayoutTests/js/script-tests/array-find.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ shouldBe("[0,1,2,3,4,5,6,7,8,9].find(findItemAddedDuringSearch)", "undefined");
101101
shouldBe("[0,1,2,3,4,5,6,7,8,9].find(findItemRemovedDuringSearch)", "undefined");
102102

103103
debug("Exceptions");
104-
shouldThrow("Array.prototype.find.call(undefined, function() {})", "'TypeError: Array.prototype.find requires that |this| not be undefined'");
105-
shouldThrow("Array.prototype.find.call(null, function() {})", "'TypeError: Array.prototype.find requires that |this| not be null'");
104+
shouldThrow("Array.prototype.find.call(undefined, function() {})", "'TypeError: Array.prototype.find requires that |this| not be null or undefined'");
105+
shouldThrow("Array.prototype.find.call(null, function() {})", "'TypeError: Array.prototype.find requires that |this| not be null or undefined'");
106106
shouldThrow("[].find(1)", "'TypeError: Array.prototype.find callback must be a function'");
107107
shouldThrow("[].find('hello')", "'TypeError: Array.prototype.find callback must be a function'");
108108
shouldThrow("[].find([])", "'TypeError: Array.prototype.find callback must be a function'");

LayoutTests/js/script-tests/array-findIndex.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ shouldBe("[0,1,2,3,4,5,6,7,8,9].findIndex(findItemAddedDuringSearch)", "-1");
103103
shouldBe("[0,1,2,3,4,5,6,7,8,9].findIndex(findItemRemovedDuringSearch)", "-1");
104104

105105
debug("Exceptions");
106-
shouldThrow("Array.prototype.findIndex.call(undefined, function() {})", "'TypeError: Array.prototype.findIndex requires that |this| not be undefined'");
107-
shouldThrow("Array.prototype.findIndex.call(null, function() {})", "'TypeError: Array.prototype.findIndex requires that |this| not be null'");
106+
shouldThrow("Array.prototype.findIndex.call(undefined, function() {})", "'TypeError: Array.prototype.findIndex requires that |this| not be null or undefined'");
107+
shouldThrow("Array.prototype.findIndex.call(null, function() {})", "'TypeError: Array.prototype.findIndex requires that |this| not be null or undefined'");
108108
shouldThrow("[].findIndex(1)", "'TypeError: Array.prototype.findIndex callback must be a function'");
109109
shouldThrow("[].findIndex('hello')", "'TypeError: Array.prototype.findIndex callback must be a function'");
110110
shouldThrow("[].findIndex([])", "'TypeError: Array.prototype.findIndex callback must be a function'");

LayoutTests/js/script-tests/string-localeCompare.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ shouldBeTrue("Object.getOwnPropertyDescriptor(String.prototype, 'localeCompare')
77
shouldBeTrue("Object.getOwnPropertyDescriptor(String.prototype, 'localeCompare').writable");
88

99
// Test RequireObjectCoercible.
10-
shouldThrow("String.prototype.localeCompare.call()", "'TypeError: String.prototype.localeCompare requires that |this| not be undefined'");
11-
shouldThrow("String.prototype.localeCompare.call(undefined)", "'TypeError: String.prototype.localeCompare requires that |this| not be undefined'");
12-
shouldThrow("String.prototype.localeCompare.call(null)", "'TypeError: String.prototype.localeCompare requires that |this| not be null'");
10+
shouldThrow("String.prototype.localeCompare.call()", "'TypeError: String.prototype.localeCompare requires that |this| not be null or undefined'");
11+
shouldThrow("String.prototype.localeCompare.call(undefined)", "'TypeError: String.prototype.localeCompare requires that |this| not be null or undefined'");
12+
shouldThrow("String.prototype.localeCompare.call(null)", "'TypeError: String.prototype.localeCompare requires that |this| not be null or undefined'");
1313
shouldNotThrow("String.prototype.localeCompare.call({}, '')");
1414
shouldNotThrow("String.prototype.localeCompare.call([], '')");
1515
shouldNotThrow("String.prototype.localeCompare.call(NaN, '')");

0 commit comments

Comments
 (0)