@@ -24,6 +24,12 @@ var categoryToName = {
24
24
32768 : 'DONE'
25
25
} ;
26
26
27
+ class ResumeException {
28
+ constructor ( exception ) {
29
+ this . exception = exception ;
30
+ }
31
+ }
32
+
27
33
class Ctx extends NQPObject {
28
34
constructor ( callerCtx , outerCtx , callThis ) {
29
35
super ( ) ;
@@ -44,7 +50,6 @@ class Ctx extends NQPObject {
44
50
while ( ctx ) {
45
51
if ( ctx [ handler ] || ctx . $$CONTROL ) {
46
52
exception . caught = ctx ;
47
- exception . resume = false ;
48
53
ctx . exception = exception ;
49
54
50
55
exceptionsStack . push ( exception ) ;
@@ -54,15 +59,17 @@ class Ctx extends NQPObject {
54
59
} else {
55
60
ctx . unwind . ret = ctx . $$CONTROL ( ) ;
56
61
}
62
+ } catch ( e ) {
63
+ if ( e instanceof ResumeException && e . exception === exception ) {
64
+ return ;
65
+ } else {
66
+ throw e ;
67
+ }
57
68
} finally {
58
69
exceptionsStack . pop ( ) ;
59
70
}
60
71
61
- if ( exception . resume ) {
62
- return ;
63
- } else {
64
- throw ctx . unwind ;
65
- }
72
+ throw ctx . unwind ;
66
73
}
67
74
ctx = ctx . $$caller ;
68
75
}
@@ -71,28 +78,32 @@ class Ctx extends NQPObject {
71
78
}
72
79
73
80
propagateException ( exception ) {
74
- if ( exception . $$category ) this . propagateControlException ( exception ) ;
81
+ if ( exception . $$category ) {
82
+ this . propagateControlException ( exception ) ;
83
+ return ;
84
+ }
75
85
76
86
var ctx = this ;
77
87
78
88
while ( ctx ) {
79
89
if ( ctx . $$CATCH ) {
80
90
exception . caught = ctx ;
81
- exception . resume = false ;
82
91
ctx . exception = exception ;
83
92
84
93
exceptionsStack . push ( exception ) ;
85
94
try {
86
95
ctx . unwind . ret = ctx . $$CATCH ( ) ;
96
+ } catch ( e ) {
97
+ if ( e instanceof ResumeException && e . exception === exception ) {
98
+ return ;
99
+ } else {
100
+ throw e ;
101
+ }
87
102
} finally {
88
103
exceptionsStack . pop ( ) ;
89
104
}
90
105
91
- if ( exception . resume ) {
92
- return ;
93
- } else {
94
- throw ctx . unwind ;
95
- }
106
+ throw ctx . unwind ;
96
107
}
97
108
ctx = ctx . $$caller ;
98
109
}
@@ -118,7 +129,7 @@ class Ctx extends NQPObject {
118
129
}
119
130
120
131
resume ( exception ) {
121
- exception . resume = true ;
132
+ throw new ResumeException ( exception ) ;
122
133
}
123
134
124
135
throw ( exception ) {
@@ -144,11 +155,9 @@ class Ctx extends NQPObject {
144
155
145
156
let ctx = this ;
146
157
147
-
148
158
while ( ctx ) {
149
159
if ( ctx [ handler ] || ctx . $$CONTROL ) {
150
160
exception . caught = ctx ;
151
- exception . resume = false ;
152
161
ctx . exception = exception ;
153
162
154
163
exceptionsStack . push ( exception ) ;
@@ -158,15 +167,17 @@ class Ctx extends NQPObject {
158
167
} else {
159
168
ctx . unwind . ret = ctx . $$CONTROL ( ) ;
160
169
}
170
+ } catch ( e ) {
171
+ if ( e instanceof ResumeException && e . exception === exception ) {
172
+ return ;
173
+ } else {
174
+ throw e ;
175
+ }
161
176
} finally {
162
177
exceptionsStack . pop ( ) ;
163
178
}
164
179
165
- if ( exception . resume ) {
166
- return ;
167
- } else {
168
- throw ctx . unwind ;
169
- }
180
+ throw ctx . unwind ;
170
181
}
171
182
ctx = ctx . $$outer ;
172
183
}
0 commit comments