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

Unified Diff: src/harmony-array.js

Issue 1181623003: In Array.of and Array.from, fall back to DefineOwnProperty (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix %AddElement call, changed in rebase Created 5 years, 6 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/prologue.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-array.js
diff --git a/src/harmony-array.js b/src/harmony-array.js
index f9ce2f194f9ac0976cc7fe1ec289abbfc7154899..637dd6ed857639f8b743f617a744aea9460a4e85 100644
--- a/src/harmony-array.js
+++ b/src/harmony-array.js
@@ -19,6 +19,7 @@ var GetMethod;
var MathMax;
var MathMin;
var ObjectIsFrozen;
+var ObjectDefineProperty;
utils.Import(function(from) {
GetIterator = from.GetIterator;
@@ -26,6 +27,7 @@ utils.Import(function(from) {
MathMax = from.MathMax;
MathMin = from.MathMin;
ObjectIsFrozen = from.ObjectIsFrozen;
+ ObjectDefineProperty = from.ObjectDefineProperty;
});
// -------------------------------------------------------------------
@@ -191,6 +193,16 @@ function ArrayFill(value, start, end) {
return InnerArrayFill(value, start, end, array, length);
}
+function AddArrayElement(constructor, array, i, value) {
+ if (constructor === GlobalArray) {
+ %AddElement(array, i, value);
+ } else {
+ ObjectDefineProperty(array, i, {
+ value: value, writable: true, configurable: true, enumerable: true
+ });
+ }
+}
+
// ES6, draft 10-14-14, section 22.1.2.1
function ArrayFrom(arrayLike, mapfn, receiver) {
var items = $toObject(arrayLike);
@@ -238,8 +250,8 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
} else {
mappedValue = nextValue;
}
- // TODO(verwaest): This should redefine rather than adding.
- %AddElement(result, k++, mappedValue);
+ AddArrayElement(this, result, k, mappedValue);
+ k++;
}
} else {
var len = $toLength(items.length);
@@ -252,8 +264,7 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
} else {
mappedValue = nextValue;
}
- // TODO(verwaest): This should redefine rather than adding.
- %AddElement(result, k, mappedValue);
+ AddArrayElement(this, result, k, mappedValue);
}
result.length = k;
@@ -268,8 +279,7 @@ function ArrayOf() {
// TODO: Implement IsConstructor (ES6 section 7.2.5)
var array = %IsConstructor(constructor) ? new constructor(length) : [];
for (var i = 0; i < length; i++) {
- // TODO(verwaest): This should redefine rather than adding.
- %AddElement(array, i, %_Arguments(i));
+ AddArrayElement(constructor, array, i, %_Arguments(i));
}
array.length = length;
return array;
« no previous file with comments | « no previous file | src/prologue.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698