|
1 // Copyright 2012 Mozilla Corporation. All rights reserved. |
|
2 // This code is governed by the BSD license found in the LICENSE file. |
|
3 |
|
4 /** |
|
5 * @description Tests that Intl.NumberFormat.prototype functions throw a |
|
6 * TypeError if called on a non-object value or an object that hasn't been |
|
7 * initialized as a NumberFormat. |
|
8 * @author Norbert Lindenberg |
|
9 */ |
|
10 |
|
11 var functions = { |
|
12 "format getter": Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get, |
|
13 resolvedOptions: Intl.NumberFormat.prototype.resolvedOptions |
|
14 }; |
|
15 var invalidTargets = [undefined, null, true, 0, "NumberFormat", [], {}]; |
|
16 |
|
17 Object.getOwnPropertyNames(functions).forEach(function (functionName) { |
|
18 var f = functions[functionName]; |
|
19 invalidTargets.forEach(function (target) { |
|
20 var error; |
|
21 try { |
|
22 f.call(target); |
|
23 } catch (e) { |
|
24 error = e; |
|
25 } |
|
26 if (error === undefined) { |
|
27 $ERROR("Calling " + functionName + " on " + target + " was not rejected."); |
|
28 } else if (error.name !== "TypeError") { |
|
29 $ERROR("Calling " + functionName + " on " + target + " was rejected with wrong error " + error.name + "."); |
|
30 } |
|
31 }); |
|
32 }); |
|
33 |