Skip to content

Commit 64741fd

Browse files
authored
Merge pull request msgpack#24 from msgpack/workaround_for_ie_dataview
workround IE11 issues
2 parents 50b613f + 98b8d07 commit 64741fd

7 files changed

Lines changed: 48 additions & 11 deletions

File tree

codecov.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: 90%
6+
threshold: 1%
7+
patch: off

karma.conf.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ export default function configure(config: any) {
66
config.set({
77
customLaunchers: {
88
...sauceLaunchers,
9+
10+
// To debug it wih IE11,
11+
// Install `karma-virtualbox-ie11-launcher`,
12+
// and configure custom launchers like this:
13+
// IE11: {
14+
// base: "VirtualBoxIE11",
15+
// keepAlive: true,
16+
// vmName: "IE11 - Win10",
17+
// },
918
},
1019
sauceLabs,
1120
browsers: ["ChromeHeadless", "FirefoxHeadless"],

package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
"@types/node": "^11.13.10",
4747
"@typescript-eslint/eslint-plugin": "^1.8.0",
4848
"@typescript-eslint/parser": "^1.8.0",
49-
"assert": "github:browserify/commonjs-assert#sync-with-node-master",
49+
"assert": "^2.0.0",
5050
"core-js": "^3.0.1",
5151
"eslint": "^5.16.0",
5252
"eslint-config-prettier": "^4.2.0",
53-
"eslint-plugin-prettier": "^3.0.1",
53+
"eslint-plugin-prettier": "^3.1.0",
5454
"ieee754": "^1.1.13",
5555
"karma": "^4.1.0",
5656
"karma-chrome-launcher": "^2.2.0",

src/Decoder.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,21 @@ type StackState = StackArrayState | StackMapState;
2929
const HEAD_BYTE_REQUIRED = -1;
3030

3131
const EMPTY_VIEW = new DataView(new ArrayBuffer(0));
32-
const MORE_DATA = new RangeError("Insufficient data");
32+
33+
// IE11: Hack to support IE11.
34+
// IE11: Drop this hack and just use RangeError when IE11 is obsolete.
35+
export const DataViewIndexOutOfBoundsError: typeof Error = (() => {
36+
try {
37+
// IE11: The spec says it should throw RangeError,
38+
// IE11: but in IE11 it throws TypeError.
39+
EMPTY_VIEW.getInt8(0);
40+
} catch (e) {
41+
return e.constructor;
42+
}
43+
throw new Error("never reached");
44+
})();
45+
46+
const MORE_DATA = new DataViewIndexOutOfBoundsError("Insufficient data");
3347

3448
export class Decoder {
3549
totalPos = 0;
@@ -92,7 +106,7 @@ export class Decoder {
92106
object = this.decodeSync();
93107
decoded = true;
94108
} catch (e) {
95-
if (!(e instanceof RangeError)) {
109+
if (!(e instanceof DataViewIndexOutOfBoundsError)) {
96110
throw e; // rethrow
97111
}
98112
// fallthrough

test/edge-cases.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from "assert";
22
import { encode, decode, decodeAsync } from "../src";
3+
import { DataViewIndexOutOfBoundsError } from "../src/Decoder";
34

45
describe("edge cases", () => {
56
context("try to encode trycyclic refs", () => {
@@ -15,7 +16,7 @@ describe("edge cases", () => {
1516
context("try to encode non-encodable objects", () => {
1617
it("throws errors", () => {
1718
assert.throws(() => {
18-
encode(Symbol("this is a symbol!"));
19+
encode(() => {});
1920
}, /unrecognized object/i);
2021
});
2122
});
@@ -51,7 +52,8 @@ describe("edge cases", () => {
5152
0x92, // fixarray size=2
5253
0xc0, // nil
5354
]);
54-
}, RangeError);
55+
// [IE11] A raw error thrown by DataView
56+
}, DataViewIndexOutOfBoundsError);
5557
});
5658

5759
it("throws errors (asynchronous)", async () => {

test/karma-run.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// import "util" first,
2+
// because core-js breaks the util polyfll (https://github.com/browserify/node-util) on IE11.
3+
import "util";
4+
15
import "core-js";
26

37
const testsContext = (require as any).context(".", true, /\.test\.ts$/);

0 commit comments

Comments
 (0)