|
@@ -100,13 +100,19 @@ let handle_stack_overflow eval f =
|
|
with Stack_overflow -> exc_string "Stack overflow"
|
|
with Stack_overflow -> exc_string "Stack overflow"
|
|
|
|
|
|
let catch_exceptions ctx ?(final=(fun() -> ())) f p =
|
|
let catch_exceptions ctx ?(final=(fun() -> ())) f p =
|
|
- let prev = !GlobalState.get_ctx_ref in
|
|
|
|
|
|
+ let reset_ctx =
|
|
|
|
+ if !GlobalState.initialized then
|
|
|
|
+ let prev = !GlobalState.get_ctx_ref in
|
|
|
|
+ (fun() -> GlobalState.get_ctx_ref := prev)
|
|
|
|
+ else
|
|
|
|
+ (fun() -> ())
|
|
|
|
+ in
|
|
select ctx;
|
|
select ctx;
|
|
let eval = get_eval ctx in
|
|
let eval = get_eval ctx in
|
|
let env = eval.env in
|
|
let env = eval.env in
|
|
let r = try
|
|
let r = try
|
|
let v = handle_stack_overflow eval f in
|
|
let v = handle_stack_overflow eval f in
|
|
- GlobalState.get_ctx_ref := prev;
|
|
|
|
|
|
+ reset_ctx();
|
|
final();
|
|
final();
|
|
Some v
|
|
Some v
|
|
with
|
|
with
|
|
@@ -117,7 +123,7 @@ let catch_exceptions ctx ?(final=(fun() -> ())) f p =
|
|
if is v key_haxe_macro_Error then begin
|
|
if is v key_haxe_macro_Error then begin
|
|
let v1 = field v key_exception_message in
|
|
let v1 = field v key_exception_message in
|
|
let v2 = field v key_pos in
|
|
let v2 = field v key_pos in
|
|
- GlobalState.get_ctx_ref := prev;
|
|
|
|
|
|
+ reset_ctx();
|
|
final();
|
|
final();
|
|
match v1 with
|
|
match v1 with
|
|
| VString s ->
|
|
| VString s ->
|
|
@@ -148,7 +154,7 @@ let catch_exceptions ctx ?(final=(fun() -> ())) f p =
|
|
| _ :: l -> l (* Otherwise, ignore topmost frame position. *)
|
|
| _ :: l -> l (* Otherwise, ignore topmost frame position. *)
|
|
in
|
|
in
|
|
let msg = get_exc_error_message ctx v stack (if p' = null_pos then p else p') in
|
|
let msg = get_exc_error_message ctx v stack (if p' = null_pos then p else p') in
|
|
- GlobalState.get_ctx_ref := prev;
|
|
|
|
|
|
+ reset_ctx();
|
|
final();
|
|
final();
|
|
Error.error msg null_pos
|
|
Error.error msg null_pos
|
|
end
|
|
end
|
|
@@ -156,7 +162,7 @@ let catch_exceptions ctx ?(final=(fun() -> ())) f p =
|
|
final();
|
|
final();
|
|
None
|
|
None
|
|
| exc ->
|
|
| exc ->
|
|
- GlobalState.get_ctx_ref := prev;
|
|
|
|
|
|
+ reset_ctx();
|
|
final();
|
|
final();
|
|
raise exc
|
|
raise exc
|
|
in
|
|
in
|