@live-codes/browser-compilers 0.4.10 → 0.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,119 @@
1
+ export const svgbobWasm = async (wasmUrl) => {
2
+ var svgbob_wasm_bg_default =
3
+ wasmUrl || 'https://cdn.jsdelivr.net/npm/svgbob-wasm/svgbob_wasm_bg.wasm';
4
+
5
+ var imports = {};
6
+ async function loadWasm(module3, imports2) {
7
+ if (typeof module3 === 'string') {
8
+ const moduleRequest = await fetch(module3);
9
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
10
+ try {
11
+ return await WebAssembly.instantiateStreaming(moduleRequest, imports2);
12
+ } catch (e) {
13
+ if (moduleRequest.headers.get('Content-Type') != 'application/wasm') {
14
+ console.warn(e);
15
+ } else {
16
+ throw e;
17
+ }
18
+ }
19
+ }
20
+ module3 = await moduleRequest.arrayBuffer();
21
+ }
22
+ return await WebAssembly.instantiate(module3, imports2);
23
+ }
24
+ var { instance, module: module2 } = await loadWasm(svgbob_wasm_bg_default, imports);
25
+ var memory = instance.exports.memory;
26
+ var convert_string = instance.exports.convert_string;
27
+ var __wbindgen_export_0 = instance.exports.__wbindgen_export_0;
28
+ var __wbindgen_malloc = instance.exports.__wbindgen_malloc;
29
+ var __wbindgen_realloc = instance.exports.__wbindgen_realloc;
30
+ var __wbindgen_free = instance.exports.__wbindgen_free;
31
+
32
+ var WASM_VECTOR_LEN = 0;
33
+ var cachegetUint8Memory0 = null;
34
+ function getUint8Memory0() {
35
+ if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== memory.buffer) {
36
+ cachegetUint8Memory0 = new Uint8Array(memory.buffer);
37
+ }
38
+ return cachegetUint8Memory0;
39
+ }
40
+ var lTextEncoder =
41
+ typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
42
+ var cachedTextEncoder = new lTextEncoder('utf-8');
43
+ var encodeString =
44
+ typeof cachedTextEncoder.encodeInto === 'function'
45
+ ? function (arg, view) {
46
+ return cachedTextEncoder.encodeInto(arg, view);
47
+ }
48
+ : function (arg, view) {
49
+ const buf = cachedTextEncoder.encode(arg);
50
+ view.set(buf);
51
+ return {
52
+ read: arg.length,
53
+ written: buf.length,
54
+ };
55
+ };
56
+ function passStringToWasm0(arg, malloc, realloc) {
57
+ if (realloc === void 0) {
58
+ const buf = cachedTextEncoder.encode(arg);
59
+ const ptr2 = malloc(buf.length);
60
+ getUint8Memory0()
61
+ .subarray(ptr2, ptr2 + buf.length)
62
+ .set(buf);
63
+ WASM_VECTOR_LEN = buf.length;
64
+ return ptr2;
65
+ }
66
+ let len = arg.length;
67
+ let ptr = malloc(len);
68
+ const mem = getUint8Memory0();
69
+ let offset = 0;
70
+ for (; offset < len; offset++) {
71
+ const code = arg.charCodeAt(offset);
72
+ if (code > 127) break;
73
+ mem[ptr + offset] = code;
74
+ }
75
+ if (offset !== len) {
76
+ if (offset !== 0) {
77
+ arg = arg.slice(offset);
78
+ }
79
+ ptr = realloc(ptr, len, (len = offset + arg.length * 3));
80
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
81
+ const ret = encodeString(arg, view);
82
+ offset += ret.written;
83
+ }
84
+ WASM_VECTOR_LEN = offset;
85
+ return ptr;
86
+ }
87
+ var cachegetInt32Memory0 = null;
88
+ function getInt32Memory0() {
89
+ if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== memory.buffer) {
90
+ cachegetInt32Memory0 = new Int32Array(memory.buffer);
91
+ }
92
+ return cachegetInt32Memory0;
93
+ }
94
+ var lTextDecoder =
95
+ typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
96
+ var cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
97
+ cachedTextDecoder.decode();
98
+ function getStringFromWasm0(ptr, len) {
99
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
100
+ }
101
+ function convert_string2(data) {
102
+ try {
103
+ const retptr = __wbindgen_export_0.value - 16;
104
+ __wbindgen_export_0.value = retptr;
105
+ var ptr0 = passStringToWasm0(data, __wbindgen_malloc, __wbindgen_realloc);
106
+ var len0 = WASM_VECTOR_LEN;
107
+ convert_string(retptr, ptr0, len0);
108
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
109
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
110
+ return getStringFromWasm0(r0, r1);
111
+ } finally {
112
+ __wbindgen_export_0.value += 16;
113
+ __wbindgen_free(r0, r1);
114
+ }
115
+ }
116
+ return {
117
+ convert_string: convert_string2,
118
+ };
119
+ };
@@ -1,96 +1,85 @@
1
+ // @ts-nocheck
1
2
  // based on https://github.com/MikeRalphson/turbopascal/blob/master/tpc.js
2
3
  const turbopascal = {
3
- compiler: new Promise((resolve) => {
4
- requirejs.config({
5
- baseUrl: 'https://cdn.jsdelivr.net/npm/turbopascal@1.0.3',
6
- paths: {
7
- underscore: 'https://cdn.jsdelivr.net/npm/underscore@1.13.2/underscore-umd.min',
8
- },
9
- });
4
+ createCompiler: (options = {}) =>
5
+ new Promise((resolve) => {
6
+ const inputCallback =
7
+ options.inputCallback ||
8
+ ((callback) => {
9
+ const input = window.prompt('please supply the input');
10
+ callback(input);
11
+ });
12
+ const outputCallback = options.outputCallback || console.log;
13
+ const errorCallback = options.errorCallback || console.warn;
10
14
 
11
- require([
12
- 'Stream',
13
- 'Lexer',
14
- 'CommentStripper',
15
- 'Parser',
16
- 'PascalError',
17
- 'Compiler',
18
- 'Machine',
19
- 'SymbolTable',
20
- ], function (
21
- Stream,
22
- Lexer,
23
- CommentStripper,
24
- Parser,
25
- PascalError,
26
- Compiler,
27
- Machine,
28
- SymbolTable,
29
- ) {
30
- function compile(source, run, DEBUG_TRACE) {
31
- let self = this;
15
+ requirejs.config({
16
+ baseUrl: 'https://cdn.jsdelivr.net/npm/turbopascal@1.0.3',
17
+ paths: {
18
+ underscore: 'https://cdn.jsdelivr.net/npm/underscore@1.13.2/underscore-umd.min',
19
+ },
20
+ });
32
21
 
33
- if (!source) {
34
- return;
35
- }
36
-
37
- let stream = new Stream(source);
38
- let lexer = new CommentStripper(new Lexer(stream));
39
- let parser = new Parser(lexer);
22
+ require([
23
+ 'Stream',
24
+ 'Lexer',
25
+ 'CommentStripper',
26
+ 'Parser',
27
+ 'Compiler',
28
+ 'Machine',
29
+ 'SymbolTable',
30
+ ], function (Stream, Lexer, CommentStripper, Parser, Compiler, Machine, SymbolTable) {
31
+ function compile(source, run, DEBUG_TRACE) {
32
+ let result = { parsed: false, compiled: false };
33
+ if (!source) return result;
40
34
 
41
- let result = { parsed: false, compiled: false };
35
+ let stream = new Stream(source);
36
+ let lexer = new CommentStripper(new Lexer(stream));
37
+ let parser = new Parser(lexer);
42
38
 
43
- try {
44
- // Create the symbol table of built-in constants, functions, and procedures.
45
- let builtinSymbolTable = SymbolTable.makeBuiltinSymbolTable();
39
+ try {
40
+ // Create the symbol table of built-in constants, functions, and procedures.
41
+ let builtinSymbolTable = SymbolTable.makeBuiltinSymbolTable();
46
42
 
47
- // Parse the program into a parse tree. Create the symbol table as we go.
48
- let root = parser.parse(builtinSymbolTable);
49
- result.tree = root.print('');
50
- result.parsed = true;
43
+ // Parse the program into a parse tree. Create the symbol table as we go.
44
+ let root = parser.parse(builtinSymbolTable);
45
+ result.tree = root.print('');
46
+ result.parsed = true;
51
47
 
52
- // Compile to bytecode.
53
- let compiler = new Compiler();
54
- let bytecode = compiler.compile(root);
55
- result.compiled = true;
56
- result.bytecode = bytecode;
57
- result.pSrc = bytecode.print();
48
+ // Compile to bytecode.
49
+ let compiler = new Compiler();
50
+ let bytecode = compiler.compile(root);
51
+ result.compiled = true;
52
+ result.bytecode = bytecode;
53
+ result.pSrc = bytecode.print();
58
54
 
59
- if (run) {
60
- // Execute the bytecode.
61
- let machine = new Machine(bytecode, this.keyboard);
62
- if (DEBUG_TRACE) {
63
- machine.setDebugCallback(function (state) {
64
- $state.append(state + '\\n');
55
+ if (run) {
56
+ // Execute the bytecode.
57
+ let machine = new Machine(bytecode, this.keyboard);
58
+ if (DEBUG_TRACE) {
59
+ machine.setDebugCallback(function (state) {
60
+ $state.append(state + '\\n');
61
+ });
62
+ }
63
+ machine.setFinishCallback(function (runningTime) {});
64
+ machine.setOutputCallback(function (line) {
65
+ outputCallback(line);
65
66
  });
66
- }
67
- machine.setFinishCallback(function (runningTime) {});
68
- machine.setOutputCallback(function (line) {
69
- console.log(line);
70
- });
71
- machine.setOutChCallback(function (line) {
72
- console.log(line);
73
- });
74
- machine.setInputCallback(function (callback) {
75
- self.screen.addCursor();
76
- self._setInputMode(INPUT_STRING, function (line) {
77
- self._setInputMode(INPUT_RUNNING);
78
- callback(line);
67
+ machine.setOutChCallback(function (line) {
68
+ outputCallback(line);
79
69
  });
80
- });
81
- machine.run();
82
- }
83
- } catch (e) {
84
- console.warn(e.message);
85
- // Print parsing errors.
86
- if (e instanceof PascalError) {
87
- console.warn(e.getMessage());
70
+ machine.setInputCallback(function (callback) {
71
+ inputCallback(callback);
72
+ });
73
+ machine.run();
74
+ }
75
+ } catch (e) {
76
+ // Print errors.
77
+ const msg = e.getMessage() || e.message || e;
78
+ errorCallback(msg);
88
79
  }
89
- console.warn(e.stack);
80
+ return result;
90
81
  }
91
- return result;
92
- }
93
- resolve(compile);
94
- });
95
- }),
82
+ resolve(compile);
83
+ });
84
+ }),
96
85
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-codes/browser-compilers",
3
- "version": "0.4.10",
3
+ "version": "0.4.14",
4
4
  "description": "Compilers that run in the browser, for use in livecodes.io",
5
5
  "author": "Hatem Hosny",
6
6
  "license": "MIT",
@@ -9,7 +9,7 @@
9
9
  "url": "https://github.com/live-codes/browser-compilers"
10
10
  },
11
11
  "scripts": {
12
- "start": "live-server dist --cors",
12
+ "start": "live-server dist --port=8081 --no-browser --cors",
13
13
  "build": "run-s clean build:vendors copy:types",
14
14
  "build:vendors": "node ./scripts/vendors.js",
15
15
  "copy:types": "recursive-copy vendor_modules/types dist/types",
@@ -39,6 +39,7 @@
39
39
  "react": "17.0.2",
40
40
  "react-dom": "17.0.2",
41
41
  "react-native-web": "0.17.5",
42
+ "sass": "1.49.7",
42
43
  "svelte": "3.44.1",
43
44
  "windicss": "3.2.1"
44
45
  },
@@ -51,7 +52,6 @@
51
52
  "autoprefixer": "10.4.0",
52
53
  "cz-conventional-changelog": "3.2.0",
53
54
  "esbuild": "0.11.12",
54
- "esbuild-plugin-replace": "1.0.6",
55
55
  "eslint": "7.32.0",
56
56
  "eslint-config-prettier": "6.11.0",
57
57
  "eslint-plugin-import": "2.20.2",
@@ -64,6 +64,28 @@ entryFiles.forEach(async (file) => {
64
64
  await parcelBundler.bundle();
65
65
  });
66
66
 
67
+ // sass
68
+ fs.readFile(path.resolve('node_modules/sass/sass.dart.js'), 'utf8', function (err, data) {
69
+ if (err) return console.log(err);
70
+
71
+ var result = data.replace(
72
+ 'var self = Object.create(dartNodePreambleSelf);',
73
+ 'var self = window;',
74
+ );
75
+
76
+ fs.writeFile(path.resolve('node_modules/sass/sass.dart.js'), result, 'utf8', function (err) {
77
+ if (err) return console.log(err);
78
+
79
+ esbuild.build({
80
+ ...baseOptions,
81
+ entryPoints: ['vendor_modules/imports/sass.ts'],
82
+ outfile: 'dist/sass/sass.js',
83
+ globalName: 'sass',
84
+ plugins: nodePolyfills,
85
+ });
86
+ });
87
+ });
88
+
67
89
  // Less
68
90
  esbuild.buildSync({
69
91
  ...baseOptions,
@@ -238,3 +260,21 @@ fs.copyFileSync(
238
260
  path.resolve(vendor_modules_src + '/turbopascal/turbopascal.js'),
239
261
  path.resolve(targetDir + '/turbopascal/turbopascal.js'),
240
262
  );
263
+
264
+ // gnuplot
265
+ mkdirp(targetDir + '/gnuplot');
266
+ fs.copyFileSync(
267
+ path.resolve(vendor_modules_src + '/gnuplot-JS/www/gnuplot.js'),
268
+ path.resolve(targetDir + '/gnuplot/gnuplot.js'),
269
+ );
270
+ fs.copyFileSync(
271
+ path.resolve(vendor_modules_src + '/gnuplot-JS/www/gnuplot_api.js'),
272
+ path.resolve(targetDir + '/gnuplot/gnuplot_api.js'),
273
+ );
274
+
275
+ // svgbob-wasm
276
+ mkdirp(targetDir + '/svgbob-wasm');
277
+ fs.copyFileSync(
278
+ path.resolve(vendor_modules_src + '/svgbob-wasm/svgbob-wasm.js'),
279
+ path.resolve(targetDir + '/svgbob-wasm/svgbob-wasm.js'),
280
+ );
@@ -10,6 +10,10 @@ clientside-haml-js: [MIT License](https://github.com/uglyog/clientside-haml-js/b
10
10
 
11
11
  CoffeeScript: [MIT License](https://github.com/jashkenas/coffeescript/tree/07f644c39223e016aceedd2cd71b5941579b5659)
12
12
 
13
+ dart-sass: [MIT License](https://github.com/sass/dart-sass/blob/e3bf3eb3a3a8708877a86a08c7e3bee92160ac1f/LICENSE)
14
+
15
+ gnuplot-JS: [MIT License](https://github.com/chhu/gnuplot-JS/blob/62a3c8488ad00c97807ba48ae75738ca3af607fe/LICENSE)
16
+
13
17
  JSCPP: [MIT License](https://github.com/felixhao28/JSCPP/blob/befbd6b48666007151c259c5dd291ab028ad4c04/LICENSE)
14
18
 
15
19
  Less: [Apache License 2.0](https://github.com/less/less.js/blob/870f9b2d8136bfbcdc9e1293bb0def51b54f9276/LICENSE)
@@ -46,6 +50,10 @@ Stylus: [MIT License](https://github.com/stylus/stylus/blob/59bc665db295981d4e3f
46
50
 
47
51
  Svelte: [MIT License](https://github.com/sveltejs/svelte/blob/dafbdc286eef3de2243088a9a826e6899e20465c/LICENSE)
48
52
 
53
+ svgbob: [Apache License 2.0](https://github.com/ivanceras/svgbob/blob/277f28b337a2d00a61cf342247060cf5fbf88d50/LICENSE)
54
+
55
+ svgbob-wasm: [Apache License 2.0](https://github.com/agoose77/svgbob-wasm/blob/45e280096ee7f7a07981de2ce95aba343bc94123/LICENSE_APACHE)
56
+
49
57
  turbopascal: [BSD 2-Clause License](https://github.com/MikeRalphson/turbopascal/blob/cfcc5ee6d93f32664bb6127aa751c68841ca5c1d/LICENSE)
50
58
 
51
59
  wacl: [BSD 3-Clause License](https://github.com/ecky-l/wacl/blob/9daacabb0102a9986f33263261350edfeebdd83b/LICENSE)
@@ -0,0 +1,16 @@
1
+ import sass from 'sass';
2
+
3
+ window.process = {
4
+ ...window.process,
5
+ stdout: {
6
+ write: (...data) => console.log(...data),
7
+ isTTY: false,
8
+ },
9
+ stderr: {
10
+ write: (...data) => console.warn(...data),
11
+ },
12
+ env: {},
13
+ };
14
+
15
+ export const compileString = sass.compileString;
16
+ export const compileStringAsync = sass.compileStringAsync;
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Christian Huettig
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,55 @@
1
+ Portable JS Gnuplot
2
+ *******************
3
+
4
+ This is the result of compiling gnuplot with emscripten, combined with an API so it is usable straight out of the box in your browser.
5
+ The www directory contains the necessary files and a compiled version of gnuplot 4.6.3. The gnuplot-4.6.3 directory contains everything to
6
+ build the gnuplot sources with emscripten.
7
+
8
+ How to compile gnuplot
9
+ **********************
10
+
11
+ - Install llvm / emscripten, follow instructions at http://emscripten.org
12
+ - Download the gnuplot-4.6.3.tar.gz sources at http://gnuplot.info and untar.
13
+ - Copy the contents of this repo's gnuplot-4.6.3 into the folder where you unpacked the sources (should be the same name).
14
+ - [optional] adjust src/term.h and remove unneeded terminals to reduce final size
15
+ - [optional] patch src/axis.c with the patch file to fix axis descriptions: cd src;patch <../gnuplot-4.6.3.patch
16
+ - Run em_make to configure and build, you should have a gnuplot.js in your directory. WAIT at the end! The final step takes long.
17
+
18
+ How the API works
19
+ *****************
20
+
21
+ The gnuplot API (gnuplot_api.js) creates a worker (JS-thread) that loads gnuplot.js and handles all the work. No browser checks are done to check for HTML5 features.
22
+ The API lets you interact with the worker to "upload" or "download" files. Emscripten uses a mock-up for file I/O, so keep in mind that files are kept in memory as arrays
23
+ and that you need to push / pull any file-content to / from the fake file system within the worker. The API provides some convenience functions for this.
24
+
25
+ The demo site from the www directory is online at http://gnuplot.respawned.com
26
+
27
+ A minimal implementation should look like this (untested! see index.html for working version):
28
+
29
+ <img id="result"/>
30
+ <script src='gnuplot_api.js'></script>
31
+ <script>
32
+ gnuplot = new Gnuplot('gnuplot.js');
33
+ //gnuplot.putFile("myData.dat", "1 2 3 4 5 6 7 8 9 0"); // No callback needed here
34
+ gnuplot.run("my gnuplot script as a string", function(e) {
35
+ gnuplot.getFile('out.svg', function(e) {
36
+ if (!e.content) {
37
+ alert("Output file out.svg not found!");
38
+ return;
39
+ }
40
+ var img = document.getElementById('result');
41
+ try {
42
+ var ab = new Uint8Array(e.content);
43
+ var blob = new Blob([ab], {"type": "image\/svg+xml"});
44
+ window.URL = window.URL || window.webkitURL;
45
+ img.src = window.URL.createObjectURL(blob);
46
+ } catch (err) { // in case blob / URL missing, fallback to data-uri
47
+ var rstr = '';
48
+ for (var i = 0; i < e.content.length; i++)
49
+ rstr += String.fromCharCode(e.content[i]);
50
+ img.src = 'data:image\/svg+xml;base64,' + btoa(rstr);
51
+ }
52
+ });
53
+ });
54
+ </script>
55
+
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ emconfigure ./configure --without-readline --without-x --disable-h3d-quadtree --disable-wxwidgets
3
+ #emmake make clean
4
+ emmake make
5
+ rm gnuplot.o
6
+ mv src/gnuplot ./gnuplot.o
7
+ em++ -s INVOKE_RUN=0 -O2 -s ASM_JS=1 gnuplot.o -o gnuplot.js --post-js post.js --pre-js pre.js
@@ -0,0 +1,13 @@
1
+ --- gnuplot-4.6.3/src/axis.c 2012-11-08 18:13:08.000000000 +0100
2
+ +++ gnuplot-4.6.3_mod/src/axis.c 2013-05-11 11:08:08.791587160 +0200
3
+ @@ -467,8 +467,9 @@ copy_or_invent_formatstring(AXIS_INDEX a
4
+ int precision = (ceil(-log10(fabs(axmax-axmin))));
5
+ if ((axmin*axmax > 0) && precision > 4)
6
+ sprintf(ticfmt[axis],"%%.%df", (precision>14) ? 14 : precision);
7
+ + else
8
+ + strcpy(ticfmt[axis], "%g");
9
+ }
10
+ -
11
+ return ticfmt[axis];
12
+ }
13
+
@@ -0,0 +1,17 @@
1
+ shouldRunNow = true;
2
+ self['Runtime'] = Runtime;
3
+ self['FS'] = FS;
4
+ };
5
+ gnuplot_create();
6
+ // This is to avoid name mangling from closure compilers
7
+ self['FS'] = FS;
8
+ self['FS']['root'] = FS.root;
9
+ self['FS']['deleteFile'] = FS.deleteFile;
10
+ self['FS']['findObject'] = FS.findObject;
11
+ self['FS']['createDataFile'] = FS.createDataFile;
12
+ self['FS']['getFileContents'] = function(name) {
13
+ var file = FS.findObject(name);
14
+ if (!file) return null;
15
+ return file.contents;
16
+ };
17
+
@@ -0,0 +1,62 @@
1
+ self.addEventListener('message', function(e) {
2
+ var data = e.data;
3
+ if (!data) return;
4
+ var cmd = data['cmd'];
5
+ var transaction = data['transaction'];
6
+ var name = data['name'];
7
+ var content = data['content'];
8
+ var result = {
9
+ transaction: transaction
10
+ };
11
+ switch (cmd) {
12
+ case 'run':
13
+ try {
14
+ shouldRunNow = true;
15
+ if (content)
16
+ Module.run(content);
17
+ else
18
+ Module.run();
19
+ } catch(err) {
20
+
21
+ Module.printErr('Exit called, reset state.');
22
+ gnuplot_create();
23
+ };
24
+ result['content'] = 'FINISH';
25
+ self.postMessage(result);
26
+ break;
27
+
28
+ case 'putFile':
29
+ if (FS.findObject(name))
30
+ FS.deleteFile(name);
31
+ var arrc = content;
32
+ if (typeof(content) == "string")
33
+ arrc = Module['intArrayFromString'](content, true);
34
+ FS.createDataFile('/', name, arrc);
35
+ result['content'] = 'OK';
36
+ self.postMessage(result);
37
+ break;
38
+
39
+ case 'getFile':
40
+ var file = FS.findObject(name);
41
+ result['content'] = file.contents || 0;
42
+ self.postMessage(result);
43
+ break;
44
+
45
+ default:
46
+ result['content'] = 'unknown cmd';
47
+ self.postMessage(result);
48
+ };
49
+ }, false);
50
+
51
+
52
+ var Module = {
53
+ 'noInitialRun': true,
54
+ print: function(text) {
55
+ self.postMessage({'transaction': -1, 'content': text});
56
+ },
57
+ printErr: function(text) {
58
+ self.postMessage({'transaction': -2, 'content': text});
59
+ },
60
+
61
+ };
62
+ function gnuplot_create() {