From e2782f09f51d71cac387d9f2c6f90b17d3e5e067 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 11 Oct 2015 13:46:09 -0400 Subject: [PATCH] Clean up EvalController by using a callback in -[DebuggerBackEnd evalScript:callback:]. --- Source/DebuggerBackEnd.h | 5 +---- Source/DebuggerBackEnd.m | 4 ++-- Source/DebuggerController.m | 5 ----- Source/EvalController.h | 6 ------ Source/EvalController.m | 14 +++----------- 5 files changed, 6 insertions(+), 28 deletions(-) diff --git a/Source/DebuggerBackEnd.h b/Source/DebuggerBackEnd.h index ecd9a70..b926968 100644 --- a/Source/DebuggerBackEnd.h +++ b/Source/DebuggerBackEnd.h @@ -61,7 +61,7 @@ - (void)removeBreakpoint:(Breakpoint*)bp; // Evaluates a given string in the current execution context. -- (void)evalScript:(NSString*)str; +- (void)evalScript:(NSString*)str callback:(void (^)(NSString*))callback; // Gets a property by name from the debugger engine. Properties must be // retrieved at a certain stack depth. @@ -98,8 +98,5 @@ // TODO: rename to |-frameUpdated:|. - (void)sourceUpdated:(StackFrame*)frame; -// Callback for the result of |-evalScript:|. -- (void)scriptWasEvaluatedWithResult:(NSString*)result; - @end diff --git a/Source/DebuggerBackEnd.m b/Source/DebuggerBackEnd.m index 276ae65..44c643e 100644 --- a/Source/DebuggerBackEnd.m +++ b/Source/DebuggerBackEnd.m @@ -234,7 +234,7 @@ /** * Sends a string to be evaluated by the engine. */ -- (void)evalScript:(NSString*)str { +- (void)evalScript:(NSString*)str callback:(void (^)(NSString*))callback { if (!_active) return; @@ -243,7 +243,7 @@ ProtocolClientMessageHandler handler = ^(NSXMLDocument* message) { NSXMLElement* parent = (NSXMLElement*)[[message rootElement] childAtIndex:0]; NSString* value = [parent base64DecodedValue]; - [self.delegate scriptWasEvaluatedWithResult:value]; + callback(value); }; [_client sendCustomCommandWithFormat:@"eval -i {txn} -- %s" handler:handler, encodedString]; free(encodedString); diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index 3155dca..63ed8ce 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -391,9 +391,4 @@ [self updateSourceViewer]; } -- (void)scriptWasEvaluatedWithResult:(NSString*)result -{ - [EvalController scriptWasEvaluatedWithResult:result]; -} - @end diff --git a/Source/EvalController.h b/Source/EvalController.h index 5a99149..542aa94 100644 --- a/Source/EvalController.h +++ b/Source/EvalController.h @@ -37,10 +37,4 @@ - (IBAction)evaluateScript:(id)sender; - (IBAction)closeWindow:(id)sender; -// Callback from the DebuggerBackEnd that is routed through the -// DebuggerController. This will message the current EvalController if it is -// running modally. If the controller is not running, the message will be -// dropped. -+ (void)scriptWasEvaluatedWithResult:(NSString*)result; - @end diff --git a/Source/EvalController.m b/Source/EvalController.m index c0b2f0f..9c68687 100644 --- a/Source/EvalController.m +++ b/Source/EvalController.m @@ -18,8 +18,6 @@ #import "DebuggerBackEnd.h" -static EvalController* g_activeEvalController = nil; - @implementation EvalController @synthesize dataField = dataField_; @@ -42,8 +40,6 @@ static EvalController* g_activeEvalController = nil; - (void)runModalForWindow:(NSWindow*)parent { - assert(!g_activeEvalController); - g_activeEvalController = self; [NSApp beginSheet:[self window] modalForWindow:parent modalDelegate:self @@ -55,14 +51,15 @@ static EvalController* g_activeEvalController = nil; returnCode:(NSInteger)returnCode contextInfo:(void*)contextInfo { - g_activeEvalController = nil; [self autorelease]; } - (IBAction)evaluateScript:(id)sender { NSString* code = [self.dataField stringValue]; - [backEnd_ evalScript:code]; + [backEnd_ evalScript:code callback:^(NSString* result) { + [self.resultField setStringValue:result]; + }]; } - (IBAction)closeWindow:(id)sender @@ -71,9 +68,4 @@ static EvalController* g_activeEvalController = nil; [NSApp endSheet:[self window]]; } -+ (void)scriptWasEvaluatedWithResult:(NSString*)result -{ - [g_activeEvalController.resultField setStringValue:result]; -} - @end -- 2.43.5