Skip to content

Commit 87eb0c5

Browse files
Snuffleupagusbackstroke-bot
authored andcommitted
Convert the various image decoder ...Errors to classes extending BaseException (PR 11185 follow-up)
Somehow I missed these in PR 11185, but there's no good reason not to convert them as well.
1 parent 2216937 commit 87eb0c5

File tree

3 files changed

+22
-54
lines changed

3 files changed

+22
-54
lines changed

src/core/jbig2.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { log2, readInt8, readUint16, readUint32, shadow } from '../shared/util';
16+
import {
17+
BaseException, log2, readInt8, readUint16, readUint32, shadow
18+
} from '../shared/util';
1719
import { ArithmeticDecoder } from './arithmetic_decoder';
1820
import { CCITTFaxDecoder } from './ccitt';
1921

20-
let Jbig2Error = (function Jbig2ErrorClosure() {
21-
function Jbig2Error(msg) {
22-
this.message = 'JBIG2 error: ' + msg;
22+
class Jbig2Error extends BaseException {
23+
constructor(msg) {
24+
super(`JBIG2 error: ${msg}`);
2325
}
24-
25-
Jbig2Error.prototype = new Error();
26-
Jbig2Error.prototype.name = 'Jbig2Error';
27-
Jbig2Error.constructor = Jbig2Error;
28-
29-
return Jbig2Error;
30-
})();
26+
}
3127

3228
var Jbig2Image = (function Jbig2ImageClosure() {
3329
// Utility data structures

src/core/jpg.js

+10-32
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,22 @@
1414
*/
1515
/* eslint-disable no-multi-spaces */
1616

17-
import { assert, warn } from '../shared/util';
17+
import { assert, BaseException, warn } from '../shared/util';
1818

19-
let JpegError = (function JpegErrorClosure() {
20-
function JpegError(msg) {
21-
this.message = 'JPEG error: ' + msg;
19+
class JpegError extends BaseException {
20+
constructor(msg) {
21+
super(`JPEG error: ${msg}`);
2222
}
23+
}
2324

24-
JpegError.prototype = new Error();
25-
JpegError.prototype.name = 'JpegError';
26-
JpegError.constructor = JpegError;
27-
28-
return JpegError;
29-
})();
30-
31-
let DNLMarkerError = (function DNLMarkerErrorClosure() {
32-
function DNLMarkerError(message, scanLines) {
33-
this.message = message;
25+
class DNLMarkerError extends BaseException {
26+
constructor(message, scanLines) {
27+
super(message);
3428
this.scanLines = scanLines;
3529
}
30+
}
3631

37-
DNLMarkerError.prototype = new Error();
38-
DNLMarkerError.prototype.name = 'DNLMarkerError';
39-
DNLMarkerError.constructor = DNLMarkerError;
40-
41-
return DNLMarkerError;
42-
})();
43-
44-
let EOIMarkerError = (function EOIMarkerErrorClosure() {
45-
function EOIMarkerError(message) {
46-
this.message = message;
47-
}
48-
49-
EOIMarkerError.prototype = new Error();
50-
EOIMarkerError.prototype.name = 'EOIMarkerError';
51-
EOIMarkerError.constructor = EOIMarkerError;
52-
53-
return EOIMarkerError;
54-
})();
32+
class EOIMarkerError extends BaseException { }
5533

5634
/**
5735
* This code was forked from https://github.com/notmasteryet/jpgjs.

src/core/jpx.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,15 @@
1414
*/
1515

1616
import {
17-
info, log2, readUint16, readUint32, warn
17+
BaseException, info, log2, readUint16, readUint32, warn
1818
} from '../shared/util';
1919
import { ArithmeticDecoder } from './arithmetic_decoder';
2020

21-
let JpxError = (function JpxErrorClosure() {
22-
function JpxError(msg) {
23-
this.message = 'JPX error: ' + msg;
21+
class JpxError extends BaseException {
22+
constructor(msg) {
23+
super(`JPX error: ${msg}`);
2424
}
25-
26-
JpxError.prototype = new Error();
27-
JpxError.prototype.name = 'JpxError';
28-
JpxError.constructor = JpxError;
29-
30-
return JpxError;
31-
})();
25+
}
3226

3327
var JpxImage = (function JpxImageClosure() {
3428
// Table E.1

0 commit comments

Comments
 (0)