From c650b1a9b088afde24911e82c428d03de635e5be Mon Sep 17 00:00:00 2001
From: Sam Mikes <smikes@cubane.com>
Date: Fri, 1 Aug 2014 13:43:24 +0100
Subject: [PATCH] ES5.S15: new tests to clarify Array.concat

Test of spec language from 15.4.4.4,
5.b.iii.3.b states 'Call the [[DefineOwnProeprty]] internal method of A'
which means that the result of Array.prototype.concat
should return `true` from `hasOwnProperty` for every property
created by `concat`, up to `length`

Set length to 3.
a[0] is set to 0 on a
a[1] is unset
a[2] is set to 2 via a prototype of a

add assertions for values of b[0], b[1], b[2]
add assertions for b.hasOwnProperty('2')

Check with Array.prototype and Object.prototype, separate tests

fix typo in assertion message

test was correct, but assertion message was incorrect
---
 .../15.4/15.4.4/15.4.4.4/S15.4.4.4_A3_T2.js   | 64 +++++++++++++++++++
 .../15.4/15.4.4/15.4.4.4/S15.4.4.4_A3_T3.js   | 64 +++++++++++++++++++
 2 files changed, 128 insertions(+)
 create mode 100644 test/suite/ch15/15.4/15.4.4/15.4.4.4/S15.4.4.4_A3_T2.js
 create mode 100644 test/suite/ch15/15.4/15.4.4/15.4.4.4/S15.4.4.4_A3_T3.js

diff --git a/test/suite/ch15/15.4/15.4.4/15.4.4.4/S15.4.4.4_A3_T2.js b/test/suite/ch15/15.4/15.4.4/15.4.4.4/S15.4.4.4_A3_T2.js
new file mode 100644
index 0000000000..771862b347
--- /dev/null
+++ b/test/suite/ch15/15.4/15.4.4/15.4.4.4/S15.4.4.4_A3_T2.js
@@ -0,0 +1,64 @@
+// Copyright 2014 Ecma International.  All rights reserved.
+// See LICENSE or https://github.com/tc39/test262/blob/master/LICENSE
+
+/*---
+info: Array.prototype.concat uses [[Get]] on 'length' to determine array length
+es5id: 15.4.4.4_A3_T2
+description: >
+  checking whether non-ownProperties are seen, copied by Array.prototype.concat: Array.prototype[1]
+---*/
+
+var a = [0];
+
+if (a.length !== 1) {
+  $ERROR("expected a.length === 1, actually " + a.length);
+}
+
+a.length = 3;
+
+if (a[1] !== undefined) {
+  $ERROR("expected a[1] === undefined, actually " + a[1]);
+}
+if (a[2] !== undefined) {
+  $ERROR("expected a[2] === undefined, actually " + a[2]);
+}
+
+Array.prototype[2] = 2;
+
+if (a[1] !== undefined) {
+  $ERROR("expected a[1] === undefined, actually " + a[1]);
+}
+if (a[2] !== 2) {
+  $ERROR("expected a[2] === 2, actually " + a[2]);
+}
+
+if (a.hasOwnProperty('1') !== false) {
+  $ERROR("a.hasOwnProperty('1') === false, actually " + a.hasOwnProperty('1'));
+}
+if (a.hasOwnProperty('2') !== false) {
+  $ERROR("a.hasOwnProperty('2') === false, actually " + a.hasOwnProperty('2'));
+}
+
+var b = a.concat();
+
+if (b.length !== 3) {
+  $ERROR("expected b.length === 3, actually " + b.length);
+}
+
+if (b[0] !== 0) {
+  $ERROR("expected b[0] === 0, actually " + b[0]);
+}
+if (b[1] !== undefined) {
+  $ERROR("expected b[1] === undefined, actually " + b[1]);
+}
+if (b[2] !== 2) {
+  $ERROR("expected b[2] === 2, actually " + b[2]);
+}
+
+if (b.hasOwnProperty('1') !== false) {
+  $ERROR("expected b.hasOwnProperty('1') === false, actually " + b.hasOwnProperty('1'));
+}
+if (b.hasOwnProperty('2') !== true) {
+  $ERROR("expected b.hasOwnProperty('2') === true, actually " + b.hasOwnProperty('2'));
+}
+
diff --git a/test/suite/ch15/15.4/15.4.4/15.4.4.4/S15.4.4.4_A3_T3.js b/test/suite/ch15/15.4/15.4.4/15.4.4.4/S15.4.4.4_A3_T3.js
new file mode 100644
index 0000000000..8435746525
--- /dev/null
+++ b/test/suite/ch15/15.4/15.4.4/15.4.4.4/S15.4.4.4_A3_T3.js
@@ -0,0 +1,64 @@
+// Copyright 2014 Ecma International.  All rights reserved.
+// See LICENSE or https://github.com/tc39/test262/blob/master/LICENSE
+
+/*---
+info: Array.prototype.concat uses [[Get]] on 'length' to determine array length
+es5id: 15.4.4.4_A3_T3
+description: >
+  checking whether non-ownProperties are seen, copied by Array.prototype.concat: Object.prototype[1]
+---*/
+
+var a = [0];
+
+if (a.length !== 1) {
+  $ERROR("expected a.length === 1, actually " + a.length);
+}
+
+a.length = 3;
+
+if (a[1] !== undefined) {
+  $ERROR("expected a[1] === undefined, actually " + a[1]);
+}
+if (a[2] !== undefined) {
+  $ERROR("expected a[2] === undefined, actually " + a[2]);
+}
+
+Object.prototype[2] = 2;
+
+if (a[1] !== undefined) {
+  $ERROR("expected a[1] === undefined, actually " + a[1]);
+}
+if (a[2] !== 2) {
+  $ERROR("expected a[2] === 2, actually " + a[2]);
+}
+
+if (a.hasOwnProperty('1') !== false) {
+  $ERROR("a.hasOwnProperty('1') === false, actually " + a.hasOwnProperty('1'));
+}
+if (a.hasOwnProperty('2') !== false) {
+  $ERROR("a.hasOwnProperty('2') === false, actually " + a.hasOwnProperty('2'));
+}
+
+var b = a.concat();
+
+if (b.length !== 3) {
+  $ERROR("expected b.length === 3, actually " + b.length);
+}
+
+if (b[0] !== 0) {
+  $ERROR("expected b[0] === 0, actually " + b[0]);
+}
+if (b[1] !== undefined) {
+  $ERROR("expected b[1] === undefined, actually " + b[1]);
+}
+if (b[2] !== 2) {
+  $ERROR("expected b[2] === 2, actually " + b[2]);
+}
+
+if (b.hasOwnProperty('1') !== false) {
+  $ERROR("expected b.hasOwnProperty('1') === false, actually " + b.hasOwnProperty('1'));
+}
+if (b.hasOwnProperty('2') !== true) {
+  $ERROR("expected b.hasOwnProperty('2') === true, actually " + b.hasOwnProperty('2'));
+}
+
-- 
GitLab