diff --git a/packages/near-membrane-base/src/intrinsics.ts b/packages/near-membrane-base/src/intrinsics.ts index 6edb1c3a..b425aaff 100644 --- a/packages/near-membrane-base/src/intrinsics.ts +++ b/packages/near-membrane-base/src/intrinsics.ts @@ -124,6 +124,8 @@ function getESGlobalKeys(maxPerfMode: boolean) { 'Request', 'Response', 'SubtleCrypto', + 'TextDecoder', + 'TextEncoder', 'URL', 'XMLHttpRequest', ], diff --git a/test/membrane/binary-data.spec.js b/test/membrane/binary-data.spec.js index b1bcd680..4281f274 100644 --- a/test/membrane/binary-data.spec.js +++ b/test/membrane/binary-data.spec.js @@ -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); diff --git a/test/membrane/untrusted/binary-data/text-decoder.js b/test/membrane/untrusted/binary-data/text-decoder.js new file mode 100644 index 00000000..b0eb8647 --- /dev/null +++ b/test/membrane/untrusted/binary-data/text-decoder.js @@ -0,0 +1 @@ +new TextDecoder().decode(Uint8Array.from('Hello World!'.split('').map(letter => letter.charCodeAt(0)))); diff --git a/test/membrane/untrusted/binary-data/text-encoder.js b/test/membrane/untrusted/binary-data/text-encoder.js new file mode 100644 index 00000000..6023c4c0 --- /dev/null +++ b/test/membrane/untrusted/binary-data/text-encoder.js @@ -0,0 +1 @@ +new TextEncoder().encodeInto('hello', new Uint8Array(8), 0); \ No newline at end of file