From 240125f38b25bad7ad558182fb23f5494f637ff2 Mon Sep 17 00:00:00 2001 From: rhysd Date: Tue, 18 Feb 2020 21:57:40 +0900 Subject: [PATCH] fix(host): Add Buffer to global scope in sandbox (fixes #141) --- packages/integration-tests/src/factory.test.ts | 3 +++ packages/neovim/src/host/factory.ts | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/packages/integration-tests/src/factory.test.ts b/packages/integration-tests/src/factory.test.ts index a5d5e82b..1676cc44 100644 --- a/packages/integration-tests/src/factory.test.ts +++ b/packages/integration-tests/src/factory.test.ts @@ -38,6 +38,9 @@ describe('Plugin Factory (used by host)', () => { expect( await pluginObj.handleRequest('Global', 'function', ['loaded']) ).toEqual(true); + expect( + await pluginObj.handleRequest('Global', 'function', ['Buffer']) + ).not.toEqual(undefined); expect( await pluginObj.handleRequest('Global', 'function', ['process']) ).not.toContain(['chdir', 'exit']); diff --git a/packages/neovim/src/host/factory.ts b/packages/neovim/src/host/factory.ts index 989ed23f..be4ebfd7 100644 --- a/packages/neovim/src/host/factory.ts +++ b/packages/neovim/src/host/factory.ts @@ -99,6 +99,7 @@ export interface Sandbox { module: NodeModule; require: (p: string) => any; console: { [key in keyof Console]?: Function }; + Buffer: typeof Buffer; } function createSandbox(filename: string): Sandbox { @@ -151,6 +152,9 @@ function createSandbox(filename: string): Sandbox { sandbox.process.stdout = devNull; sandbox.process.stderr = devNull; + // Buffer is no longer an owned property of 'global' variable in Node.js v12 (#141) + sandbox.Buffer = global.Buffer; + return sandbox; }