summaryrefslogtreecommitdiff
path: root/test/built-ins/String/prototype/toString/S15.5.4.2_A2_T1.js
blob: 8f1721db55f5e14744cdd8fbc0b5d9b90fb5f8ee (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
// Copyright 2009 the Sputnik authors.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
info: |
    The toString 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
es5id: 15.5.4.2_A2_T1
description: Checking if creating variable String.prototype.toString fails
---*/

var __toString = String.prototype.toString;

//////////////////////////////////////////////////////////////////////////////
//CHECK#1
if (typeof __toString !== "function") {
  $ERROR('#1: __toString = String.prototype.toString; typeof __toString === "function". Actual: typeof __toString ==='+typeof __toString ); 
}

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

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