Commit 841763be authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[parser] Skipping inner funcs: Fix variable name debug mode check.

Apparently it can happen that the variable to which we're restoring to has a
two-byte name corresponding to the one-byte name we expect. Modify the debug-mode
name check to allow this.

BUG=v8:7428

Change-Id: I94c56a4b2de3c58b50246fecaead332b0f9679b4
Reviewed-on: https://chromium-review.googlesource.com/911801Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51304}
parent 7402841e
...@@ -14,7 +14,7 @@ struct PreparseDataConstants { ...@@ -14,7 +14,7 @@ struct PreparseDataConstants {
public: public:
// Layout and constants of the preparse data exchange format. // Layout and constants of the preparse data exchange format.
static const unsigned kMagicNumber = 0xBadDead; static const unsigned kMagicNumber = 0xBadDead;
static const unsigned kCurrentVersion = 17; static const unsigned kCurrentVersion = 18;
static const int kMagicOffset = 0; static const int kMagicOffset = 0;
static const int kVersionOffset = 1; static const int kVersionOffset = 1;
......
...@@ -396,6 +396,7 @@ void ProducedPreParsedScopeData::SaveDataForVariable(Variable* var) { ...@@ -396,6 +396,7 @@ void ProducedPreParsedScopeData::SaveDataForVariable(Variable* var) {
// Store the variable name in debug mode; this way we can check that we // Store the variable name in debug mode; this way we can check that we
// restore data to the correct variable. // restore data to the correct variable.
const AstRawString* name = var->raw_name(); const AstRawString* name = var->raw_name();
byte_data_->WriteUint8(name->is_one_byte());
byte_data_->WriteUint32(name->length()); byte_data_->WriteUint32(name->length());
for (int i = 0; i < name->length(); ++i) { for (int i = 0; i < name->length(); ++i) {
byte_data_->WriteUint8(name->raw_data()[i]); byte_data_->WriteUint8(name->raw_data()[i]);
...@@ -605,9 +606,20 @@ void ConsumedPreParsedScopeData::RestoreData(Scope* scope) { ...@@ -605,9 +606,20 @@ void ConsumedPreParsedScopeData::RestoreData(Scope* scope) {
void ConsumedPreParsedScopeData::RestoreDataForVariable(Variable* var) { void ConsumedPreParsedScopeData::RestoreDataForVariable(Variable* var) {
#ifdef DEBUG #ifdef DEBUG
const AstRawString* name = var->raw_name(); const AstRawString* name = var->raw_name();
bool data_one_byte = scope_data_->ReadUint8();
DCHECK_IMPLIES(name->is_one_byte(), data_one_byte);
DCHECK_EQ(scope_data_->ReadUint32(), static_cast<uint32_t>(name->length())); DCHECK_EQ(scope_data_->ReadUint32(), static_cast<uint32_t>(name->length()));
for (int i = 0; i < name->length(); ++i) { if (!name->is_one_byte() && data_one_byte) {
DCHECK_EQ(scope_data_->ReadUint8(), name->raw_data()[i]); // It's possible that "name" is a two-byte representation of the string
// stored in the data.
for (int i = 0; i < 2 * name->length(); i += 2) {
DCHECK_EQ(scope_data_->ReadUint8(), name->raw_data()[i]);
DCHECK_EQ(0, name->raw_data()[i + 1]);
}
} else {
for (int i = 0; i < name->length(); ++i) {
DCHECK_EQ(scope_data_->ReadUint8(), name->raw_data()[i]);
}
} }
#endif #endif
uint8_t variable_data = scope_data_->ReadQuarter(); uint8_t variable_data = scope_data_->ReadQuarter();
......
...@@ -365,3 +365,15 @@ TestSkippableFunctionInForOfHeaderAndBody(); ...@@ -365,3 +365,15 @@ TestSkippableFunctionInForOfHeaderAndBody();
function lazy(p = (function() {}, class {}, function() {}, class { method1() { } })) { } function lazy(p = (function() {}, class {}, function() {}, class { method1() { } })) { }
lazy(); lazy();
})(); })();
(function TestOneByteTwoByteMismatch() {
// Regression test for
// https://bugs.chromium.org/p/v8/issues/detail?id=7428
let name = 'weird_string\u2653'.slice(0, 12);
let o = {};
o[name] = null;
var x;
eval('x = function weird_string() { function skip() {} };');
x();
})();
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