From 9a1acca8b6949422730e1588a21cc562d55491d9 Mon Sep 17 00:00:00 2001 From: Appurva Murawat Date: Wed, 25 Sep 2024 01:40:12 +0530 Subject: [PATCH] Expose `File` class globally --- CHANGELOG.yaml | 1 + lib/sandbox/execute-context.js | 2 ++ test/unit/sandbox-libraries/buffer.test.js | 16 ++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index 7d0b9bd8..92ef0b3a 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -4,6 +4,7 @@ unreleased: 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-1051 Exposed `File` globally 5.1.1: date: 2024-08-01 diff --git a/lib/sandbox/execute-context.js b/lib/sandbox/execute-context.js index 0932091c..f58e2490 100644 --- a/lib/sandbox/execute-context.js +++ b/lib/sandbox/execute-context.js @@ -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 diff --git a/test/unit/sandbox-libraries/buffer.test.js b/test/unit/sandbox-libraries/buffer.test.js index 2f4d08eb..899bea1f 100644 --- a/test/unit/sandbox-libraries/buffer.test.js +++ b/test/unit/sandbox-libraries/buffer.test.js @@ -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'), @@ -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); + }); });