inline bool is_expression();
inline void set_is_expression(bool value);
- // Is this function a top-level function. Used for accessing the
- // caller of functions. Top-level functions (scripts, evals) are
- // returned as null; see JSFunction::GetCallerAccessor(...).
+ // Is this function a top-level function (scripts, evals).
inline bool is_toplevel();
inline void set_is_toplevel(bool value);
target_start_position = start_position;
target = shared;
} else {
- if (target_start_position < start_position &&
- shared->end_position() < target->end_position()) {
+ if (target_start_position == start_position &&
+ shared->end_position() == target->end_position()) {
+ // If a top-level function contain only one function
+ // declartion the source for the top-level and the function is
+ // the same. In that case prefer the non top-level function.
+ if (!shared->is_toplevel()) {
+ target_start_position = start_position;
+ target = shared;
+ }
+ } else if (target_start_position <= start_position &&
+ shared->end_position() <= target->end_position()) {
+ // This containment check includes equality as a function inside
+ // a top-level function can share either start or end position
+ // with the top-level function.
target_start_position = start_position;
target = shared;
}