Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: @W-17310064 [LWS] Add TextDecoder to near-membrane maxPerfMode keys to fix "TypeError: parameter 1 is not of type 'ArrayBuffer'" #473

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading