Skip to content

Commit

Permalink
Upgrade duktape
Browse files Browse the repository at this point in the history
  • Loading branch information
amol- committed Nov 4, 2024
1 parent 94fe3b4 commit ead4b01
Show file tree
Hide file tree
Showing 5 changed files with 99,320 additions and 85,648 deletions.
14 changes: 5 additions & 9 deletions dukpy/evaljs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import os
import logging

# Duktape uses CESU-8 encoding, so we need support for it.
# see https://github.com/svaarala/duktape/issues/504#issuecomment-168336246
from mutf8 import encode_modified_utf8, decode_modified_utf8

from dukpy.module_loader import JSModuleLoader
from . import _dukpy

Expand Down Expand Up @@ -53,16 +49,16 @@ def evaljs(self, code, **kwargs):
jscode = self._adapt_code(code)

if not isinstance(jscode, bytes):
jscode = encode_modified_utf8(jscode)
jscode = jscode.encode('utf-8')

if not isinstance(jsvars, bytes):
jsvars = encode_modified_utf8(jsvars)
jsvars = jsvars.encode('utf-8')

res = _dukpy.eval_string(self, jscode, jsvars)
if res is None:
return None

return json.loads(decode_modified_utf8(res))
return json.loads(res.decode('utf-8'))

def export_function(self, name, func):
"""Exports a python function to the javascript layer with the given name.
Expand All @@ -80,12 +76,12 @@ def _check_exported_function_exists(self, func):
def _call_python(self, func, json_args):
# Arguments came in reverse order from JS
func = func.decode('ascii')
json_args = decode_modified_utf8(json_args)
json_args = json_args.decode('utf-8')

args = list(reversed(json.loads(json_args)))
ret = self._funcs[func](*args)
if ret is not None:
return encode_modified_utf8(json.dumps(ret))
return json.dumps(ret).encode('utf-8')

def _init_process(self):
self.evaljs("process = {}; process.env = dukpy.environ", environ=dict(os.environ))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
except IOError:
README = ''

INSTALL_REQUIRES = ["mutf8"]
INSTALL_REQUIRES = []
if py_version == (2, 6):
INSTALL_REQUIRES.append('argparse')

Expand Down
Loading

0 comments on commit ead4b01

Please sign in to comment.