Reviewers: arv, Dmitry S. Lomov, rossberg,

Message:
PTAL, quick fixup following allen's comment on
https://esdiscuss.org/topic/isconcatspreadable

Description:
[es6] fix IsConcatSpreadable() algorithm in runtime-array.cc

The ordering of the "IsArray()" check for IsConcatSpreadable() either moved, or
was
just wrong before. IsArray() is used if Get(O, @@isConcatSpreadable) is
undefined.

22.1.3.1.1
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isconcatspreadable

BUG=v8:3764
LOG=N
[email protected], [email protected], [email protected]

Please review this at https://codereview.chromium.org/1192153002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+26, -3 lines):
  M src/runtime/runtime-array.cc
  M test/mjsunit/harmony/array-concat.js


Index: src/runtime/runtime-array.cc
diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc
index c468673dd5298f472a91d1a89edbdbf7ba4d2877..806af12b55b3631e9818d1af24a9e5746ae0d118 100644
--- a/src/runtime/runtime-array.cc
+++ b/src/runtime/runtime-array.cc
@@ -724,17 +724,18 @@ static bool IterateElements(Isolate* isolate, Handle<JSObject> receiver,
 static bool IsConcatSpreadable(Isolate* isolate, Handle<Object> obj) {
   HandleScope handle_scope(isolate);
   if (!obj->IsSpecObject()) return false;
-  if (obj->IsJSArray()) return true;
   if (FLAG_harmony_arrays) {
     Handle<Symbol> key(isolate->factory()->is_concat_spreadable_symbol());
     Handle<Object> value;
     MaybeHandle<Object> maybeValue =
         i::Runtime::GetObjectProperty(isolate, obj, key);
     if (maybeValue.ToHandle(&value)) {
-      return value->BooleanValue();
+      if (!value->IsUndefined()) {
+        return value->BooleanValue();
+      }
     }
   }
-  return false;
+  return obj->IsJSArray();
 }


Index: test/mjsunit/harmony/array-concat.js
diff --git a/test/mjsunit/harmony/array-concat.js b/test/mjsunit/harmony/array-concat.js index c1ff92c8c3df03100571eafb0f91dd2ad1abbcec..b623a5cc114303a50a39f25e39bb40a6053e1459 100644
--- a/test/mjsunit/harmony/array-concat.js
+++ b/test/mjsunit/harmony/array-concat.js
@@ -194,6 +194,15 @@ assertThrows(function() {

 (function testConcatArraySubclass() {
   "use strict";
+  // If @@isConcatSpreadable is not used, the value of IsArray(O)
+  // is used to determine the spreadable property.
+  class A extends Array {}
+  var obj = [].concat(new A(1, 2, 3), new A(4, 5, 6), new A(7, 8, 9));
+  assertEquals(9, obj.length);
+  for (var i = 0; i < obj.length; ++i) {
+    assertEquals(i + 1, obj[i]);
+  }
+
// TODO(caitp): when concat is called on instances of classes which extend
   // Array, they should:
   //
@@ -203,6 +212,19 @@ assertThrows(function() {
 })();


+(function testConcatArraySubclassOptOut() {
+  "use strict";
+  class A extends Array {
+    get [Symbol.isConcatSpreadable]() { return false; }
+  }
+  var obj = [].concat(new A(1, 2, 3), new A(4, 5, 6), new A(7, 8, 9));
+  assertEquals(3, obj.length);
+  assertEquals(3, obj[0].length);
+  assertEquals(3, obj[1].length);
+  assertEquals(3, obj[2].length);
+})();
+
+
 (function testConcatNonArray() {
   "use strict";
   class NonArray {


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to