@@ -2649,37 +2649,46 @@ static void SelectBestFit(Function* best_fit, Function* func) {
2649
2649
}
2650
2650
2651
2651
2652
+ static bool IsTokenPosWithinFunction (const Function& func, TokenPosition pos) {
2653
+ return (func.token_pos () <= pos && pos <= func.end_token_pos ());
2654
+ }
2655
+
2656
+
2652
2657
RawFunction* Debugger::FindBestFit (const Script& script,
2653
2658
TokenPosition token_pos) {
2654
2659
Zone* zone = Thread::Current ()->zone ();
2655
2660
Class& cls = Class::Handle (zone);
2656
2661
Array& functions = Array::Handle (zone);
2657
- GrowableObjectArray& closures = GrowableObjectArray::Handle (zone);
2662
+ const GrowableObjectArray& closures = GrowableObjectArray::Handle (
2663
+ zone, isolate_->object_store ()->closure_functions ());
2658
2664
Function& function = Function::Handle (zone);
2659
2665
Function& best_fit = Function::Handle (zone);
2660
2666
Error& error = Error::Handle (zone);
2661
2667
2662
- closures = isolate_->object_store ()->closure_functions ();
2663
2668
const intptr_t num_closures = closures.Length ();
2664
2669
for (intptr_t i = 0 ; i < num_closures; i++) {
2665
2670
function ^= closures.At (i);
2666
- if (FunctionContains (function, script, token_pos)) {
2671
+ if (function.script () != script.raw ()) {
2672
+ continue ;
2673
+ }
2674
+ if (IsTokenPosWithinFunction (function, token_pos)) {
2675
+ // Select the inner most closure.
2667
2676
SelectBestFit (&best_fit, &function);
2668
2677
}
2669
2678
}
2679
+ if (!best_fit.IsNull ()) {
2680
+ // The inner most closure found will be the best fit. Going
2681
+ // over class functions below will not help in any further
2682
+ // narrowing.
2683
+ return best_fit.raw ();
2684
+ }
2670
2685
2671
2686
const ClassTable& class_table = *isolate_->class_table ();
2672
2687
const intptr_t num_classes = class_table.NumCids ();
2673
2688
for (intptr_t i = 1 ; i < num_classes; i++) {
2674
2689
if (class_table.HasValidClassAt (i)) {
2675
2690
cls = class_table.At (i);
2676
- // Note: if this class has been parsed and finalized already,
2677
- // we need to check the functions of this class even if
2678
- // it is defined in a different 'script'. There could
2679
- // be mixin functions from the given script in this class.
2680
- // However, if this class is not parsed yet (not finalized),
2681
- // we can ignore it and avoid the side effect of parsing it.
2682
- if ((cls.script () != script.raw ()) && !cls.is_finalized ()) {
2691
+ if (cls.script () != script.raw ()) {
2683
2692
continue ;
2684
2693
}
2685
2694
// Parse class definition if not done yet.
@@ -2697,14 +2706,18 @@ RawFunction* Debugger::FindBestFit(const Script& script,
2697
2706
for (intptr_t pos = 0 ; pos < num_functions; pos++) {
2698
2707
function ^= functions.At (pos);
2699
2708
ASSERT (!function.IsNull ());
2700
- if (FunctionContains (function, script, token_pos)) {
2701
- SelectBestFit (&best_fit, &function);
2709
+ if (IsTokenPosWithinFunction (function, token_pos)) {
2710
+ // Closures and inner functions within a class method are not
2711
+ // present in the functions of a class. Hence, we can return
2712
+ // right away as looking through other functions of a class
2713
+ // will not narrow down to any inner function/closure.
2714
+ return function.raw ();
2702
2715
}
2703
2716
}
2704
2717
}
2705
2718
}
2706
2719
}
2707
- return best_fit. raw ();
2720
+ return Function::null ();
2708
2721
}
2709
2722
2710
2723
0 commit comments