Closed
Bug 151337
Opened 22 years ago
Closed 22 years ago
EcmaError.getLineSource() returns 0x0 characters.
Categories
(Rhino Graveyard :: Core, defect)
Tracking
(Not tracked)
VERIFIED
FIXED
1.5R4
People
(Reporter: morten, Assigned: norrisboyd)
Details
Attachments
(2 files)
949 bytes,
text/plain
|
Details | |
10.22 KB,
patch
|
Details | Diff | Splinter Review |
The function EcmaError.getLineSource() returns 0x0 ascii characters if the syntax error happened on a line that doesnt have a end of line before the script ends (last line of the code that doesnt have a newline in the end). For example, the script "illegal javascript syntax" will return "illegal javascript syntax[][][][][][][][][]" where [] is ascii 0x0. ---- Little code showing the problem ---- import org.mozilla.javascript.*; import java.io.*; public class EcmaError { public static void main(String args[]) throws JavaScriptException, IOException { Context cx = Context.enter(); Scriptable scope = cx.initStandardObjects(null); String s = "\njavascript syntax error"; // A script with syntax error and no newline try { Object result = cx.evaluateString(scope, s, "<cmd>", 1, null); } catch (EcmaError e) { e.printStackTrace(); for (int i = 0 ; i < e.getLineSource().length() ; i++ ) System.out.print(" " + (int)(e.getLineSource().charAt(i))); System.out.println("\nline is : \"" + e.getLineSource() + "\" (length of line = " + e.getLineSource().length() + ")"); } Context.exit(); } } ---- Run result --- 106 97 118 97 115 99 114 105 112 116 32 115 121 110 116 97 120 32 101 114 114 111 114 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 line is : "javascript syntax error" (length of line = 254) Notice the string is 254 characters long and have a lot of 0x0 ascii chars in the end. Sounds like a end of buffer problem.
Comment 1•22 years ago
|
||
The test should print PASSED if getLineSource returns proper string
Comment 2•22 years ago
|
||
I committed the patch which is big due to removal of startString/getString as TokenStream uses own buffer.
Comment 3•22 years ago
|
||
Fixed: it would be nice if Rhino will implement the line property of the error object to match SM so the test case can be written in JS...
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Comment 4•22 years ago
|
||
Verified FIXED. Before the patch, the above testcase failed as follows: FAILED! e.getLineSource() does not match 'javascript syntax error': javascript syntax error\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 After the patch: PASSED
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•