| 1 |
// Simple tests for evaluate's "columnNumber" option. |
| 2 |
|
| 3 |
load(libdir + 'asserts.js'); |
| 4 |
|
| 5 |
assertEq(evaluate("saveStack().column"), 1); |
| 6 |
assertEq(evaluate("saveStack().column", { columnNumber: 1729 }), 1729); |
| 7 |
assertEq(evaluate("\nsaveStack().column", { columnNumber: 1729 }), 1); |
| 8 |
assertEq(evaluate("saveStack().column", { columnNumber: "42" }), 42); |
| 9 |
// columnNumber < 1 is fixed to 1. |
| 10 |
assertEq(evaluate("saveStack().column", { columnNumber: -10 }), 1); |
| 11 |
assertThrowsInstanceOf(() => evaluate("saveStack().column", { columnNumber: Math.pow(2,30) }), |
| 12 |
RangeError); |
| 13 |
|
| 14 |
if (helperThreadCount() > 0) { |
| 15 |
print("offThreadCompileToStencil 1"); |
| 16 |
offThreadCompileToStencil("saveStack().column", { columnNumber: -10 }); |
| 17 |
var stencil = finishOffThreadStencil(); |
| 18 |
assertEq(evalStencil(stencil), 1); |
| 19 |
|
| 20 |
print("offThreadCompileToStencil 2"); |
| 21 |
offThreadCompileToStencil("saveStack().column", { columnNumber: Math.pow(2,30) }); |
| 22 |
assertThrowsInstanceOf(() => { |
| 23 |
var stencil = finishOffThreadStencil(); |
| 24 |
evalStencil(); |
| 25 |
}, RangeError); |
| 26 |
|
| 27 |
print("offThreadCompileToStencil 3"); |
| 28 |
offThreadCompileToStencil("saveStack().column", { columnNumber: 10000 }); |
| 29 |
stencil = finishOffThreadStencil(); |
| 30 |
assertEq(evalStencil(stencil), 10000); |
| 31 |
} |
| 32 |
|
| 33 |
// Check handling of columns near the limit of our ability to represent them. |
| 34 |
// (This is hardly thorough, but since web content can't set column numbers, |
| 35 |
// it's probably not worth it to be thorough.) |
| 36 |
const maxColumn = Math.pow(2, 30) - 2; |
| 37 |
assertEq(evaluate("saveStack().column", { columnNumber: maxColumn }), |
| 38 |
maxColumn); |
| 39 |
|
| 40 |
// Check the saturation behavior when we reach the limit of the column |
| 41 |
// representation. |
| 42 |
assertEq(evaluate(" saveStack().column", { columnNumber: maxColumn }), |
| 43 |
maxColumn + 1); |
| 44 |
|
| 45 |
// Gathering source text for inclusion in error messages should not try to reach |
| 46 |
// outside the buffer to find the start of the source line. The below should |
| 47 |
// report the error without crashing. |
| 48 |
assertThrowsInstanceOf(() => evaluate("function x(y,y) { 'use strict'; } x()", |
| 49 |
{ columnNumber: 10 }), |
| 50 |
SyntaxError); |