Skip to content

Commit 55d6bf3

Browse files
improve undefined is not a function error message (finally)
1 parent 1158449 commit 55d6bf3

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

js2py/base.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def get(self, prop): #external use!
319319
#prop = prop.value
320320
if self.Class == 'Undefined' or self.Class == 'Null':
321321
raise MakeError('TypeError',
322-
'Undefined and null dont have properties!')
322+
'Undefined and null dont have properties (tried getting property %s)' % repr(prop))
323323
if not isinstance(prop, basestring):
324324
prop = prop.to_string().value
325325
if not isinstance(prop, basestring): raise RuntimeError('Bug')
@@ -361,7 +361,7 @@ def put(self, prop, val, op=None): #external use!
361361
* / % + - << >> & ^ |'''
362362
if self.Class == 'Undefined' or self.Class == 'Null':
363363
raise MakeError('TypeError',
364-
'Undefined and null dont have properties!')
364+
'Undefined and null don\'t have properties (tried setting property %s)' % repr(prop))
365365
if not isinstance(prop, basestring):
366366
prop = prop.to_string().value
367367
if NUMPY_AVAILABLE and prop.isdigit():
@@ -991,7 +991,8 @@ def callprop(self, prop, *args):
991991
cand = self.get(prop)
992992
if not cand.is_callable():
993993
raise MakeError('TypeError',
994-
'%s is not a function' % cand.typeof())
994+
'%s is not a function (tried calling property %s of %s)' % (
995+
cand.typeof(), repr(prop), repr(self.Class)))
995996
return cand.call(self, args)
996997

997998
def to_python(self):
@@ -1464,9 +1465,11 @@ def call(self, this, args=()):
14641465
except NotImplementedError:
14651466
raise
14661467
except RuntimeError as e: # maximum recursion
1467-
raise MakeError(
1468-
'RangeError', e.message if
1469-
not isinstance(e, NotImplementedError) else 'Not implemented!')
1468+
try:
1469+
msg = e.message
1470+
except:
1471+
msg = repr(e)
1472+
raise MakeError('RangeError', msg)
14701473

14711474
def has_instance(self, other):
14721475
# I am not sure here so instanceof may not work lol.

js2py/node_import.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _get_and_translate_npm_module(module_name, include_polyfill=False, update=Fa
130130
return py_code
131131

132132

133-
def require(module_name, include_polyfill=False, update=False, context=None):
133+
def require(module_name, include_polyfill=True, update=False, context=None):
134134
"""
135135
Installs the provided npm module, exports a js bundle via browserify, converts to ECMA 5.1 via babel and
136136
finally translates the generated JS bundle to Python via Js2Py.
@@ -139,7 +139,7 @@ def require(module_name, include_polyfill=False, update=False, context=None):
139139
:param module_name: Name of the npm module to require. For example 'esprima'. Supports specific versions via @
140140
specification. Eg: 'crypto-js@3.3'.
141141
:param include_polyfill: Whether the babel-polyfill should be included as part of the translation. May be needed
142-
for some modules that use unsupported features.
142+
for some modules that use unsupported features of JS6 such as Map or typed arrays.
143143
:param update: Whether to force update the translation. Otherwise uses a cached version if exists.
144144
:param context: Optional context in which the translated module should be executed in. If provided, the
145145
header (js2py imports) will be skipped as it is assumed that the context already has all the necessary imports.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# twine upload dist/*
2828
setup(
2929
name='Js2Py',
30-
version='0.68',
30+
version='0.70',
3131

3232
packages=['js2py', 'js2py.utils', 'js2py.prototypes', 'js2py.translators',
3333
'js2py.constructors', 'js2py.host', 'js2py.es6', 'js2py.internals',

simple_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import js2py
22
import time
3+
import sys
4+
5+
sys.setrecursionlimit(10000)
36

47
print("Testing ECMA 5...")
58

0 commit comments

Comments
 (0)