Commit f3e3fe28 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Use `CHECK_OBJECT_COERCIBLE` macro where possible

Contributed by Mathias Bynens <mathiasb@opera.com>.

TEST=
BUG=v8:3122
LOG=N
R=arv@chromium.org

Review URL: https://codereview.chromium.org/132333019

Patch from Mathias Bynens <mathiasb@opera.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18979 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2daf43ac
...@@ -376,10 +376,7 @@ function ArrayToLocaleString() { ...@@ -376,10 +376,7 @@ function ArrayToLocaleString() {
function ArrayJoin(separator) { function ArrayJoin(separator) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.join"]);
}
var length = TO_UINT32(this.length); var length = TO_UINT32(this.length);
if (IS_UNDEFINED(separator)) { if (IS_UNDEFINED(separator)) {
...@@ -414,10 +411,7 @@ function ObservedArrayPop(n) { ...@@ -414,10 +411,7 @@ function ObservedArrayPop(n) {
// Removes the last element from the array and returns it. See // Removes the last element from the array and returns it. See
// ECMA-262, section 15.4.4.6. // ECMA-262, section 15.4.4.6.
function ArrayPop() { function ArrayPop() {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.pop"]);
}
var n = TO_UINT32(this.length); var n = TO_UINT32(this.length);
if (n == 0) { if (n == 0) {
...@@ -462,10 +456,7 @@ function ObservedArrayPush() { ...@@ -462,10 +456,7 @@ function ObservedArrayPush() {
// Appends the arguments to the end of the array and returns the new // 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. // length of the array. See ECMA-262, section 15.4.4.7.
function ArrayPush() { function ArrayPush() {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.push"]);
}
var n = TO_UINT32(this.length); var n = TO_UINT32(this.length);
var m = %_ArgumentsLength(); var m = %_ArgumentsLength();
...@@ -489,10 +480,7 @@ function ArrayPush() { ...@@ -489,10 +480,7 @@ function ArrayPush() {
// by the array elements of each argument in order. See ECMA-262, // by the array elements of each argument in order. See ECMA-262,
// section 15.4.4.7. // section 15.4.4.7.
function ArrayConcat(arg1) { // length == 1 function ArrayConcat(arg1) { // length == 1
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.concat");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.concat"]);
}
var array = ToObject(this); var array = ToObject(this);
var arg_count = %_ArgumentsLength(); var arg_count = %_ArgumentsLength();
...@@ -551,10 +539,7 @@ function SparseReverse(array, len) { ...@@ -551,10 +539,7 @@ function SparseReverse(array, len) {
function ArrayReverse() { function ArrayReverse() {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reverse");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.reverse"]);
}
var j = TO_UINT32(this.length) - 1; var j = TO_UINT32(this.length) - 1;
...@@ -602,10 +587,7 @@ function ObservedArrayShift(len) { ...@@ -602,10 +587,7 @@ function ObservedArrayShift(len) {
} }
function ArrayShift() { function ArrayShift() {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.shift"]);
}
var len = TO_UINT32(this.length); var len = TO_UINT32(this.length);
...@@ -655,10 +637,7 @@ function ObservedArrayUnshift() { ...@@ -655,10 +637,7 @@ function ObservedArrayUnshift() {
} }
function ArrayUnshift(arg1) { // length == 1 function ArrayUnshift(arg1) { // length == 1
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.unshift"]);
}
var len = TO_UINT32(this.length); var len = TO_UINT32(this.length);
var num_arguments = %_ArgumentsLength(); var num_arguments = %_ArgumentsLength();
...@@ -700,10 +679,7 @@ function ArrayUnshift(arg1) { // length == 1 ...@@ -700,10 +679,7 @@ function ArrayUnshift(arg1) { // length == 1
function ArraySlice(start, end) { function ArraySlice(start, end) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.slice");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.slice"]);
}
var len = TO_UINT32(this.length); var len = TO_UINT32(this.length);
var start_i = TO_INTEGER(start); var start_i = TO_INTEGER(start);
...@@ -817,10 +793,7 @@ function ObservedArraySplice(start, delete_count) { ...@@ -817,10 +793,7 @@ function ObservedArraySplice(start, delete_count) {
function ArraySplice(start, delete_count) { function ArraySplice(start, delete_count) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.splice"]);
}
if (%IsObserved(this)) if (%IsObserved(this))
return ObservedArraySplice.apply(this, arguments); return ObservedArraySplice.apply(this, arguments);
...@@ -878,10 +851,7 @@ function ArraySplice(start, delete_count) { ...@@ -878,10 +851,7 @@ function ArraySplice(start, delete_count) {
function ArraySort(comparefn) { function ArraySort(comparefn) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.sort");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.sort"]);
}
// In-place QuickSort algorithm. // In-place QuickSort algorithm.
// For short (length <= 22) arrays, insertion sort is used for efficiency. // For short (length <= 22) arrays, insertion sort is used for efficiency.
...@@ -1171,10 +1141,7 @@ function ArraySort(comparefn) { ...@@ -1171,10 +1141,7 @@ function ArraySort(comparefn) {
// preserving the semantics, since the calls to the receiver function can add // preserving the semantics, since the calls to the receiver function can add
// or delete elements from the array. // or delete elements from the array.
function ArrayFilter(f, receiver) { function ArrayFilter(f, receiver) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.filter"]);
}
// Pull out the length so that modifications to the length in the // Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible. // loop will not affect the looping and side effects are visible.
...@@ -1222,10 +1189,7 @@ function ArrayFilter(f, receiver) { ...@@ -1222,10 +1189,7 @@ function ArrayFilter(f, receiver) {
function ArrayForEach(f, receiver) { function ArrayForEach(f, receiver) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.forEach"]);
}
// Pull out the length so that modifications to the length in the // Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible. // loop will not affect the looping and side effects are visible.
...@@ -1266,10 +1230,7 @@ function ArrayForEach(f, receiver) { ...@@ -1266,10 +1230,7 @@ function ArrayForEach(f, receiver) {
// Executes the function once for each element present in the // Executes the function once for each element present in the
// array until it finds one where callback returns true. // array until it finds one where callback returns true.
function ArraySome(f, receiver) { function ArraySome(f, receiver) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.some"]);
}
// Pull out the length so that modifications to the length in the // Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible. // loop will not affect the looping and side effects are visible.
...@@ -1309,10 +1270,7 @@ function ArraySome(f, receiver) { ...@@ -1309,10 +1270,7 @@ function ArraySome(f, receiver) {
function ArrayEvery(f, receiver) { function ArrayEvery(f, receiver) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.every"]);
}
// Pull out the length so that modifications to the length in the // Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible. // loop will not affect the looping and side effects are visible.
...@@ -1351,10 +1309,7 @@ function ArrayEvery(f, receiver) { ...@@ -1351,10 +1309,7 @@ function ArrayEvery(f, receiver) {
} }
function ArrayMap(f, receiver) { function ArrayMap(f, receiver) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.map"]);
}
// Pull out the length so that modifications to the length in the // Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible. // loop will not affect the looping and side effects are visible.
...@@ -1397,10 +1352,7 @@ function ArrayMap(f, receiver) { ...@@ -1397,10 +1352,7 @@ function ArrayMap(f, receiver) {
function ArrayIndexOf(element, index) { function ArrayIndexOf(element, index) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.indexOf"]);
}
var length = TO_UINT32(this.length); var length = TO_UINT32(this.length);
if (length == 0) return -1; if (length == 0) return -1;
...@@ -1456,10 +1408,7 @@ function ArrayIndexOf(element, index) { ...@@ -1456,10 +1408,7 @@ function ArrayIndexOf(element, index) {
function ArrayLastIndexOf(element, index) { function ArrayLastIndexOf(element, index) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.lastIndexOf"]);
}
var length = TO_UINT32(this.length); var length = TO_UINT32(this.length);
if (length == 0) return -1; if (length == 0) return -1;
...@@ -1511,10 +1460,7 @@ function ArrayLastIndexOf(element, index) { ...@@ -1511,10 +1460,7 @@ function ArrayLastIndexOf(element, index) {
function ArrayReduce(callback, current) { function ArrayReduce(callback, current) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.reduce"]);
}
// Pull out the length so that modifications to the length in the // Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible. // loop will not affect the looping and side effects are visible.
...@@ -1564,10 +1510,7 @@ function ArrayReduce(callback, current) { ...@@ -1564,10 +1510,7 @@ function ArrayReduce(callback, current) {
} }
function ArrayReduceRight(callback, current) { function ArrayReduceRight(callback, current) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.reduceRight"]);
}
// Pull out the length so that side effects are visible before the // Pull out the length so that side effects are visible before the
// callback function is checked. // callback function is checked.
......
...@@ -35,10 +35,7 @@ ...@@ -35,10 +35,7 @@
// ES6 draft 07-15-13, section 15.4.3.23 // ES6 draft 07-15-13, section 15.4.3.23
function ArrayFind(predicate /* thisArg */) { // length == 1 function ArrayFind(predicate /* thisArg */) { // length == 1
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.find"]);
}
var array = ToObject(this); var array = ToObject(this);
var length = ToInteger(array.length); var length = ToInteger(array.length);
...@@ -73,10 +70,7 @@ function ArrayFind(predicate /* thisArg */) { // length == 1 ...@@ -73,10 +70,7 @@ function ArrayFind(predicate /* thisArg */) { // length == 1
// ES6 draft 07-15-13, section 15.4.3.24 // ES6 draft 07-15-13, section 15.4.3.24
function ArrayFindIndex(predicate /* thisArg */) { // length == 1 function ArrayFindIndex(predicate /* thisArg */) { // length == 1
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex");
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.findIndex"]);
}
var array = ToObject(this); var array = ToObject(this);
var length = ToInteger(array.length); var length = ToInteger(array.length);
......
...@@ -247,10 +247,7 @@ function ObjectToString() { ...@@ -247,10 +247,7 @@ function ObjectToString() {
// ECMA-262 - 15.2.4.3 // ECMA-262 - 15.2.4.3
function ObjectToLocaleString() { function ObjectToLocaleString() {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Object.prototype.toLocaleString");
throw MakeTypeError("called_on_null_or_undefined",
["Object.prototype.toLocaleString"]);
}
return this.toString(); return this.toString();
} }
...@@ -276,10 +273,7 @@ function ObjectHasOwnProperty(V) { ...@@ -276,10 +273,7 @@ function ObjectHasOwnProperty(V) {
// ECMA-262 - 15.2.4.6 // ECMA-262 - 15.2.4.6
function ObjectIsPrototypeOf(V) { function ObjectIsPrototypeOf(V) {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { CHECK_OBJECT_COERCIBLE(this, "Object.prototype.isPrototypeOf");
throw MakeTypeError("called_on_null_or_undefined",
["Object.prototype.isPrototypeOf"]);
}
if (!IS_SPEC_OBJECT(V)) return false; if (!IS_SPEC_OBJECT(V)) return false;
return %IsInPrototypeChain(this, V); return %IsInPrototypeChain(this, V);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment