Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Number / prototype / valueOf / S15.7.4.4_A2_T05.js
blob504b834cb7c6e7a6ee05fb913096a76a58e4b526
1 // Copyright 2009 the Sputnik authors.  All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 info: |
6     The valueOf function is not generic, it cannot be transferred
7     to other kinds of objects for use as a method and there is should be
8     a TypeError exception if its this value is not a Number object
9 es5id: 15.7.4.4_A2_T05
10 description: transferring to the other objects
11 ---*/
13 try {
14   var s1 = {
15     x: 1
16   };
17   s1.valueOf = Number.prototype.valueOf;
18   var v1 = s1.valueOf();
19   throw new Test262Error('#1: Number.prototype.valueOf on not a Number object should throw TypeError');
21 catch (e) {
22   assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true');
25 try {
26   var s2 = {
27     x: 1
28   };
29   s2.myValueOf = Number.prototype.valueOf;
30   var v2 = s2.myValueOf();
31   throw new Test262Error('#2: Number.prototype.valueOf on not a Number object should throw TypeError');
33 catch (e) {
34   assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true');
37 reportCompare(0, 0);