| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a0a45fc commit e42ab10
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,18 +90,35 @@ if (common.hasIntl) { | |||
| 90 | 90 | } | |
| 91 | 91 | ||
| 92 | 92 | { | |
| 93 | - const fn = TextDecoder.prototype[inspect]; | ||
| 94 | - assert.doesNotThrow(() => { | ||
| 95 | - fn.call(new TextDecoder(), Infinity, {}); | ||
| 96 | - }); | ||
| 97 | - | ||
| 98 | - [{}, [], true, 1, '', new TextEncoder()].forEach((i) => { | ||
| 99 | - assert.throws(() => fn.call(i, Infinity, {}), | ||
| 100 | - common.expectsError({ | ||
| 101 | - code: 'ERR_INVALID_THIS', | ||
| 102 | - type: TypeError, | ||
| 103 | - message: 'Value of "this" must be of type TextDecoder' | ||
| 104 | - })); | ||
| 93 | + const inspectFn = TextDecoder.prototype[inspect]; | ||
| 94 | + const decodeFn = TextDecoder.prototype.decode; | ||
| 95 | + const { | ||
| 96 | + encoding: { get: encodingGetter }, | ||
| 97 | + fatal: { get: fatalGetter }, | ||
| 98 | + ignoreBOM: { get: ignoreBOMGetter }, | ||
| 99 | + } = Object.getOwnPropertyDescriptors(TextDecoder.prototype); | ||
| 100 | + | ||
| 101 | + const instance = new TextDecoder(); | ||
| 102 | + | ||
| 103 | + const expectedError = { | ||
| 104 | + code: 'ERR_INVALID_THIS', | ||
| 105 | + type: TypeError, | ||
| 106 | + message: 'Value of "this" must be of type TextDecoder' | ||
| 107 | + }; | ||
| 108 | + | ||
| 109 | + assert.doesNotThrow(() => inspectFn.call(instance, Infinity, {})); | ||
| 110 | + assert.doesNotThrow(() => decodeFn.call(instance)); | ||
| 111 | + assert.doesNotThrow(() => encodingGetter.call(instance)); | ||
| 112 | + assert.doesNotThrow(() => fatalGetter.call(instance)); | ||
| 113 | + assert.doesNotThrow(() => ignoreBOMGetter.call(instance)); | ||
| 114 | + | ||
| 115 | + const invalidThisArgs = [{}, [], true, 1, '', new TextEncoder()]; | ||
| 116 | + invalidThisArgs.forEach((i) => { | ||
| 117 | + common.expectsError(() => inspectFn.call(i, Infinity, {}), expectedError); | ||
| 118 | + common.expectsError(() => decodeFn.call(i), expectedError); | ||
| 119 | + common.expectsError(() => encodingGetter.call(i), expectedError); | ||
| 120 | + common.expectsError(() => fatalGetter.call(i), expectedError); | ||
| 121 | + common.expectsError(() => ignoreBOMGetter.call(i), expectedError); | ||
| 105 | 122 | }); | |
| 106 | 123 | } | |
| 107 | 124 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,17 +35,27 @@ assert(TextEncoder); | |||
| 35 | 35 | } | |
| 36 | 36 | ||
| 37 | 37 | { | |
| 38 | - const fn = TextEncoder.prototype[inspect]; | ||
| 39 | - assert.doesNotThrow(() => { | ||
| 40 | - fn.call(new TextEncoder(), Infinity, {}); | ||
| 41 | - }); | ||
| 42 | - | ||
| 43 | - [{}, [], true, 1, '', new TextDecoder()].forEach((i) => { | ||
| 44 | - assert.throws(() => fn.call(i, Infinity, {}), | ||
| 45 | - common.expectsError({ | ||
| 46 | - code: 'ERR_INVALID_THIS', | ||
| 47 | - type: TypeError, | ||
| 48 | - message: 'Value of "this" must be of type TextEncoder' | ||
| 49 | - })); | ||
| 38 | + const inspectFn = TextEncoder.prototype[inspect]; | ||
| 39 | + const encodeFn = TextEncoder.prototype.encode; | ||
| 40 | + const encodingGetter = | ||
| 41 | + Object.getOwnPropertyDescriptor(TextEncoder.prototype, 'encoding').get; | ||
| 42 | + | ||
| 43 | + const instance = new TextEncoder(); | ||
| 44 | + | ||
| 45 | + const expectedError = { | ||
| 46 | + code: 'ERR_INVALID_THIS', | ||
| 47 | + type: TypeError, | ||
| 48 | + message: 'Value of "this" must be of type TextEncoder' | ||
| 49 | + }; | ||
| 50 | + | ||
| 51 | + assert.doesNotThrow(() => inspectFn.call(instance, Infinity, {})); | ||
| 52 | + assert.doesNotThrow(() => encodeFn.call(instance)); | ||
| 53 | + assert.doesNotThrow(() => encodingGetter.call(instance)); | ||
| 54 | + | ||
| 55 | + const invalidThisArgs = [{}, [], true, 1, '', new TextDecoder()]; | ||
| 56 | + invalidThisArgs.forEach((i) => { | ||
| 57 | + common.expectsError(() => inspectFn.call(i, Infinity, {}), expectedError); | ||
| 58 | + common.expectsError(() => encodeFn.call(i), expectedError); | ||
| 59 | + common.expectsError(() => encodingGetter.call(i), expectedError); | ||
| 50 | 60 | }); | |
| 51 | 61 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments