Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Date / prototype / toJSON / to-primitive-abrupt.js
blob767d8b8240b0ddcde03f7206ef504db24c19e613
1 // Copyright (C) 2019 Aleksey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-date.prototype.tojson
5 description: >
6   Abrupt completion from ToPrimitive.
7 info: |
8   Date.prototype.toJSON ( key )
10   [...]
11   2. Let tv be ? ToPrimitive(O, hint Number).
13   ToPrimitive ( input [ , PreferredType ] )
15   1. Assert: input is an ECMAScript language value.
16   2. If Type(input) is Object, then
17     [...]
18     g. Return ? OrdinaryToPrimitive(input, hint).
20   OrdinaryToPrimitive ( O, hint )
22   [...]
23   5. For each name in methodNames in List order, do
24     a. Let method be ? Get(O, name).
25     b. If IsCallable(method) is true, then
26       i. Let result be ? Call(method, O).
27       ii. If Type(result) is not Object, return result.
28   6. Throw a TypeError exception.
29 ---*/
31 var toJSON = Date.prototype.toJSON;
32 var getAbrupt = {
33   get valueOf() {
34     throw new Test262Error();
35   },
38 assert.throws(Test262Error, function() {
39   toJSON.call(getAbrupt);
40 });
42 var callAbrupt = {
43   toString: function() {
44     throw new Test262Error();
45   },
48 assert.throws(Test262Error, function() {
49   toJSON.call(callAbrupt);
50 });
52 var notCoercible = Object.create(null);
54 assert.throws(TypeError, function() {
55   toJSON.call(notCoercible);
56 });
58 reportCompare(0, 0);