Git Product home page Git Product logo

Comments (7)

fniephaus avatar fniephaus commented on May 27, 2024 1

The StackOverflow thread talks about sandboxing, so I'm guessing you are concerned about security. First, security is not a primary goal of what we want to achieve here. Nonetheless, GraalVM can sandbox languages and thus the polyglot API can be considered "secure". By default, however, I think sandboxing is disabled. Will look into this for you...
So ultimately, we could move all modifications (e.g. magic parsing) to nel and leave everything else almost as they were, right?

from ipolyglot.

fniephaus avatar fniephaus commented on May 27, 2024 1

Why

return vm.runInThisContext(Polyglot.eval(magic, actualCode));

and not just

return Polyglot.eval(magic, actualCode);

?

from ipolyglot.

JakobEdding avatar JakobEdding commented on May 27, 2024

Basically works with ea2a0ef

The only things left which would be nice to have for the next meeting are execution of multiline code and supporting " for strings in code cells, not just ' :D

We might be able to solve both issues using some kind of Regex escape for strings maybe. @jonashering @tomkellog

from ipolyglot.

fniephaus avatar fniephaus commented on May 27, 2024

@jak-ing have you found the LOC where your "transpiled" code is executed (probably by calling eval()). Maybe it'd be better to extract magic and language selection where that eval call is and replace it with a direct Polyglot.eval() call? Example:

Somewhere in jp-kernel or probably in nel:

eval(request.code);

turns into:

magic = polyglotExtract(request.code);
Polyglot.eval(magic.language, magic.code);

This way, you can easily support multiline code and avoid the use of regexs :)

from ipolyglot.

fniephaus avatar fniephaus commented on May 27, 2024

Looks like nel also has some sort of transpiler support. And this is how nel executes JS code.

from ipolyglot.

JakobEdding avatar JakobEdding commented on May 27, 2024

@tomkellog wanted to take over from here but here's what I found out already yesterday:

Replacing the eval() call with Polyglot.eval()

I'm in favor of this too! vm.runInThisContext replaces eval as can be seen in the example from the vm docs. So eval() is actually not used in neither jp-kernel nor nel. But I'm not sure whether it's a good idea to swap out vm.runInThisContext with Polyglot.eval() :O Is there a GraalVM equivalent to vm @fniephaus? Or maybe we can somehow call the GraalVM node binary itself instead of runInThisContext()?

Transpiler support in nel
The transpile in nel just takes the transpile defined in e.g. IJavaScript's kernel.js through the passed config (--> Kernel(config) --> Session(...)) and doesn't do much anything else as far as I can see. Also since we don't actually transpile stuff but manipulate the code execution itself I think changing the eval() mechanism as proposed by you above is a better idea.

from ipolyglot.

niconomaa avatar niconomaa commented on May 27, 2024

Screenshot 2019-05-06 at 16 20 01

multi-line, choice of quotation marks and support for all Graal language works. Code is uncommited because changes affect node modules, in main.js):

function run(code) {

    let magic = '';

    if(code.startsWith('%polyglot ')){
        magic = code.split('\n')[0].replace('%polyglot ', '')
    } else {
        return vm.runInThisContext(code);
    }

    const actualCode = code.split('\n').slice(1).join('\n');

    return vm.runInThisContext(Polyglot.eval(magic, actualCode));
}

from ipolyglot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.