2 <script src=
"../../resources/js-test.js"></script>
3 <div id=
"description"></div>
4 <div id=
"console"></div>
6 // http://heycam.github.io/webidl/#es-operations
7 description('Operations that return a Promise type should handle exceptions ' +
8 'by returning a rejected Promise with the exception.')
10 window
.jsTestIsAsync
= true;
14 function shouldBeRejected(promise
, message
) {
15 return promise
.then(function() {
16 testFailed('Resolved unexpectedly: ' + message
);
19 testPassed('Rejected as expected: ' + message
);
20 shouldBeTrue('reason instanceof Error');
25 function shouldBeResolved(promise
, message
) {
26 return promise
.then(function() {
27 testPassed('Resolved as expected: ' + message
);
29 testFailed('Rejected unexpectedly: ' + message
);
31 shouldBeTrue('reason instanceof Error');
36 var check
= internals
.promiseCheck
.bind(internals
);
37 var check2
= internals
.promiseCheckWithoutExceptionState
.bind(internals
);
38 var check3
= internals
.promiseCheckRange
.bind(internals
);
39 var check4
= internals
.promiseCheckOverload
.bind(internals
);
41 Promise
.resolve().then(function() {
42 return shouldBeRejected(check(), 'no arguments');
44 return shouldBeResolved(check(3, true, {}, '', ['']), 'valid arguments');
46 return shouldBeResolved(check(null, true, {}, '', []), 'convert(long)');
48 return shouldBeResolved(check(3, {}, {}, '', []), 'convert(boolean)');
50 return shouldBeRejected(check(3, true, 3, '', []), 'type error(Dictionary)');
52 return shouldBeResolved(check(3, true, {}, {}, []), 'convert(String)');
55 toString: function() {
56 throw Error('Thrown from toString');
59 return shouldBeRejected(check(3, true, {}, x
, []), 'conversion error(toString)');
62 toString: function() {
63 throw Error('Thrown from toString');
66 return shouldBeRejected(check(3, true, {}, '', [x
]), 'conversion error([String])');
68 return shouldBeRejected(check(3, false, {}, '', []), 'rejected by the impl');
70 return shouldBeRejected(check2(), 'no arguments');
72 return shouldBeResolved(check2({}, '', '', ''), 'valid arguments');
74 return shouldBeResolved(check2({}, ''), 'valid arguments');
76 return shouldBeRejected(check2(3, ''), 'type error(Dictionary)');
78 return shouldBeResolved(check2({}, '', {}, 3), 'convert(String...)');
81 toString: function() {
82 throw Error('Thrown from toString');
85 return shouldBeRejected(check2({}, '', '', x
), 'conversion error(String...)');
87 return shouldBeRejected(check3(-1), 'range error(octet)');
89 return shouldBeResolved(check4(location
), 'valid argument (Location)');
91 return shouldBeResolved(check4(document
), 'valid argument (Document)');
93 return shouldBeResolved(check4(location
, 0, 0), 'valid argument (Location, long, long)');
95 return shouldBeRejected(check4({}), 'type error (Object)');
97 return shouldBeRejected(check4(location
, 0), 'type error (Location, long)');
98 }).then(undefined, function(e
) {
99 testFailed('An exception is thrown from a method');
101 }).then(finishJSTest
, finishJSTest
);