Skip to content

Commit

Permalink
fix(host): Add Buffer to global scope in sandbox (fixes #141) (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd authored Feb 18, 2020
1 parent 289d40f commit 37a5a6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/integration-tests/src/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
4 changes: 4 additions & 0 deletions packages/neovim/src/host/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 37a5a6e

Please sign in to comment.