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

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 property attributes 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') | test/mjsunit/harmony/array-from.js » ('J')
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 51e2d01b50147ded30436174685b23aca3484ac9..bbe1ff916a7a58af2993f2983adc29d9b993bfd7 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, NONE);
+ } 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,7 +250,8 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
} else {
mappedValue = nextValue;
}
- %AddElement(result, k++, mappedValue, NONE);
+ AddArrayElement(this, result, k, mappedValue);
+ k++;
}
} else {
var len = $toLength(items.length);
@@ -251,7 +264,7 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
} else {
mappedValue = nextValue;
}
- %AddElement(result, k, mappedValue, NONE);
+ AddArrayElement(this, result, k, mappedValue);
}
result.length = k;
@@ -266,7 +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++) {
- %AddElement(array, i, %_Arguments(i), NONE);
+ AddArrayElement(constructor, array, i, %_Arguments(i));
}
array.length = length;
return array;
« no previous file with comments | « no previous file | src/prologue.js » ('j') | test/mjsunit/harmony/array-from.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698