Skip to content

Commit b1bbbeb

Browse files
fixes #111
1 parent 240cd36 commit b1bbbeb

5 files changed

Lines changed: 25 additions & 9 deletions

File tree

js2py/internals/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def __init__(self, body, flags, prototype=None):
457457
reg = reg.replace(fix, rep)
458458
# print 'Fix', fix, '->', rep, '=', reg
459459
else:
460-
raise
460+
raise Exception()
461461
REGEXP_DB[body, flags] = self.pat
462462
except:
463463
#print 'Invalid pattern...', self.value, comp
@@ -594,6 +594,8 @@ def put(self, var, val, throw=False):
594594
if self.is_with_scope:
595595
if self.own.has_property(var):
596596
return self.own.put(var, val, throw=throw)
597+
else:
598+
return self.prototype.put(var, val)
597599
# trying to put in local scope
598600
# we dont know yet in which scope we should place this var
599601
elif var in self.own:

js2py/internals/byte_trans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ def WithStatement(self, object, body, **kwargs):
613613
self.emit('LABEL', beg_label)
614614
self.emit('LOAD_UNDEFINED')
615615
self.emit(body)
616-
self.emit('LABEL', end_label)
617616
self.emit('NOP')
617+
self.emit('LABEL', end_label)
618618

619619
# with statement implementation
620620
self.emit('WITH', beg_label, end_label)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from __future__ import unicode_literals
2+
3+
from js2py.internals.conversions import *
4+
from js2py.internals.func_utils import *
5+
6+
7+
class ConsoleMethods:
8+
def log(this, args):
9+
x = ' '.join(to_string(e) for e in args)
10+
print(x)

js2py/internals/fill_space.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
from base import Scope
24
from func_utils import *
35
from conversions import *
@@ -13,7 +15,6 @@
1315
import prototypes.jsjson as jsjson
1416
import prototypes.jsutils as jsutils
1517

16-
1718
from constructors import jsnumber
1819
from constructors import jsstring
1920
from constructors import jsarray
@@ -22,6 +23,8 @@
2223
from constructors import jsmath
2324
from constructors import jsobject
2425
from constructors import jsfunction
26+
from constructors import jsconsole
27+
2528

2629
def fill_proto(proto, proto_class, space):
2730
for i in dir(proto_class):
@@ -244,6 +247,8 @@ def new_create(args, space):
244247
for k,v in jsmath.CONSTANTS.items():
245248
set_protected(math, k, v)
246249

250+
console = space.NewObject()
251+
fill_proto(console, jsconsole.ConsoleMethods, space)
247252

248253

249254
# set global object
@@ -264,7 +269,8 @@ def new_create(args, space):
264269
'isFinite': isFinite,
265270
'isNaN': isNaN,
266271
'eval': easy_func(jsfunction._eval, space),
267-
'log': easy_func(jsfunction.log, space),
272+
'console': console,
273+
'log': console.get(u'log'),
268274
}
269275

270276
builtins.update(error_constructors)

js2py/internals/opcodes.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,9 @@ def eval(self, ctx):
646646
with_context.THIS_BINDING = ctx.THIS_BINDING
647647
status = ctx.space.exe.execute_fragment_under_context(with_context, self.beg_label, self.end_label)
648648

649-
650-
651649
val, typ, spec = status
652-
if typ!=3:
653-
print typ
650+
651+
if typ != 3: # exception
654652
ctx.stack.pop()
655653

656654
if typ == 0: # normal
@@ -662,7 +660,7 @@ def eval(self, ctx):
662660
elif typ == 2: # jump outside
663661
ctx.stack.append(val)
664662
return spec
665-
elif typ == 3:
663+
elif typ == 3: # exception
666664
# throw is made with empty stack as usual
667665
raise spec
668666
else:

0 commit comments

Comments
 (0)