Skip to content

Commit 691ea36

Browse files
committed
Walk on the full ast to modify return statement so all returns is catched
1 parent 8c4b808 commit 691ea36

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

javascript/emscripten.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,8 @@ def entry(self, *args):
978978
self.count += 1
979979
self.promises[promise.id] = promise
980980
result = self.function(promise, promise.wait, *args)
981-
if not promise.next_called and not promise.waitable.object['resolved']:
982-
promise.resolve(result)
981+
#if not promise.next_called and not promise.waitable.object['resolved']:
982+
# promise.resolve(result)
983983
return promise.waitable
984984

985985
def next(self):
@@ -994,8 +994,8 @@ def next(self):
994994
self.awaits = []
995995
self.step += 1
996996
result = self.function(self, self.wait, *self.args)
997-
if not self.next_called and not self.waitable.object['resolved']:
998-
self.resolve(result)
997+
#if not self.next_called and not self.waitable.object['resolved']:
998+
# self.resolve(result)
999999
#Maybe returns here too to catch promise chain
10001000

10011001
def wait(self, awaits=None, native=None):
@@ -1058,12 +1058,20 @@ def resolve(self, value):
10581058
#new_function = ast.parse('def ' + name + '(rpython_promise=None, *args): ' + (', '.join(args) if args else 'args') + (' = args[0]' if len(args) == 1 else ' = args')).body[0]
10591059
groups = []
10601060
returns = False
1061+
for object in ast.walk(code):
1062+
if isinstance(object, ast.Return):
1063+
resolve = ast.parse('rpython_promise.resolve()' if object.value is None else 'rpython_promise.resolve(rpython_keep_object())').body[0].value
1064+
if object.value is None:
1065+
resolve.args.append(ast.parse('None').body[0].value)
1066+
else:
1067+
resolve.args[0].args.append(object.value)
1068+
object.value = resolve
10611069
for line in function.body:
10621070
if not groups: groups.append([])
10631071
object = line #{'line': line}
10641072
if isinstance(object, ast.Return):
10651073
returns = True
1066-
resolve = ast.parse('return rpython_promise.resolve()' if object.value is None else 'return rpython_promise.resolve(rpython_keep_object())').body[0]
1074+
"""resolve = ast.parse('return rpython_promise.resolve()' if object.value is None else 'return rpython_promise.resolve(rpython_keep_object())').body[0]
10671075
if object.value is None:
10681076
resolve.value.args.append(object.value if object.value is not None else ast.parse('None').body[0].value)
10691077
else:
@@ -1074,7 +1082,8 @@ def resolve(self, value):
10741082
# groups[-1].append(keep)
10751083
groups[-1].append(resolve)
10761084
break
1077-
else: groups[-1].append(object)
1085+
else: """
1086+
groups[-1].append(object)
10781087
conditions = []
10791088
conditions += [(isinstance(line, ast.Expr) or isinstance(line, ast.Assign)) and isinstance(line.value, ast.Call) and isinstance(line.value.func, ast.Name) and line.value.func.id == 'wait']
10801089
conditions += [(isinstance(line, ast.Expr) or isinstance(line, ast.Assign)) and isinstance(line.value, ast.Call) and isinstance(line.value.func, ast.Attribute) and line.value.func.attr == 'wait']

0 commit comments

Comments
 (0)