Closed shawnsarwar closed 4 years ago
What exactly are you trying?
Here's a self contained example of trying to call a function from the standard library:
from quickjs import Context
js_str = '''
import * as std from "std";
std.open("f.txt")
'''
context = Context()
context.eval(js_str)
Which yields
Traceback (most recent call last):
File "./t.py", line 9, in <module>
context.eval(js_str)
_quickjs.JSException: SyntaxError: expecting '('
My goal is to use quickjs as a sandboxed JS environment to execute user defined js functions for the purpose of Map / Reduce. I'd rather not be able to access the standard library, I just want to make sure I'm not doing something dumb (which is my current assumption).
The standard library used in the quickjs executable is not available. Also, the context does not evaluate the code as a module, that's why you are getting the syntax error.
I'm trying to assess this for sandboxing small bits of JS code execution in a python environment. I don't see you performing imports of
os
orstd
in the tests and when I try with eitherFunction
or Context I get:_quickjs.JSException: SyntaxError: expecting '('
Is this the intended behavior? I want to make sure that I can restrict or regulate access to things likeos.open
andstd.getUrl
from within aFunction
orContext
evaluation.