Commit e8d86597 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[parsing] Improve elision of hole checks for default parameters

Use the position of the next parameter to be declared as the end of the
initializer for default parameters, so that hole checks can be elided
for initializers using previous parameters in arrow functions.

This fixes a source of bytecode mismatches when collecting source
positions lazily.

Bug: chromium:980422, v8:8510
Change-Id: I5ab074231248b661156e7d8e47c01685448b56d5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1683267Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62525}
parent fb3445dc
......@@ -695,9 +695,15 @@ class ArrowHeadParsingScope : public ExpressionParsingScope<Types> {
}
}
int initializer_position = this->parser()->end_position();
auto var_it = this->variable_list()->begin();
for (auto declaration : *result->declarations()) {
declaration->var()->set_initializer_position(initializer_position);
// If it's not the last variable, then use the position of the next
// variable. For the last one, use the end position of the arrow head.
int end_position = var_it + 1 == this->variable_list()->end()
? this->parser()->end_position()
: (*(var_it + 1))->position();
declaration->var()->set_initializer_position(end_position);
var_it++;
}
if (uses_this_) result->UsesThis();
return result;
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --enable-lazy-source-positions
try {
(function () {
((d, e = d) => {
throw new Error();
})();
})();
} catch (ex) {
print(ex.stack);
}
try {
(function () {
((d, e = f, f = d) => {
// Won't get here as the initializers will cause a ReferenceError
})();
})();
} catch (ex) {
print(ex.stack);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment