Skip to content
Snippets Groups Projects
Unverified Commit 7972f9bb authored by Leo Balter's avatar Leo Balter
Browse files

Add and update common tests for Array and Array.prototype

Ref #960
parent c58738e0
No related branches found
No related tags found
No related merge requests found
Showing
with 25 additions and 337 deletions
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array-constructor-array
description: >
The Array constructor is a built-in function
---*/
assert.sameValue(typeof Array, 'function');
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-the-array-constructor
description: >
The prototype of the Array constructor is the intrinsic object %FunctionPrototype%.
info: |
22.1.2 Properties of the Array Constructor
The value of the [[Prototype]] internal slot of the Array constructor is the
intrinsic object %FunctionPrototype%.
---*/
assert.sameValue(Object.getPrototypeOf(Array), Function.prototype);
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The Array has property prototype
es5id: 15.4.3.1_A1
description: Checking use hasOwnProperty
---*/
//CHECK#1
if (Array.hasOwnProperty('prototype') !== true) {
$ERROR('#1: Array.hasOwnProperty(\'prototype\') === true. Actual: ' + (Array.hasOwnProperty('prototype')));
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The Array.prototype property has the attribute DontEnum
es5id: 15.4.3.1_A2
description: Checking if enumerating the Array.prototype property fails
---*/
//CHECK#1
if (Array.propertyIsEnumerable('prototype') !== false) {
$ERROR('#1: Array.propertyIsEnumerable(\'prototype\') === false. Actual: ' + (Array.propertyIsEnumerable('prototype')));
}
//CHECK#2
var result = true;
for (var p in Array){
if (p === "prototype") {
result = false;
}
}
if (result !== true) {
$ERROR('#2: result = true; for (p in Array) { if (p === "prototype") result = false; } result === true;');
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The Array.prototype property has the attribute DontDelete
es5id: 15.4.3.1_A3
description: Checking if deleting the Array.prototype property fails
includes: [propertyHelper.js]
---*/
//CHECK#1
if (Array.hasOwnProperty('prototype') !== true) {
$ERROR('#1: Array.hasOwnProperty(\'prototype\') === true. Actual: ' + (Array.hasOwnProperty('prototype')));
}
verifyNotConfigurable(Array, "prototype");
//CHECK#2
try {
if((delete Array.prototype) !== false){
$ERROR('#2: Array.prototype has the attribute DontDelete');
}
} catch (e) {
if (e instanceof Test262Error) throw e;
assert(e instanceof TypeError);
}
//CHECK#3
if (Array.hasOwnProperty('prototype') !== true) {
$ERROR('#3: delete Array.prototype; Array.hasOwnProperty(\'prototype\') === true. Actual: ' + (Array.hasOwnProperty('prototype')));
}
//CHECK#4
if (Array.prototype === undefined) {
$ERROR('#4: delete Array.prototype; Array.prototype !== undefined');
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The Array.prototype property has the attribute ReadOnly
es5id: 15.4.3.1_A4
description: Checking if varying the Array.prototype property fails
includes: [propertyHelper.js]
---*/
//CHECK#1
var x = Array.prototype;
verifyNotWritable(Array, "prototype", null, 1);
if (Array.prototype !== x) {
$ERROR('#1: x = Array.prototype; Array.prototype = 1; Array.prototype === x. Actual: ' + (Array.prototype));
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of Array.prototype is 0
es5id: 15.4.3.1_A5
description: Array.prototype.length === 0
---*/
//CHECK#1
if (Array.prototype.length !== 0) {
$ERROR('#1.1: Array.prototype.length === 0. Actual: ' + (Array.prototype.length));
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: >
The value of the internal [[Prototype]] property of
the Array prototype object is the Object prototype object
es5id: 15.4.4_A1.1_T1
description: >
Create new property of Function.prototype. When Array.prototype
object has this property
---*/
Object.prototype.myproperty = 1;
//CHECK#1
if (Array.prototype.myproperty !== 1) {
$ERROR('#1: Object.prototype.myproperty = 1; Array.prototype.myproperty === 1. Actual: ' + (Array.prototype.myproperty));
}
//CHECK#2
if (Array.prototype.hasOwnProperty('myproperty') !== false) {
$ERROR('#2: Object.prototype.myproperty = 1; Array.prototype.hasOwnProperty(\'myproperty\') === false. Actual: ' + (Array.prototype.hasOwnProperty('myproperty')));
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 15.4.4_A1.1_T2
description: >
The Array prototype object is itself an array; its [[Class]]
is "Array",
---*/
//CHECK#1
if (Object.prototype.toString.call(Array.prototype) !== "[object Array]") {
$ERROR('The Array prototype object is itself an array; its' +
'[[Class]] is "Array".');
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: >
The value of the internal [[Prototype]] property of
the Array prototype object is the Object prototype object
es5id: 15.4.4_A1.1_T3
description: Checking use isPrototypeOf
---*/
//CHECK#1
if (Object.prototype.isPrototypeOf(Array.prototype) !== true) {
$ERROR('#1: Object.prototype.isPrototypeOf(Array.prototype) === true. Actual: ' + (Object.prototype.isPrototypeOf(Array.prototype)));
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The [[Class]] property of the Array prototype object is set to "Array"
es5id: 15.4.4_A1.2_T1
description: Checking use Object.prototype.toString
---*/
//CHECK#1
Array.prototype.getClass = Object.prototype.toString;
if (Array.prototype.getClass() !== "[object " + "Array" + "]") {
$ERROR('#1: Array.prototype.getClass = Object.prototype.toString; Array.prototype is Array object. Actual: ' + (Array.prototype.getClass()));
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: >
The Array prototype object does not have a valueOf property of
its own; however, it inherits the valueOf property from the valueOf
property from the Object prototype Object
es5id: 15.4.4_A2.1_T1
description: Checking use hasOwnProperty
---*/
//CHECK#1
if (Array.prototype.hasOwnProperty('valueOf') !== false) {
$ERROR('#1: Array.prototype.hasOwnProperty(\'valueOf\') === false. Actual: ' + (Array.prototype.hasOwnProperty('valueOf')));
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: >
The Array prototype object does not have a valueOf property of
its own; however, it inherits the valueOf property from the valueOf
property from the Object prototype Object
es5id: 15.4.4_A2.1_T2
description: >
Change valueOf property of Object.prototype. When
Array.prototype.valueOf also change
---*/
Object.prototype.valueOf = 1;
//CHECK#1
if (Array.prototype.valueOf !== 1) {
$ERROR('#1: Object.prototype.valueOf = 1; Array.prototype.valueOf === 1. Actual: ' + (Array.prototype.valueOf));
}
//CHECK#2
var x = new Array();
if (x.valueOf !== 1) {
$ERROR('#1: Object.prototype.valueOf = 1; x = new Array(); x.valueOf === 1. Actual: ' + (x.valueOf));
}
// Copyright (c) 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/*---
es6id: 22.1.3.1_3
description: Array.prototype.concat arity
---*/
assert.sameValue(Array.prototype.concat.length, 1);
// Copyright (c) 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/*---
es6id: 22.1.3.1_3
description: Array.prototype.concat descriptor
---*/
var desc = Object.getOwnPropertyDescriptor(Array.prototype, "concat");
assert.sameValue(desc.enumerable, false);
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of concat has the attribute DontEnum
es5id: 15.4.4.4_A4.1
description: Checking use propertyIsEnumerable, for-in
---*/
//CHECK#1
if (Array.prototype.concat.propertyIsEnumerable('length') !== false) {
$ERROR('#1: Array.prototype.concat.propertyIsEnumerable(\'length\') === false. Actual: ' + (Array.prototype.concat.propertyIsEnumerable('length')));
}
//CHECK#2
var result = true;
for (var p in Array.prototype.concat){
if (p === "length") {
result = false;
}
}
if (result !== true) {
$ERROR('#2: result = true; for (p in Array.prototype.concat) { if (p === "length") result = false; } result === true;');
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of concat does not have the attribute DontDelete
es5id: 15.4.4.4_A4.2
description: Checking use hasOwnProperty, delete
---*/
//CHECK#1
if (Array.prototype.concat.hasOwnProperty('length') !== true) {
$ERROR('#1: Array.prototype.concat.hasOwnProperty(\'length\') === true. Actual: ' + (Array.prototype.concat.hasOwnProperty('length')));
}
delete Array.prototype.concat.length;
//CHECK#2
if (Array.prototype.concat.hasOwnProperty('length') !== false) {
$ERROR('#2: delete Array.prototype.concat.length; Array.prototype.concat.hasOwnProperty(\'length\') === false. Actual: ' + (Array.prototype.concat.hasOwnProperty('length')));
}
//CHECK#3
if (Array.prototype.concat.length === undefined) {
$ERROR('#3: delete Array.prototype.concat.length; Array.prototype.concat.length !== undefined');
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of concat has the attribute ReadOnly
es5id: 15.4.4.4_A4.3
description: Checking if varying the length property fails
includes: [propertyHelper.js]
---*/
//CHECK#1
var x = Array.prototype.concat.length;
verifyNotWritable(Array.prototype.concat, "length", null, Infinity);
if (Array.prototype.concat.length !== x) {
$ERROR('#1: x = Array.prototype.concat.length; Array.prototype.concat.length = Infinity; Array.prototype.concat.length === x. Actual: ' + (Array.prototype.concat.length));
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of concat is 1
es5id: 15.4.4.4_A4.4
description: concat.length === 1
---*/
//CHECK#1
if (Array.prototype.concat.length !== 1) {
$ERROR('#1: Array.prototype.concat.length === 1. Actual: ' + (Array.prototype.concat.length));
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The concat property of Array has the attribute DontEnum
es5id: 15.4.4.4_A4.5
description: Checking use propertyIsEnumerable, for-in
---*/
//CHECK#1
if (Array.propertyIsEnumerable('concat') !== false) {
$ERROR('#1: Array.propertyIsEnumerable(\'concat\') === false. Actual: ' + (Array.propertyIsEnumerable('concat')));
}
//CHECK#2
var result = true;
for (var p in Array){
if (p === "concat") {
result = false;
}
}
if (result !== true) {
$ERROR('#2: result = true; for (p in Array) { if (p === "concat") result = false; } result === true;');
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment