diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 9755446060e5..47cd76fae691 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -123,7 +123,7 @@ BytecodeEmitter::BytecodeEmitter(BytecodeEmitter* parent, SharedContext* sc, : sc(sc), cx(sc->cx_), parent(parent), - bytecodeSection_(cx, sc->extent().lineno, sc->extent().column), + bytecodeSection_(cx, sc->extent().lineno), perScriptData_(cx, compilationInfo), compilationInfo(compilationInfo), compilationState(compilationState), @@ -554,11 +554,6 @@ bool BytecodeEmitter::updateLineNumberNotes(uint32_t offset) { unsigned line = er->lineAt(offset); unsigned delta = line - bytecodeSection().currentLine(); - // If we use a `SetLine` note below, we want it to be relative to the - // scripts initial line number for better chance of sharing. - unsigned initialLine = sc->extent().lineno; - MOZ_ASSERT(line >= initialLine); - /* * Encode any change in the current source line number by using * either several SrcNoteType::NewLine notes or just one @@ -571,9 +566,10 @@ bool BytecodeEmitter::updateLineNumberNotes(uint32_t offset) { * SrcNoteType::SetLine. */ bytecodeSection().setCurrentLine(line, offset); - if (delta >= SrcNote::SetLine::lengthFor(line, initialLine)) { + if (delta >= SrcNote::SetLine::lengthFor(line)) { + MOZ_ASSERT(line >= sc->extent().lineno); if (!newSrcNote2(SrcNoteType::SetLine, - SrcNote::SetLine::toOperand(line, initialLine))) { + SrcNote::SetLine::toOperand(line))) { return false; } } else { diff --git a/js/src/frontend/BytecodeSection.cpp b/js/src/frontend/BytecodeSection.cpp index e9ea9c007842..92eb7d16f9f2 100644 --- a/js/src/frontend/BytecodeSection.cpp +++ b/js/src/frontend/BytecodeSection.cpp @@ -188,16 +188,14 @@ JSObject* ObjLiteralStencil::create(JSContext* cx, return InterpretObjLiteral(cx, atomCache, atoms_, writer_); } -BytecodeSection::BytecodeSection(JSContext* cx, uint32_t lineNum, - uint32_t column) +BytecodeSection::BytecodeSection(JSContext* cx, uint32_t lineNum) : code_(cx), notes_(cx), lastNoteOffset_(0), tryNoteList_(cx), scopeNoteList_(cx), resumeOffsetList_(cx), - currentLine_(lineNum), - lastColumn_(column) {} + currentLine_(lineNum) {} void BytecodeSection::updateDepth(BytecodeOffset target) { jsbytecode* pc = code(target); diff --git a/js/src/frontend/BytecodeSection.h b/js/src/frontend/BytecodeSection.h index e0804124c279..427fbb63b24f 100644 --- a/js/src/frontend/BytecodeSection.h +++ b/js/src/frontend/BytecodeSection.h @@ -189,7 +189,7 @@ typedef Vector SrcNotesVector; // bytecode is stored in this class. class BytecodeSection { public: - BytecodeSection(JSContext* cx, uint32_t lineNum, uint32_t column); + BytecodeSection(JSContext* cx, uint32_t lineNum); // ---- Bytecode ---- diff --git a/js/src/frontend/SourceNotes.h b/js/src/frontend/SourceNotes.h index 287942a4260f..548d9c7ce871 100644 --- a/js/src/frontend/SourceNotes.h +++ b/js/src/frontend/SourceNotes.h @@ -249,18 +249,13 @@ class SrcNote { } public: - static inline unsigned lengthFor(unsigned line, size_t initialLine) { - unsigned operandSize = - toOperand(line, initialLine) > SrcNote::FourBytesOperandMask ? 4 : 1; - return 1 /* SetLine */ + operandSize; + static inline unsigned lengthFor(unsigned line) { + return 1 /* SetLine */ + (line > SrcNote::FourBytesOperandMask ? 4 : 1); } - static inline ptrdiff_t toOperand(size_t line, size_t initialLine) { - MOZ_ASSERT(line >= initialLine); - return ptrdiff_t(line - initialLine); - } + static inline ptrdiff_t toOperand(size_t line) { return ptrdiff_t(line); } - static inline size_t getLine(const SrcNote* sn, size_t initialLine); + static inline size_t getLine(const SrcNote* sn); }; friend class SrcNoteWriter; @@ -368,9 +363,8 @@ inline ptrdiff_t SrcNote::ColSpan::getSpan(const SrcNote* sn) { } /* static */ -inline size_t SrcNote::SetLine::getLine(const SrcNote* sn, size_t initialLine) { - return initialLine + - fromOperand(SrcNoteReader::getOperand(sn, unsigned(Operands::Line))); +inline size_t SrcNote::SetLine::getLine(const SrcNote* sn) { + return fromOperand(SrcNoteReader::getOperand(sn, unsigned(Operands::Line))); } // Iterate over SrcNote array, until it hits terminator. diff --git a/js/src/jit-test/tests/parser/bytecode-sharing.js b/js/src/jit-test/tests/parser/bytecode-sharing.js index 26f0ac429c90..1f0764aaf547 100644 --- a/js/src/jit-test/tests/parser/bytecode-sharing.js +++ b/js/src/jit-test/tests/parser/bytecode-sharing.js @@ -18,7 +18,7 @@ evaluate(`function b03( ){}`) evaluate(`function b04() {}`) evaluate(`function b05(){ }`) assertEq(hasSameBytecodeData(b, b01), true) -assertEq(hasSameBytecodeData(b, b02), true) +assertEq(hasSameBytecodeData(b, b02), false) assertEq(hasSameBytecodeData(b, b03), false) assertEq(hasSameBytecodeData(b, b04), false) assertEq(hasSameBytecodeData(b, b05), false) @@ -73,16 +73,16 @@ assertEq(hasSameBytecodeData(h01, h03), true) evaluate(`function i01(){ return\n\n\n\n\n\n\n\n0; }`) evaluate(`\nfunction i02(){ return\n\n\n\n\n\n\n\n0; }`) evaluate(`\n\n\n\n\n\n\nfunction i03(){ return\n\n\n\n\n\n\n\n0; }`) -assertEq(hasSameBytecodeData(i01, i02), true) -assertEq(hasSameBytecodeData(i01, i03), true) +assertEq(hasSameBytecodeData(i01, i02), false) +assertEq(hasSameBytecodeData(i01, i03), false) // Check effect of column number. evaluate(`function j01(){ return 0; }`) evaluate(` function j02(){ return 0; }`) evaluate(` \tfunction j03(){ return 0; }`) -assertEq(hasSameBytecodeData(j01, j02), true) -assertEq(hasSameBytecodeData(j01, j03), true) +assertEq(hasSameBytecodeData(j01, j02), false) +assertEq(hasSameBytecodeData(j01, j03), false) // Check different forms of functions. diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 30d160a95f68..73641f531078 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -3127,7 +3127,7 @@ static MOZ_MUST_USE bool SrcNotes(JSContext* cx, HandleScript script, break; case SrcNoteType::SetLine: - lineno = SrcNote::SetLine::getLine(sn, script->lineno()); + lineno = SrcNote::SetLine::getLine(sn); if (!sp->jsprintf(" lineno %u", lineno)) { return false; } diff --git a/js/src/vm/BytecodeUtil-inl.h b/js/src/vm/BytecodeUtil-inl.h index 776bfa1b91e1..dadfd65d5a05 100644 --- a/js/src/vm/BytecodeUtil-inl.h +++ b/js/src/vm/BytecodeUtil-inl.h @@ -114,9 +114,8 @@ class BytecodeRangeWithPosition : private BytecodeRange { BytecodeRangeWithPosition(JSContext* cx, JSScript* script) : BytecodeRange(cx, script), - initialLine(script->lineno()), lineno(script->lineno()), - column(script->column()), + column(0), sn(script->notes()), snpc(script->code()), isEntryPoint(false), @@ -204,7 +203,7 @@ class BytecodeRangeWithPosition : private BytecodeRange { column += colspan; lastLinePC = snpc; } else if (type == SrcNoteType::SetLine) { - lineno = SrcNote::SetLine::getLine(sn, initialLine); + lineno = SrcNote::SetLine::getLine(sn); column = 0; lastLinePC = snpc; } else if (type == SrcNoteType::NewLine) { @@ -224,7 +223,6 @@ class BytecodeRangeWithPosition : private BytecodeRange { isEntryPoint = lastLinePC == frontPC(); } - size_t initialLine; size_t lineno; size_t column; const SrcNote* sn; diff --git a/js/src/vm/CodeCoverage.cpp b/js/src/vm/CodeCoverage.cpp index f96cfdff68c3..62ddf170d673 100644 --- a/js/src/vm/CodeCoverage.cpp +++ b/js/src/vm/CodeCoverage.cpp @@ -178,7 +178,7 @@ void LCovSource::writeScript(JSScript* script, const char* scriptName) { sn = *iter; SrcNoteType type = sn->type(); if (type == SrcNoteType::SetLine) { - lineno = SrcNote::SetLine::getLine(sn, script->lineno()); + lineno = SrcNote::SetLine::getLine(sn); } else if (type == SrcNoteType::NewLine) { lineno++; } diff --git a/js/src/vm/JSScript.cpp b/js/src/vm/JSScript.cpp index 8a074778d1fb..7997b9e7d6aa 100644 --- a/js/src/vm/JSScript.cpp +++ b/js/src/vm/JSScript.cpp @@ -4027,11 +4027,11 @@ const js::SrcNote* js::GetSrcNote(JSContext* cx, JSScript* script, return GetSrcNote(cx->caches().gsnCache, script, pc); } -unsigned js::PCToLineNumber(unsigned startLine, unsigned startCol, - SrcNote* notes, jsbytecode* code, jsbytecode* pc, +unsigned js::PCToLineNumber(unsigned startLine, SrcNote* notes, + jsbytecode* code, jsbytecode* pc, unsigned* columnp) { unsigned lineno = startLine; - unsigned column = startCol; + unsigned column = 0; /* * Walk through source notes accumulating their deltas, keeping track of @@ -4049,7 +4049,7 @@ unsigned js::PCToLineNumber(unsigned startLine, unsigned startCol, SrcNoteType type = sn->type(); if (type == SrcNoteType::SetLine) { - lineno = SrcNote::SetLine::getLine(sn, startLine); + lineno = SrcNote::SetLine::getLine(sn); column = 0; } else if (type == SrcNoteType::NewLine) { lineno++; @@ -4075,8 +4075,8 @@ unsigned js::PCToLineNumber(JSScript* script, jsbytecode* pc, return 0; } - return PCToLineNumber(script->lineno(), script->column(), script->notes(), - script->code(), pc, columnp); + return PCToLineNumber(script->lineno(), script->notes(), script->code(), pc, + columnp); } jsbytecode* js::LineNumberToPC(JSScript* script, unsigned target) { @@ -4103,7 +4103,7 @@ jsbytecode* js::LineNumberToPC(JSScript* script, unsigned target) { offset += sn->delta(); SrcNoteType type = sn->type(); if (type == SrcNoteType::SetLine) { - lineno = SrcNote::SetLine::getLine(sn, script->lineno()); + lineno = SrcNote::SetLine::getLine(sn); } else if (type == SrcNoteType::NewLine) { lineno++; } @@ -4122,7 +4122,7 @@ JS_FRIEND_API unsigned js::GetScriptLineExtent(JSScript* script) { auto sn = *iter; SrcNoteType type = sn->type(); if (type == SrcNoteType::SetLine) { - lineno = SrcNote::SetLine::getLine(sn, script->lineno()); + lineno = SrcNote::SetLine::getLine(sn); } else if (type == SrcNoteType::NewLine) { lineno++; } diff --git a/js/src/vm/JSScript.h b/js/src/vm/JSScript.h index e46d4db9a787..75b3d51ad38e 100644 --- a/js/src/vm/JSScript.h +++ b/js/src/vm/JSScript.h @@ -2590,8 +2590,8 @@ namespace js { extern unsigned PCToLineNumber(JSScript* script, jsbytecode* pc, unsigned* columnp = nullptr); -extern unsigned PCToLineNumber(unsigned startLine, unsigned startCol, - SrcNote* notes, jsbytecode* code, jsbytecode* pc, +extern unsigned PCToLineNumber(unsigned startLine, SrcNote* notes, + jsbytecode* code, jsbytecode* pc, unsigned* columnp = nullptr); /*