Commit b308c41a authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

[ast] Fix de-duping "get 0 {}" and "0: ..." inside objects

This fix makes ObjectLiteral::CalculateEmitStore work correctly.

Bug: v8:11810
Change-Id: I60f3d5cb657f4b2ca574d5224c8f1cb7a8216354
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2917040Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74986}
parent 4cb3c5cb
......@@ -1040,6 +1040,12 @@ bool Literal::ToBooleanIsTrue() const {
}
uint32_t Literal::Hash() {
uint32_t index;
if (AsArrayIndex(&index)) {
// Treat array indices as numbers, so that array indices are de-duped
// correctly even if one of them is a string and the other is a number.
return ComputeLongHash(index);
}
return IsString() ? AsRawString()->Hash()
: ComputeLongHash(double_to_uint64(AsNumber()));
}
......@@ -1048,6 +1054,11 @@ uint32_t Literal::Hash() {
bool Literal::Match(void* a, void* b) {
Literal* x = static_cast<Literal*>(a);
Literal* y = static_cast<Literal*>(b);
uint32_t index_x;
uint32_t index_y;
if (x->AsArrayIndex(&index_x)) {
return y->AsArrayIndex(&index_y) && index_x == index_y;
}
return (x->IsString() && y->IsString() &&
x->AsRawString() == y->AsRawString()) ||
(x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
......
// Copyright 2021 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.
function test(object, property) {
assertEquals('pass', object[property]);
}
(function TestStringProperty() {
let o1 = {get foo() { return 'fail'}, 'foo':'pass'};
test(o1, 'foo');
let o2 = {'foo':'fail', get foo() { return 'pass'}, };
test(o2, 'foo');
})();
(function TestNumberProperty() {
let o1 = {get 0() { return 'fail'}, 0:'pass'};
test(o1, 0);
let o2 = {0:'fail', get 0() { return 'pass'}};
test(o2, 0);
})();
(function TestBigNumberProperty() {
// Test a number which is too big to be considered an array index.
let o1 = {get 50000000000() { return 'fail'}, 50000000000:'pass'};
test(o1, 50000000000);
let o2 = {50000000000:'fail', get 50000000000() { return 'pass'}};
test(o2, 50000000000);
})();
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