Skip to content

Commit

Permalink
fix: @W-17310064 [LWS] Add TextDecoder to near-membrane maxPerfMode k…
Browse files Browse the repository at this point in the history
…eys to fix "TypeError: parameter 1 is not of type 'ArrayBuffer'"
  • Loading branch information
rwaldron committed Nov 25, 2024
1 parent 8fd3afa commit 6954b9d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/near-membrane-base/src/intrinsics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ function getESGlobalKeys(maxPerfMode: boolean) {
'Request',
'Response',
'SubtleCrypto',
'TextDecoder',
'TextEncoder',
'URL',
'XMLHttpRequest',
],
Expand Down
40 changes: 40 additions & 0 deletions test/membrane/binary-data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,46 @@ describe('Binary Data and maxPerfMode:', () => {
});
});

describe('TextDecoder:', () => {
beforeEach(createBaseLineMaxCompatModeEnvironment);

it('can decode from typed array', () => {
const env = createVirtualEnvironment(window, {
endowments: Object.getOwnPropertyDescriptors({ expect }),
});

env.evaluate(untrusted('text-decoder.js'));
});
it('can decode from typed array, when maxPerfMode is true', () => {
const env = createVirtualEnvironment(window, {
endowments: Object.getOwnPropertyDescriptors({ expect }),
maxPerfMode: true,
});

env.evaluate(untrusted('text-decoder.js'));
});
});

describe('TextEncoder:', () => {
beforeEach(createBaseLineMaxCompatModeEnvironment);

it('can encode into typed array', () => {
const env = createVirtualEnvironment(window, {
endowments: Object.getOwnPropertyDescriptors({ expect }),
});

env.evaluate(untrusted('text-encoder.js'));
});
it('can encode into typed array, when maxPerfMode is true', () => {
const env = createVirtualEnvironment(window, {
endowments: Object.getOwnPropertyDescriptors({ expect }),
maxPerfMode: true,
});

env.evaluate(untrusted('text-encoder.js'));
});
});

describe('FileSaver library:', () => {
beforeEach(createBaseLineMaxCompatModeEnvironment);

Expand Down
1 change: 1 addition & 0 deletions test/membrane/untrusted/binary-data/text-decoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
new TextDecoder().decode(Uint8Array.from('Hello World!'.split('').map(letter => letter.charCodeAt(0))));
1 change: 1 addition & 0 deletions test/membrane/untrusted/binary-data/text-encoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
new TextEncoder().encodeInto('hello', new Uint8Array(8), 0);

0 comments on commit 6954b9d

Please sign in to comment.