Skip to content

Instantly share code, notes, and snippets.

@hotsphink
Created January 7, 2020 23:21
Show Gist options
  • Save hotsphink/0d96222b2145c848de6045a67baf6a38 to your computer and use it in GitHub Desktop.
Save hotsphink/0d96222b2145c848de6045a67baf6a38 to your computer and use it in GitHub Desktop.
mkgist-created gist
# HG changeset patch
# User Ted Campbell <[email protected]>
# Date 0 0
# Branch default
# Node ID 574ef3bd069f82d8a22da2313dc0c15832398def
# Parent 8e4a18a47c2f
Bug 1602530 - Add more asserts about bytecode structure. r?jorendorff
Depends on D58439
Differential Revision: https://phabricator.services.mozilla.com/D58441
diff --git a/js/src/vm/JSScript.h b/js/src/vm/JSScript.h
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -3179,10 +3179,10 @@
// The following 3 functions find the static scope just before the
// execution of the instruction pointed to by pc.
- js::Scope* lookupScope(jsbytecode* pc);
+ js::Scope* lookupScope(jsbytecode* pc) const;
- js::Scope* innermostScope(jsbytecode* pc);
- js::Scope* innermostScope() { return innermostScope(main()); }
+ js::Scope* innermostScope(jsbytecode* pc) const;
+ js::Scope* innermostScope() const { return innermostScope(main()); }
/*
* The isEmpty method tells whether this script has code that computes any
diff --git a/js/src/vm/JSScript.cpp b/js/src/vm/JSScript.cpp
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -4561,6 +4561,12 @@
MOZ_ASSERT_IF(target < loc, target.is(JSOP_LOOPHEAD));
MOZ_ASSERT_IF(target < loc, IsBackedgePC(loc.toRawBytecode()));
+ // All forward jumps must be to a JSOP_JUMPTARGET op.
+ MOZ_ASSERT_IF(target > loc, target.is(JSOP_JUMPTARGET));
+
+ // Jumps must not cross scope boundaries.
+ MOZ_ASSERT(loc.innermostScope(this) == target.innermostScope(this));
+
// Check fallthrough of conditional jump instructions.
if (loc.fallsThrough()) {
BytecodeLocation fallthrough = loc.next();
@@ -5375,7 +5381,7 @@
return nlivefixed;
}
-Scope* JSScript::lookupScope(jsbytecode* pc) {
+Scope* JSScript::lookupScope(jsbytecode* pc) const {
MOZ_ASSERT(containsPC(pc));
size_t offset = pc - code();
@@ -5424,7 +5430,7 @@
return scope;
}
-Scope* JSScript::innermostScope(jsbytecode* pc) {
+Scope* JSScript::innermostScope(jsbytecode* pc) const {
if (Scope* scope = lookupScope(pc)) {
return scope;
}
diff --git a/js/src/vm/Interpreter.cpp b/js/src/vm/Interpreter.cpp
--- a/js/src/vm/Interpreter.cpp
+++ b/js/src/vm/Interpreter.cpp
@@ -1962,7 +1962,10 @@
CASE(JSOP_LINENO)
END_CASE(JSOP_LINENO)
- CASE(JSOP_FORCEINTERPRETER)
+ CASE(JSOP_FORCEINTERPRETER) {
+ // Ensure pattern matching still works.
+ MOZ_ASSERT(script->hasForceInterpreterOp());
+ }
END_CASE(JSOP_FORCEINTERPRETER)
CASE(JSOP_UNDEFINED) {
diff --git a/js/src/vm/BytecodeLocation.h b/js/src/vm/BytecodeLocation.h
--- a/js/src/vm/BytecodeLocation.h
+++ b/js/src/vm/BytecodeLocation.h
@@ -90,6 +90,8 @@
PropertyName* getPropertyName(const JSScript* script) const;
+ Scope* innermostScope(const JSScript* script) const;
+
#ifdef DEBUG
bool hasSameScript(const BytecodeLocation& other) const {
return debugOnlyScript_ == other.debugOnlyScript_;
diff --git a/js/src/vm/BytecodeLocation-inl.h b/js/src/vm/BytecodeLocation-inl.h
--- a/js/src/vm/BytecodeLocation-inl.h
+++ b/js/src/vm/BytecodeLocation-inl.h
@@ -36,6 +36,11 @@
return script->getName(this->rawBytecode_);
}
+inline Scope* BytecodeLocation::innermostScope(const JSScript* script) const {
+ MOZ_ASSERT(this->isValid());
+ return script->innermostScope(this->rawBytecode_);
+}
+
inline uint32_t BytecodeLocation::tableSwitchCaseOffset(
const JSScript* script, uint32_t caseIndex) const {
return script->tableSwitchCaseOffset(this->rawBytecode_, caseIndex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment