Debian package: Add support for xulrunner 18
[conkeror.git] / modules / source-code.js
blob1b90e08bc7f84709e5b56ce4fa0508cd068bfb9e
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 require_later("external-editor.js");
12 var conkeror_source_code_path = null;
14 function source_code_reference (uri, line_number) {
15     this.uri = uri;
16     this.line_number = line_number;
18 source_code_reference.prototype = {
19     constructor: source_code_reference,
20     get module_name () {
21         if (this.uri.indexOf(module_uri_prefix) == 0)
22             return this.uri.substring(module_uri_prefix.length);
23         return null;
24     },
26     get file_name () {
27         var file_uri_prefix = "file://";
28         if (this.uri.indexOf(file_uri_prefix) == 0)
29             return this.uri.substring(file_uri_prefix.length);
30         return null;
31     },
33     get best_uri () {
34         if (conkeror_source_code_path != null) {
35             var module_name = this.module_name;
36             if (module_name != null)
37                 return "file://" + conkeror_source_code_path + "/modules/" + module_name;
38         }
39         return this.uri;
40     },
42     open_in_editor : function() {
43         yield open_with_external_editor(load_spec(this.best_uri),
44                                         $line = this.line_number);
45     }
48 var get_caller_source_code_reference_ignored_functions = {};
50 function get_caller_source_code_reference (extra_frames_back) {
51     /* Skip at least this function itself and whoever called it (and
52      * more if the caller wants to be skipped). */
53     var frames_to_skip = 2;
54     if (extra_frames_back != null)
55         frames_to_skip += extra_frames_back;
57     for (let f = Components.stack; f != null; f = f.caller) {
58         if (frames_to_skip > 0) {
59             --frames_to_skip;
60             continue;
61         }
62         if (get_caller_source_code_reference_ignored_functions[f.name])
63             continue;
64         return new source_code_reference(f.filename, f.lineNumber);
65     }
67     return null;
70 function ignore_function_for_get_caller_source_code_reference (func_name) {
71     get_caller_source_code_reference_ignored_functions[func_name] = 1;
74 provide("source-code");