We use cookies and other tracking technologies to improve your browsing experience on our site, analyze site traffic, and understand where our audience is coming from. To find out more, please read our privacy policy.

By choosing 'I Accept', you consent to our use of cookies and other tracking technologies.

We use cookies and other tracking technologies to improve your browsing experience on our site, analyze site traffic, and understand where our audience is coming from. To find out more, please read our privacy policy.

By choosing 'I Accept', you consent to our use of cookies and other tracking technologies. Less

We use cookies and other tracking technologies... More

Login or register
to apply for this job!

Login or register to start contributing with an article!

Login or register
to see more jobs from this company!

Login or register
to boost this post!

Show some love to the author of this blog by giving their post some rocket fuel 🚀.

Login or register to search for your ideal job!

Login or register to start working on this issue!

Engineers who find a new job through Golang Works average a 15% increase in salary 🚀

Run computation in isolated context

Pull requests: 1
Contributors: 0
Level: Advanced
  • Clojure
  • $300
Pull requests: 1
Contributors: 0
Level: Advanced
  • Clojure
  • $300

On GitHub

Klipse is a Javacript plugin for embedding interactive code snippets in tech blogs. A simple client-side code evaluator pluggable on any web page: clojure, ruby, javascript, python, scheme, es2017, jsx, brainfuck, c++, reagent, lua, ocaml, reasonml, prolog, common lisp
More info >

Issue posted by: 
dmsnell's avatar

Dennis Snell

Description

See also #100

Being able to run the compilation/computation inside a WebWorker or in an iframe would make it significantly easier to secure the scripts to guard against abuse and it would enhance the viewing experience by moving expensive or runaway calculations out of the UI thread.

After a conversation with @viebel he recommended trying to prototype by replacing eval() with an async version that channels messages through the frames/contexts. Something like this would do…

function isolatedEval( inputSourceCode, mode, options = { timeout: 1000 } ) {
	return new Promise( ( response, reject ) => {
		const [ port1, port2 ] = new MessageChannel();
		let alreadyFinished = false;
		let handle;

		klipseWorker.postMessage( { inputSourceCode, mode, options }, [ port2 ] );

		handle = setTimeout( () => {
			alreadyFinished = true;
			port1.postMessage( 'cancel' );
			port1.close();
			reject( 'timeout' );
		}, timeout );

		port1.onmessage = ( { data: { error, output, wasSuccess } } ) => {
			clearTimeout( handle );
			port1.close();

			if ( alreadyFinished ) {
				return;
			}

			alreadyFinished = true;

			if ( wasSuccess ) {
				resolve( output );
			} else {
				reject( error );
			}
		};
	} );
}

If running inside an iframe we could support view-only DOM creation by sending .innerHTML across the frame as a string and then stiching it up on the host side.

    Use Open Source Issues to hire or get hired

    On GitHub

    Klipse is a Javacript plugin for embedding interactive code snippets in tech blogs. A simple client-side code evaluator pluggable on any web page: clojure, ruby, javascript, python, scheme, es2017, jsx, brainfuck, c++, reagent, lua, ocaml, reasonml, prolog, common lisp
    More info >

    Issue posted by: 
    dmsnell's avatar

    Dennis Snell

    Use Open Source Issues to hire or get hired

    Run computation in isolated context
    View on GitHub