aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite/sputnik_converted/15_Native/15.5_String_Objects/15.5.4_Properties_of_the_String_Prototype_Object/S15.5.4.3_A2_T2.js
blob: 40eb0444b50bd8b20a835d2cec39509ec20547be (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
// Copyright 2009 the Sputnik authors.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/**
* @name: S15.5.4.3_A2_T2;
* @section: 15.5.4.3;
* @assertion: The valueOf function is not generic; it throws a TypeError exception if its this value is not a String object. 
* Therefore, it cannot be transferred to other kinds of objects for use as a method;
* @description: Checking if creating the object String.prototype.valueOf fails;
*/


// Converted for Test262 from original Sputnik source

ES5Harness.registerTest( {
id: "S15.5.4.3_A2_T2",

path: "TestCases/15_Native/15.5_String_Objects/15.5.4_Properties_of_the_String_Prototype_Object/S15.5.4.3_A2_T2.js",

assertion: "The valueOf function is not generic; it throws a TypeError exception if its this value is not a String object.",

description: "Checking if creating the object String.prototype.valueOf fails",

test: function testcase() {
   var __obj={valueOf : String.prototype.valueOf};

//////////////////////////////////////////////////////////////////////////////
//CHECK#1
if (typeof __obj["valueOf"] !== "function") {
  $ERROR('#1: var __obj={valueOf : String.prototype.valueOf}; typeof __obj["valueOf"] === "function". Actual: typeof __obj["valueOf"] ==='+typeof __obj["valueOf"] ); 
}

//
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
//CHECK#2
try {
  var x = (__obj == 1);
  $FAIL('#2: "var __obj={valueOf : String.prototype.valueOf}; var x = (__obj == 1)" lead to throwing exception');
} catch (e) {
  if (!(e instanceof TypeError)) {
    $ERROR('#2.1: Exception is instance of TypeError. Actual: exception is '+e);
  }
}
//
//////////////////////////////////////////////////////////////////////////////

 }
});