From 70adf7ad8bc879804d15741a14d76a84f39e4e35 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 20 Jan 2018 17:56:34 +0800 Subject: [PATCH 1/5] String should not be wrapped by quotes. __repr__ of PyJsObject has been overwritten. --- js2py/base.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/js2py/base.py b/js2py/base.py index 5b46e307..15598216 100644 --- a/js2py/base.py +++ b/js2py/base.py @@ -24,9 +24,9 @@ def str_repr(s): if six.PY2: - return repr(s.encode('utf-8')) + return s.encode('utf-8') else: - return repr(s) + return s def MakeError(name, message): """Returns PyJsException with PyJsError inside""" @@ -907,12 +907,7 @@ def __unicode__(self): return self.to_string().value def __repr__(self): - if self.Class=='Object': - res = [] - for e in self: - res.append(str_repr(e.value)+': '+str_repr(self.get(e))) - return '{%s}'%', '.join(res) - elif self.Class=='String': + if self.Class=='String': return str_repr(self.value) elif self.Class in ['Array','Int8Array','Uint8Array','Uint8ClampedArray','Int16Array','Uint16Array','Int32Array','Uint32Array','Float32Array','Float64Array']: res = [] From 55ff9b4539df30fca2d8a605fc6d3f57ce93e2da Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 20 Jan 2018 19:07:41 +0800 Subject: [PATCH 2/5] Multiple arguments support for console.log --- js2py/host/console.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js2py/host/console.py b/js2py/host/console.py index 822219ea..b26dbee3 100644 --- a/js2py/host/console.py +++ b/js2py/host/console.py @@ -6,6 +6,6 @@ def console(): @Js def log(): - print(arguments[0]) + print(*arguments.to_list()) console.put('log', log) \ No newline at end of file From f72a21f80e6fc7dcd4d0727080ac8f71e7efd9d9 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 20 Jan 2018 19:10:32 +0800 Subject: [PATCH 3/5] Added "to_dict()" in PyJsArguments --- js2py/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/js2py/base.py b/js2py/base.py index 15598216..2484340f 100644 --- a/js2py/base.py +++ b/js2py/base.py @@ -2381,6 +2381,9 @@ def __init__(self, args, callee): def to_list(self): return [self.get(str(e)) for e in xrange(self.get('length').to_uint32())] + def to_dict(self): + return dict([(str(e), self.get(str(e))) for e in xrange(self.get('length').to_uint32())]) + #We can define function proto after number proto because func uses number in its init FunctionPrototype = PyJsFunction(Empty, ObjectPrototype) From c30aae31d3f9564acab5d8f02ec9c29c3f13cc91 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 20 Jan 2018 19:30:10 +0800 Subject: [PATCH 4/5] revert console.py in order to compatible with py2 --- js2py/host/console.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js2py/host/console.py b/js2py/host/console.py index b26dbee3..822219ea 100644 --- a/js2py/host/console.py +++ b/js2py/host/console.py @@ -6,6 +6,6 @@ def console(): @Js def log(): - print(*arguments.to_list()) + print(arguments[0]) console.put('log', log) \ No newline at end of file From 272a28ffeb41d0e2b5c92c19dc74ab4737a7d63a Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 20 Jan 2018 19:49:33 +0800 Subject: [PATCH 5/5] Added multiple arguments support in console.log and compatible with python2 --- js2py/host/console.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js2py/host/console.py b/js2py/host/console.py index 822219ea..5a5f4154 100644 --- a/js2py/host/console.py +++ b/js2py/host/console.py @@ -6,6 +6,6 @@ def console(): @Js def log(): - print(arguments[0]) + print(' '.join(map(str, arguments.to_list()))) console.put('log', log) \ No newline at end of file