summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/fields/field-initializer-position.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/fields/field-initializer-position.js')
-rw-r--r--js/src/jit-test/tests/fields/field-initializer-position.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/fields/field-initializer-position.js b/js/src/jit-test/tests/fields/field-initializer-position.js
new file mode 100644
index 0000000000..f1c7f6f2d3
--- /dev/null
+++ b/js/src/jit-test/tests/fields/field-initializer-position.js
@@ -0,0 +1,52 @@
+// Test class field initializers have reasonable lineno/column values
+
+gczeal(0);
+
+// Use the Debugger API to introspect the line / column.
+let d = new Debugger();
+let g = newGlobal({newCompartment: true})
+let gw = d.addDebuggee(g);
+
+let source = `
+ let A = "A";
+ let B = "B";
+
+ class C {
+ // START----v
+ 'field_str';
+ 'field_str_with_init' = 1;
+ [A];
+ [B] = 2;
+ static x;
+ static y = 3;
+ static [A + "static"];
+ static [B + "static"] = 4;
+ // END
+ }
+`;
+
+let NumInitializers = 8;
+
+// Compute (1-based) line number of 'START' and 'END' markers.
+let START = source.split('\n').findIndex(x => x.includes("START")) + 1;
+let END = source.split('\n').findIndex(x => x.includes("END")) + 1;
+assertEq(END - START - 1, NumInitializers);
+
+// Use debugger to locate internal field-initializer scripts.
+g.evaluate(source);
+let scripts = d.findScripts()
+ .filter(script => (script.startLine >= START &&
+ script.startLine <= END));
+scripts.sort((x, y) => (x.sourceStart - y.sourceStart))
+
+for (var i = 0; i < NumInitializers; ++i) {
+ let script = scripts[i];
+ let lineText = source.split('\n')[START + i];
+
+ // Check the initializer lambda has expected line/column
+ assertEq(script.startLine, START + 1 + i);
+ assertEq(script.startColumn, 20);
+
+ // Check that source length matches expectations.
+ assertEq(script.startColumn + script.sourceLength + ';'.length, lineText.length);
+}