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

Expose File class globally #1051

Open
wants to merge 2 commits into
base: feature/add-missing-buffer-apis
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion CHANGELOG.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ unreleased:
- GH-1052 Dropped support for Node < v18
new features:
- GH-1032 Enhanced performance when operating on buffers in Node environment
- GH-1035 Added missing buffer APIs to expose a uniform interface across environments
- GH-1052 Added support URL, Encoding, File, Cryptography, and Stream globals
fixed bugs:
- GH-1036 Fixed `uncaughtException` event listener not being removed
- GH-1034 Fixed an issue where sandbox crashes for large response body
- GH-1035 Added missing buffer APIs to expose a uniform interface across environments
- GH-1052 Fixed an issue where script execution failed on Node > v22.3
chores:
- GH-1033 Update ci.yml to run coverage on latest node version
- GH-1032 Add support for configuring module resolver based on environment
Expand Down
2 changes: 2 additions & 0 deletions lib/sandbox/execute-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module.exports = function (scope, code, execution, console, timers, pmapi, onAss
// prepare the scope's environment variables
scope.import({
Buffer: require('buffer').Buffer,
// TODO: Remove this once it is added to Uniscope (node>=v20)
File: require('buffer').File,
// forward console
console: console,
// forward pm-api instance
Expand Down
16 changes: 16 additions & 0 deletions test/unit/sandbox-libraries/buffer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ describe('sandbox library - buffer', function () {
`, done);
});

it('should have same File implementation as global', function (done) {
context.execute(`
const assert = require('assert'),
bufferFile = require('buffer').File;
assert.strictEqual(File === bufferFile, true);
`, done);
});

it('should expose Blob class', function (done) {
context.execute(`
const assert = require('assert'),
Expand All @@ -270,4 +278,12 @@ describe('sandbox library - buffer', function () {
assert.strictEqual(blob.size, 11);
`, done);
});

it('should have same Blob implementation as global', function (done) {
context.execute(`
const assert = require('assert'),
bufferBlob = require('buffer').Blob;
assert.strictEqual(Blob === bufferBlob, true);
`, done);
});
});
Loading