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

Unified Diff: src/builtins.cc

Issue 6357025: ArraySplice builtin should return empty array and not alter receiver if invoked with no arguments. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Minor correction Created 9 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
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index 58dd439d250435055057650af19246246cc56bd4..3e3a7034b8a74e8c1f6db4f1f93e4d2198722845 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -753,16 +753,22 @@ BUILTIN(ArraySplice) {
// given differently from when an undefined delete count is given.
// This does not follow ECMA-262, but we do the same for
// compatibility.
- int delete_count = len;
- if (n_arguments > 1) {
- Object* arg2 = args[2];
- if (arg2->IsSmi()) {
- delete_count = Smi::cast(arg2)->value();
- } else {
- return CallJsBuiltin("ArraySplice", args);
+ int actual_delete_count;
+ if (n_arguments != 1) {
+ int value = 0; // ToInteger(undefined) == 0
+ if (n_arguments > 1) {
+ Object* arg2 = args[2];
+ if (arg2->IsSmi()) {
+ value = Smi::cast(arg2)->value();
+ } else {
+ return CallJsBuiltin("ArraySplice", args);
+ }
}
+ actual_delete_count = Min(Max(value, 0), len - actual_start);
+ } else {
+ ASSERT(len - actual_start >= 0);
+ actual_delete_count = len - actual_start;
}
- int actual_delete_count = Min(Max(delete_count, 0), len - actual_start);
JSArray* result_array = NULL;
if (actual_delete_count == 0) {
« src/array.js ('K') | « src/array.js ('k') | test/mjsunit/array-splice.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698