Introduce Javascript controls (#4076)

* Introduce Javascript controls

This allows power-users to perform intricate transformations on data and
objects using javascript code.

The operations allowed are "sanboxed" or limited using node's vm
`runInNewContext`
https://nodejs.org/api/vm.html#vm_vm_runinnewcontext_code_sandbox_options

For now I'm only enabling in the line chart visualization, but the plan
would be to go towards offering more power to people who can write some
JS moving forward.

* Not applied
This commit is contained in:
Maxime Beauchemin
2017-12-20 21:24:35 -08:00
committed by GitHub
parent b4909f2d03
commit 69195f8d2d
6 changed files with 87 additions and 8 deletions

View File

@@ -0,0 +1,17 @@
import { it, describe } from 'mocha';
import { expect } from 'chai';
import sandboxedEval from '../../../javascripts/modules/sandbox';
describe('sandboxedEval', () => {
it('works like a basic eval', () => {
expect(sandboxedEval('100')).to.equal(100);
expect(sandboxedEval('v => v * 2')(5)).to.equal(10);
});
it('d3 is in context and works', () => {
expect(sandboxedEval("l => _.find(l, s => s === 'bar')")(['foo', 'bar'])).to.equal('bar');
});
it('passes context as expected', () => {
expect(sandboxedEval('foo', { foo: 'bar' })).to.equal('bar');
});
});