Skip to content

Commit 38be305

Browse files
Locating JS symbols
1 parent a663bba commit 38be305

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CustomisingSelenese.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ layout: default
88
# Identifying Javascript implementation of Selenese commands
99
Do not search for implementation functions of Selenese action [commands][command] case-sensitively. Actions (i.e. ones with primary forms that don't start with **`get`** neither with **`is`** and that are not like <code><strong>is</strong>Xyz<strong>Present</strong></code> - as per table at {{navAutoGeneratedSeleneseCommands}}) are defined in Javascript functions whose names start with **`do`**. E.g. command `xyz` is implemented in function <code><strong>do</strong>Xyz</code>.
1010

11-
For locating the source code of those Javascript functions see [JavascriptSpecial](JavascriptSpecial) > [Locating a Javascript function in sources](JavascriptSpecial#locating-a-javascript-function-in-sources).
11+
For locating the source code of those Javascript functions see [JavascriptSpecial](JavascriptSpecial) > [Locating a Javascript function in sources](JavascriptSpecial#locating-a-javascript-function).
1212

1313
# Defining functions in Selenium Core #
1414
This is for files normally loaded into [Core scope] (via [Bootstrap](Bootstrap) or [Extension Sequencer], which use [JavascriptComplex](JavascriptComplex) > [mozIJSSubScriptLoader](JavascriptComplex#mozIJSSubScriptLoader)). (That's not for {{navJavascriptCodeModules}}.)

JavascriptSpecial.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ layout: default
44
* TOC
55
{:toc}
66

7-
# Locating a Javascript function in sources #
8-
There are various ways of how to define/set/override a function in Javascript (usually through setting it as if it were a field on the class prototype object). So if you need to debug/modify/extend a function, it may not be easy to locate. You can use the following regular expressions to find definition(s) of a function (if implemented in one of the common ways). Replace `FUNCTION` with the name of the function.
7+
# Locating Javascript symbols in source
8+
9+
## Locating a Javascript function
10+
There are various ways of how to define/set/override a function in Javascript (usually through setting it as if it were a field on the class prototype object). Hence if you need to debug/modify/extend a function, it may not be easy to locate. You can use the following regular expressions to find definition of a function (if implemented in one of the common ways). Replace `FUNCTIONNAME` with the name of the function.
911

1012
The regex itself, e.g. for use in NetBeans:
1113

@@ -21,12 +23,25 @@ egrep -r "function\s+FUNCTIONNAME[^a-zA-Z0-9_]|[^a-zA-Z0-9_]FUNCTIONNAME\s*[:=]\
2123

2224
This is especially useful with Selenium which uses same name functions in various classes/components. There may be various versions of the same class/component, depending on how the code is executed - via Selenium IDE or via webdriver (but only Selenium Core and IDE is relevant to SeLite).
2325

26+
## Locating classes in Selenium IDE
2427
In Selenium IDE sources search for class definitions with regex:
2528

2629
```
2730
className *= *classCreate *\(
2831
```
2932

33+
## Locating variables and object fields
34+
Replace `VARIABLENAME` with the name of the variable. The regex itself, e.g. for use in NetBeans:
35+
36+
`[^a-zA-Z0-9_]VARIABLENAME\s*[:=]|\[\s*['"]VARIABLENAME['"]\s*\]\s*=|\.VARIABLENAME\s*[=]|var +([^\n;]+ *, *)*VARIABLENAME[ ,;\n]`
37+
38+
### Object fields from top-level variables
39+
When searching for an object field (rather than a variable), if the above doesn't find it as a field but only as a top-level variable, that may be when the Javascript file that defines the variable is loaded within a scope that is stored in the target object.
40+
41+
For example, _chrome/content/selenium-runner.js_ defines a top-level variable `var LOG`. That file is loaded within scope of `runner` object from file _content/debugger.js_. That defines field `LOG` in `runner` object.
42+
43+
Search for (literal) `.loadSubScript` and find one that is `.loadSubScript`( _locationOfJavascriptFileThatDefinesTheVariable_, _objectWhereThatVariableBecomesAField_ ).
44+
3045
# Function intercepts
3146
This is for extending or completely replacing behaviour of existing functions that come from Selenium or third party. It can be done for ordinary (non-member) functions (including class constructors) and also for methods (member functions of objects). Methods can be intercepted on either
3247

0 commit comments

Comments
 (0)