aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite/sputnik_converted/15_Native/15.4_Array_Objects/15.4.4_Properties_of_the_Array_Prototype_Object/15.4.4.7_Array_prototype_push/S15.4.4.7_A2_T3.js
blob: 948888229bc5c3c87d761e1506526f5c1c21b476 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2009 the Sputnik authors.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/**
 * @name: S15.4.4.7_A2_T3;
 * @section: 15.4.4.7;
 * @assertion: The push function is intentionally generic. 
 * It does not require that its this value be an Array object;
 * @description: Operator use ToNumber from length.
 * If Type(value) is Object, evaluate ToPrimitive(value, Number); 
*/


// Converted for Test262 from original Sputnik source

ES5Harness.registerTest( {
id: "S15.4.4.7_A2_T3",

path: "TestCases/15_Native/15.4_Array_Objects/15.4.4_Properties_of_the_Array_Prototype_Object/15.4.4.7_Array_prototype_push/S15.4.4.7_A2_T3.js",

assertion: "The push function is intentionally generic.",

description: "Operator use ToNumber from length.",

test: function testcase() {
   var obj = {};
obj.push = Array.prototype.push;

//CHECK#1
obj.length = {valueOf: function() {return 3}};
var push = obj.push();
if (push !== 3) {
  $ERROR('#1:  obj.length = {valueOf: function() {return 3}}  obj.push() === 3. Actual: ' + (push));
}

//CHECK#2
obj.length = {valueOf: function() {return 3}, toString: function() {return 1}};
var push = obj.push();
if (push !== 3) {
  $ERROR('#0:  obj.length = {valueOf: function() {return 3}, toString: function() {return 1}}  obj.push() === 3. Actual: ' + (push));
} 

//CHECK#3
obj.length = {valueOf: function() {return 3}, toString: function() {return {}}};
var push = obj.push();
if (push !== 3) {
  $ERROR('#1:  obj.length = {valueOf: function() {return 3}, toString: function() {return {}}}  obj.push() === 3. Actual: ' + (push));
}

//CHECK#4
try {  
  
  obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}};  
  var push = obj.push();
if (push !== 3) {
    $ERROR('#4.1:  obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.push() === ",". Actual: ' + (push));
  }
}
catch (e) {
  if (e === "error") {
    $ERROR('#4.2:  obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.push() not throw "error"');
  } else {
    $ERROR('#4.3:  obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.push() not throw Error. Actual: ' + (e));
  }
}

//CHECK#5
obj.length = {toString: function() {return 1}};
var push = obj.push();
if (push !== 1) {
  $ERROR('#5:  obj.length = {toString: function() {return 1}}  obj.push() === 1. Actual: ' + (push));
}

//CHECK#6
obj.length = {valueOf: function() {return {}}, toString: function() {return 1}}
var push = obj.push();
if (push !== 1) {
  $ERROR('#6:  obj.length = {valueOf: function() {return {}}, toString: function() {return 1}}  obj.push() === 1. Actual: ' + (push));
}

//CHECK#7
try {
  
  obj.length = {valueOf: function() {throw "error"}, toString: function() {return 1}};  
  var push = obj.push();
  $ERROR('#7.1:  obj.length = {valueOf: function() {throw "error"}, toString: function() {return 1}}; obj.push() throw "error". Actual: ' + (push));
}  
catch (e) {
  if (e !== "error") {
    $ERROR('#7.2:  obj.length = {valueOf: function() {throw "error"}, toString: function() {return 1}}; obj.push() throw "error". Actual: ' + (e));
  } 
}

//CHECK#8
try {
  
  obj.length = {valueOf: function() {return {}}, toString: function() {return {}}};
  var push = obj.push();
  $ERROR('#8.1:  obj.length = {valueOf: function() {return {}}, toString: function() {return {}}}  obj.push() throw TypeError. Actual: ' + (push));
}  
catch (e) {
  if ((e instanceof TypeError) !== true) {
    $ERROR('#8.2:  obj.length = {valueOf: function() {return {}}, toString: function() {return {}}}  obj.push() throw TypeError. Actual: ' + (e));
  } 
}

 }
});