Skip to content

Commit

Permalink
Bug 1677354 - Part 2: Assert all non-top-level scripts are function. …
Browse files Browse the repository at this point in the history
…r=tcampbell

Differential Revision: https://phabricator.services.mozilla.com/D97112
  • Loading branch information
arai-a committed Dec 12, 2020
1 parent 8cb2349 commit 0712077
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
25 changes: 15 additions & 10 deletions js/src/frontend/CompilationInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,19 @@ class ScriptStencilIterable {
Iterator(const CompilationStencil& stencil, CompilationGCOutput& gcOutput,
size_t index)
: index_(index), stencil_(stencil), gcOutput_(gcOutput) {
skipNonFunctions();
MOZ_ASSERT(index == stencil.scriptData.length());
}

public:
explicit Iterator(const CompilationStencil& stencil,
CompilationGCOutput& gcOutput)
: stencil_(stencil), gcOutput_(gcOutput) {
skipNonFunctions();
skipTopLevelNonFunction();
}

Iterator operator++() {
next();
skipNonFunctions();
assertFunction();
return *this;
}

Expand All @@ -364,14 +364,19 @@ class ScriptStencilIterable {
index_++;
}

void skipNonFunctions() {
size_t length = stencil_.scriptData.length();
while (index_ < length) {
if (stencil_.scriptData[index_].isFunction()) {
return;
}
void assertFunction() {
if (index_ < stencil_.scriptData.length()) {
MOZ_ASSERT(stencil_.scriptData[index_].isFunction());
}
}

index_++;
void skipTopLevelNonFunction() {
MOZ_ASSERT(index_ == 0);
if (stencil_.scriptData.length()) {
if (!stencil_.scriptData[0].isFunction()) {
next();
assertFunction();
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions js/src/jit-test/tests/parser/optimized-out-functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Functions optimized out by constant-folding should have correct
// stencil data.
// This shouldn't hit any assertion while iterating stencil while instantiation.
(function() {
(function() {
});
});

0 comments on commit 0712077

Please sign in to comment.