Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade duktape to 50af773 #81

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading