Skip to content

Commit 795f9d8

Browse files
sepehrstjuanarbol
authored andcommitted
deps: V8: cherry-pick c875e86df1d7 (#2)
Original commit message: [bigint] Convert BigInt property names to decimal Hexadecimal/octal/binary BigInt property names should be converted to decimal, i.e. the following object literals should all be equivalent: var o = {0xF: 1}, p = {0xFn: 1}, q = {15: 1}, r = {15n: 1}. Test case by [email protected], uploaded at https://chromium-review.googlesource.com/c/v8/v8/+/3634937 Fixed: v8:10600 Change-Id: Ie1d8a16e95697cd31cbc0784843779c921ce91fa Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3642302 Reviewed-by: Toon Verwaest <[email protected]> Commit-Queue: Jakob Kummerow <[email protected]> Cr-Commit-Position: refs/heads/main@{#80490} Refs: v8/v8@c875e86 PR-URL: #46501 Refs: v8/v8@c875e86 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
1 parent b266adb commit 795f9d8

File tree

9 files changed

+71
-2
lines changed

9 files changed

+71
-2
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.22',
39+
'v8_embedder_string': '-node.23',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/src/numbers/conversions.cc

+25
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "src/base/numbers/dtoa.h"
1313
#include "src/base/numbers/strtod.h"
1414
#include "src/base/platform/wrappers.h"
15+
#include "src/base/small-vector.h"
1516
#include "src/bigint/bigint.h"
1617
#include "src/common/assert-scope.h"
1718
#include "src/handles/handles.h"
@@ -970,6 +971,23 @@ class StringToBigIntHelper : public StringToIntHelper<IsolateT> {
970971
UNREACHABLE();
971972
}
972973

974+
// Used for converting BigInt literals. The scanner has already checked
975+
// that the literal is valid and not too big, so this always succeeds.
976+
std::unique_ptr<char[]> DecimalString(bigint::Processor* processor) {
977+
DCHECK_EQ(behavior_, Behavior::kLiteral);
978+
this->ParseInt();
979+
DCHECK_EQ(this->state(), State::kDone);
980+
int num_digits = accumulator_.ResultLength();
981+
base::SmallVector<bigint::digit_t, 8> digit_storage(num_digits);
982+
bigint::RWDigits digits(digit_storage.data(), num_digits);
983+
processor->FromString(digits, &accumulator_);
984+
int num_chars = bigint::ToStringResultLength(digits, 10, false);
985+
std::unique_ptr<char[]> out(new char[num_chars + 1]);
986+
processor->ToString(out.get(), &num_chars, digits, 10, false);
987+
out[num_chars] = '\0';
988+
return out;
989+
}
990+
973991
private:
974992
template <class Char>
975993
void ParseInternal(Char start) {
@@ -1018,6 +1036,13 @@ template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE)
10181036
MaybeHandle<BigInt> BigIntLiteral(LocalIsolate* isolate,
10191037
const char* string);
10201038

1039+
std::unique_ptr<char[]> BigIntLiteralToDecimal(
1040+
LocalIsolate* isolate, base::Vector<const uint8_t> literal) {
1041+
StringToBigIntHelper<LocalIsolate> helper(nullptr, literal.begin(),
1042+
literal.length());
1043+
return helper.DecimalString(isolate->bigint_processor());
1044+
}
1045+
10211046
const char* DoubleToCString(double v, base::Vector<char> buffer) {
10221047
switch (FPCLASSIFY_NAMESPACE::fpclassify(v)) {
10231048
case FP_NAN:

deps/v8/src/numbers/conversions.h

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ const int kDoubleToCStringMinBufferSize = 100;
119119
V8_EXPORT_PRIVATE const char* DoubleToCString(double value,
120120
base::Vector<char> buffer);
121121

122+
V8_EXPORT_PRIVATE std::unique_ptr<char[]> BigIntLiteralToDecimal(
123+
LocalIsolate* isolate, base::Vector<const uint8_t> literal);
122124
// Convert an int to a null-terminated string. The returned string is
123125
// located inside the buffer, but not necessarily at the start.
124126
V8_EXPORT_PRIVATE const char* IntToCString(int n, base::Vector<char> buffer);

deps/v8/src/parsing/parser-base.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2288,7 +2288,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseProperty(
22882288

22892289
case Token::BIGINT: {
22902290
Consume(Token::BIGINT);
2291-
prop_info->name = impl()->GetSymbol();
2291+
prop_info->name = impl()->GetBigIntAsSymbol();
22922292
is_array_index = impl()->IsArrayIndex(prop_info->name, &index);
22932293
break;
22942294
}

deps/v8/src/parsing/parser.cc

+10
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,16 @@ bool Parser::CollapseNaryExpression(Expression** x, Expression* y,
247247
return true;
248248
}
249249

250+
const AstRawString* Parser::GetBigIntAsSymbol() {
251+
base::Vector<const uint8_t> literal = scanner()->BigIntLiteral();
252+
if (literal[0] != '0' || literal.length() == 1) {
253+
return ast_value_factory()->GetOneByteString(literal);
254+
}
255+
std::unique_ptr<char[]> decimal =
256+
BigIntLiteralToDecimal(local_isolate_, literal);
257+
return ast_value_factory()->GetOneByteString(decimal.get());
258+
}
259+
250260
Expression* Parser::BuildUnaryExpression(Expression* expression,
251261
Token::Value op, int pos) {
252262
DCHECK_NOT_NULL(expression);

deps/v8/src/parsing/parser.h

+2
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
790790
return ast_value_factory()->GetOneByteString(string);
791791
}
792792

793+
const AstRawString* GetBigIntAsSymbol();
794+
793795
class ThisExpression* ThisExpression() {
794796
UseThis();
795797
return factory()->ThisExpression();

deps/v8/src/parsing/preparser.h

+4
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,10 @@ class PreParser : public ParserBase<PreParser> {
15221522
return PreParserIdentifier::Default();
15231523
}
15241524

1525+
V8_INLINE PreParserIdentifier GetBigIntAsSymbol() const {
1526+
return PreParserIdentifier::Default();
1527+
}
1528+
15251529
V8_INLINE PreParserExpression ThisExpression() {
15261530
UseThis();
15271531
return PreParserExpression::This();

deps/v8/src/parsing/scanner.h

+3
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ class V8_EXPORT_PRIVATE Scanner {
336336
AstValueFactory* ast_value_factory) const;
337337

338338
double DoubleValue();
339+
base::Vector<const uint8_t> BigIntLiteral() const {
340+
return literal_one_byte_string();
341+
}
339342

340343
const char* CurrentLiteralAsCString(Zone* zone) const;
341344

deps/v8/test/mjsunit/harmony/bigint/property-names.js

+23
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,26 @@ assertEquals(it, 1);
77

88
var { 999999999999999999n: it } = { 999999999999999999n: 1 }; // greater than max safe integer
99
assertEquals(it, 1);
10+
11+
var obj = { 0xfffffffffffffffffffffn: 1};
12+
assertEquals(1, obj["19342813113834066795298815"]);
13+
14+
var obj2 = {0o777777777777777777777777777n: 1};
15+
assertEquals(1, obj2["2417851639229258349412351"]);
16+
17+
var obj3 = { 0x4n: 'hi' };
18+
19+
assertEquals('hi', obj3[4]);
20+
assertEquals(undefined, obj3["0x4"]);
21+
22+
let obj4 =
23+
{12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890n: 1};
24+
assertEquals(
25+
1,
26+
obj4["12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"]);
27+
28+
// 130 hex digits
29+
let obj5 = {0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn: 1};
30+
assertEquals(
31+
1,
32+
obj5["3432398830065304857490950399540696608634717650071652704697231729592771591698828026061279820330727277488648155695740429018560993999858321906287014145557528575"]);

0 commit comments

Comments
 (0)