File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,20 @@ type StackState = StackArrayState | StackMapState;
2929const HEAD_BYTE_REQUIRED = - 1 ;
3030
3131const EMPTY_VIEW = new DataView ( new ArrayBuffer ( 0 ) ) ;
32- const MORE_DATA = new RangeError ( "Insufficient data" ) ;
32+
33+ // IE11: Just use RangeError when IE11 is obsolete.
34+ export const DataViewIndexOutOfBoundsError : typeof Error = ( ( ) => {
35+ try {
36+ // IE11: The spec says it should throw RangeError,
37+ // IE11: but in IE11 it throws TypeError.
38+ EMPTY_VIEW . getInt8 ( 0 ) ;
39+ } catch ( e ) {
40+ return e . constructor ;
41+ }
42+ throw new Error ( "never reached" ) ;
43+ } ) ( ) ;
44+
45+ const MORE_DATA = new DataViewIndexOutOfBoundsError ( "Insufficient data" ) ;
3346
3447export class Decoder {
3548 totalPos = 0 ;
@@ -92,7 +105,7 @@ export class Decoder {
92105 object = this . decodeSync ( ) ;
93106 decoded = true ;
94107 } catch ( e ) {
95- if ( ! ( e instanceof RangeError ) ) {
108+ if ( ! ( e instanceof DataViewIndexOutOfBoundsError ) ) {
96109 throw e ; // rethrow
97110 }
98111 // fallthrough
Original file line number Diff line number Diff line change 11import assert from "assert" ;
22import { encode , decode , decodeAsync } from "../src" ;
3+ import { DataViewIndexOutOfBoundsError } from "../src/Decoder" ;
34
45describe ( "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 } , / u n r e c o g n i z e d o b j e c t / 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 ( ) => {
You can’t perform that action at this time.
0 commit comments