Commit 4a440a79 authored by Romain Casati's avatar Romain Casati
Browse files

Simple JS kernel.

parent 63486081
......@@ -3,7 +3,7 @@ var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
const kernels = ['python'];
const kernels = ['python', 'javascript'];
function gulp_task_kernel(kernel_name) {
return gulp.task(kernel_name, function() {
......
(function (root, factory) {
// requirejs?
if (typeof define === 'function') {
define(['./basthon_base'], factory);
// TypeScript?
} else if (typeof exports === 'object') {
module.exports = factory();
// default goes to global namespace
} else {
root.Basthon = factory(BasthonBase);
}
}(this, function (BasthonBase) {
'use strict';
class Basthon extends BasthonBase {
constructor() {
super();
this.execution_count = 0;
this.context = {Basthon: undefined,
Jupyter: undefined,
window: undefined,};
};
version () { return "0.0.0" };
language () { return "Javascript"; };
async launch () { await this.pageLoad(); };
eval (code) {
try {
// using context to hide several global variables
return window.eval(`with(Basthon.context) { ${code} }`);
} catch (e) {
if (e instanceof SyntaxError)
return (new Function(`with(this) { ${code} }`)).call(this.context);
throw e;
}
};
async evalAsync (code, outCallback, errCallback, data=null) {
// force interactivity in all modes
data.interactive = true;
// backup
const console_log = console.log;
const console_error = console.error;
console.log = outCallback;
console.error = errCallback;
// evaluation
let result = this.eval(code);
// restoration
console.log = console_log;
console.error = console_error;
// return result
if( typeof result !== 'undefined' )
result = {'text/plain': JSON.stringify(result)};
return [result, ++this.execution_count];
};
ps1 () { return " js> "; };
ps2 () { return "...> "; };
restart () { };
more (source) { return false; };
complete (code) { return []; };
}
return new Basthon();
}));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment