From aaf2bb2751b90943bc1af2a26b00617c6f6d2564 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 8 Sep 2016 10:34:09 -0700 Subject: [PATCH] Add spec for deleting Buffer global in preload --- spec/api-browser-window-spec.js | 16 ++++++++++++++++ spec/fixtures/module/delete-buffer.js | 11 +++++++++++ 2 files changed, 27 insertions(+) create mode 100644 spec/fixtures/module/delete-buffer.js diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index ba8c979a9f8b..d86bfe228cb0 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -542,6 +542,22 @@ describe('browser-window module', function () { }) w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html')) }) + + it('can successfully delete the Buffer global', function (done) { + var preload = path.join(fixtures, 'module', 'delete-buffer.js') + ipcMain.once('answer', function (event, test) { + assert.equal(test.toString(), 'buffer') + done() + }) + w.destroy() + w = new BrowserWindow({ + show: false, + webPreferences: { + preload: preload + } + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html')) + }) }) describe('"node-integration" option', function () { diff --git a/spec/fixtures/module/delete-buffer.js b/spec/fixtures/module/delete-buffer.js new file mode 100644 index 000000000000..d88e8b57708d --- /dev/null +++ b/spec/fixtures/module/delete-buffer.js @@ -0,0 +1,11 @@ +const path = require('path') +const {remote} = require('electron') +const {Buffer} = window + +delete window.Buffer +delete global.Buffer + +// Test that remote.js doesn't use Buffer global +remote.require(path.join(__dirname, 'print_name.js')).echo(new Buffer('bar')) + +window.test = new Buffer('buffer')