Further adapt debian webjumps as suggested by John J. Foerch
[conkeror.git] / modules / source-code.js
blob63d8fafca31d017f3274fe5a826a0540a5ca215f
1 /**
2  * (C) Copyright 2004-2007 Shawn Betts
3  * (C) Copyright 2007-2009 John J. Foerch
4  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
5  *
6  * Use, modification, and distribution are subject to the terms specified in the
7  * COPYING file.
8 **/
10 in_module(null);
12 require_later("external-editor.js");
14 var conkeror_source_code_path = null;
16 function source_code_reference (uri, line_number) {
17     this.uri = uri;
18     this.line_number = line_number;
20 source_code_reference.prototype = {
21     get module_name () {
22         if (this.uri.indexOf(module_uri_prefix) == 0)
23             return this.uri.substring(module_uri_prefix.length);
24         return null;
25     },
27     get file_name () {
28         var file_uri_prefix = "file://";
29         if (this.uri.indexOf(file_uri_prefix) == 0)
30             return this.uri.substring(file_uri_prefix.length);
31         return null;
32     },
34     get best_uri () {
35         if (conkeror_source_code_path != null) {
36             var module_name = this.module_name;
37             if (module_name != null)
38                 return "file://" + conkeror_source_code_path + "/modules/" + module_name;
39         }
40         return this.uri;
41     },
43     open_in_editor : function() {
44         yield open_with_external_editor(load_spec(this.best_uri),
45                                         $line = this.line_number);
46     }
49 var get_caller_source_code_reference_ignored_functions = {};
51 function get_caller_source_code_reference (extra_frames_back) {
52     /* Skip at least this function itself and whoever called it (and
53      * more if the caller wants to be skipped). */
54     var frames_to_skip = 2;
55     if (extra_frames_back != null)
56         frames_to_skip += extra_frames_back;
58     for (let f = Components.stack; f != null; f = f.caller) {
59         if (frames_to_skip > 0) {
60             --frames_to_skip;
61             continue;
62         }
63         if (get_caller_source_code_reference_ignored_functions[f.name])
64             continue;
65         return new source_code_reference(f.filename, f.lineNumber);
66     }
68     return null;
71 function ignore_function_for_get_caller_source_code_reference (func_name) {
72     get_caller_source_code_reference_ignored_functions[func_name] = 1;
75 provide("source-code");