Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Unified Diff: src/array.js

Issue 132333019: Use `CHECK_OBJECT_COERCIBLE` macro where possible (Closed) Base URL: git@github.com:v8/v8.git@master
Patch Set: Don’t update copyright year Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/harmony-array.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/array.js
diff --git a/src/array.js b/src/array.js
index 26bf7282e18ba1a90b7e7c5569cedf0334ef89b6..372b7ece6382118a7a578e9a2d0f40ac43ae222a 100644
--- a/src/array.js
+++ b/src/array.js
@@ -376,10 +376,7 @@ function ArrayToLocaleString() {
function ArrayJoin(separator) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.join"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join");
var length = TO_UINT32(this.length);
if (IS_UNDEFINED(separator)) {
@@ -414,10 +411,7 @@ function ObservedArrayPop(n) {
// Removes the last element from the array and returns it. See
// ECMA-262, section 15.4.4.6.
function ArrayPop() {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.pop"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop");
var n = TO_UINT32(this.length);
if (n == 0) {
@@ -462,10 +456,7 @@ function ObservedArrayPush() {
// Appends the arguments to the end of the array and returns the new
// length of the array. See ECMA-262, section 15.4.4.7.
function ArrayPush() {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.push"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push");
var n = TO_UINT32(this.length);
var m = %_ArgumentsLength();
@@ -489,10 +480,7 @@ function ArrayPush() {
// by the array elements of each argument in order. See ECMA-262,
// section 15.4.4.7.
function ArrayConcat(arg1) { // length == 1
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.concat"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.concat");
var array = ToObject(this);
var arg_count = %_ArgumentsLength();
@@ -551,10 +539,7 @@ function SparseReverse(array, len) {
function ArrayReverse() {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.reverse"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reverse");
var j = TO_UINT32(this.length) - 1;
@@ -602,10 +587,7 @@ function ObservedArrayShift(len) {
}
function ArrayShift() {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.shift"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift");
var len = TO_UINT32(this.length);
@@ -655,10 +637,7 @@ function ObservedArrayUnshift() {
}
function ArrayUnshift(arg1) { // length == 1
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.unshift"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift");
var len = TO_UINT32(this.length);
var num_arguments = %_ArgumentsLength();
@@ -700,10 +679,7 @@ function ArrayUnshift(arg1) { // length == 1
function ArraySlice(start, end) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.slice"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.slice");
var len = TO_UINT32(this.length);
var start_i = TO_INTEGER(start);
@@ -817,10 +793,7 @@ function ObservedArraySplice(start, delete_count) {
function ArraySplice(start, delete_count) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.splice"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice");
if (%IsObserved(this))
return ObservedArraySplice.apply(this, arguments);
@@ -878,10 +851,7 @@ function ArraySplice(start, delete_count) {
function ArraySort(comparefn) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.sort"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.sort");
// In-place QuickSort algorithm.
// For short (length <= 22) arrays, insertion sort is used for efficiency.
@@ -1171,10 +1141,7 @@ function ArraySort(comparefn) {
// preserving the semantics, since the calls to the receiver function can add
// or delete elements from the array.
function ArrayFilter(f, receiver) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.filter"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter");
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
@@ -1222,10 +1189,7 @@ function ArrayFilter(f, receiver) {
function ArrayForEach(f, receiver) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.forEach"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach");
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
@@ -1266,10 +1230,7 @@ function ArrayForEach(f, receiver) {
// Executes the function once for each element present in the
// array until it finds one where callback returns true.
function ArraySome(f, receiver) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.some"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some");
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
@@ -1309,10 +1270,7 @@ function ArraySome(f, receiver) {
function ArrayEvery(f, receiver) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.every"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every");
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
@@ -1351,10 +1309,7 @@ function ArrayEvery(f, receiver) {
}
function ArrayMap(f, receiver) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.map"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map");
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
@@ -1397,10 +1352,7 @@ function ArrayMap(f, receiver) {
function ArrayIndexOf(element, index) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.indexOf"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf");
var length = TO_UINT32(this.length);
if (length == 0) return -1;
@@ -1456,10 +1408,7 @@ function ArrayIndexOf(element, index) {
function ArrayLastIndexOf(element, index) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.lastIndexOf"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf");
var length = TO_UINT32(this.length);
if (length == 0) return -1;
@@ -1511,10 +1460,7 @@ function ArrayLastIndexOf(element, index) {
function ArrayReduce(callback, current) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.reduce"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce");
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
@@ -1564,10 +1510,7 @@ function ArrayReduce(callback, current) {
}
function ArrayReduceRight(callback, current) {
- if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
- throw MakeTypeError("called_on_null_or_undefined",
- ["Array.prototype.reduceRight"]);
- }
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight");
// Pull out the length so that side effects are visible before the
// callback function is checked.
« no previous file with comments | « no previous file | src/harmony-array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698