Skip to content

Commit dd4c05c

Browse files
marjakhV8 LUCI CQ
authored andcommitted
[typed array length loading] Fix interaction with super
Bug: 388844115, 402646504 Change-Id: I17ff61116e68d98648a0ef8e710dfa9739135b8a Fixed: 402646504 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6348468 Reviewed-by: Victor Gomes <[email protected]> Auto-Submit: Marja Hölttä <[email protected]> Commit-Queue: Victor Gomes <[email protected]> Cr-Commit-Position: refs/heads/main@{#99242}
1 parent 13c7e79 commit dd4c05c

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/maglev/maglev-graph-builder.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6010,9 +6010,17 @@ MaybeReduceResult MaglevGraphBuilder::TryBuildPropertyLoad(
60106010
return AddNewNode<StringLength>({string});
60116011
}
60126012
case compiler::PropertyAccessInfo::kTypedArrayLength: {
6013-
DCHECK_EQ(receiver, lookup_start_object);
60146013
CHECK(!IsRabGsabTypedArrayElementsKind(access_info.elements_kind()));
6015-
return BuildLoadTypedArrayLength(receiver, access_info.elements_kind());
6014+
if (receiver != lookup_start_object) {
6015+
// We're accessing the TypedArray length via a prototype (a TypedArray
6016+
// object in the prototype chain, objects below it not having a "length"
6017+
// property, reading via super.length). That will throw a TypeError.
6018+
// This should never occur in any realistic code, so we can deopt here
6019+
// instead of implementing special handling for it.
6020+
return EmitUnconditionalDeopt(DeoptimizeReason::kWrongMap);
6021+
}
6022+
return BuildLoadTypedArrayLength(lookup_start_object,
6023+
access_info.elements_kind());
60166024
}
60176025
}
60186026
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2025 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --allow-natives-syntax --maglev --no-always-turbofan
6+
7+
const obj = {
8+
func(optimize) {
9+
const arrowFunc = () => {
10+
return super.length;
11+
};
12+
%PrepareFunctionForOptimization(arrowFunc);
13+
if (optimize) {
14+
%OptimizeMaglevOnNextCall(arrowFunc);
15+
}
16+
return arrowFunc();
17+
}
18+
};
19+
20+
// Make super.length polymorphic:
21+
// Case 1:
22+
assertEquals(undefined, obj.func(false));
23+
24+
// Case 2:
25+
const u8Arr = new Uint8Array(20);
26+
obj.__proto__ = u8Arr;
27+
assertThrows(() => { obj.func(false); }, TypeError);
28+
29+
// Optimize for Maglev.
30+
assertThrows(() => { obj.func(true); }, TypeError);

0 commit comments

Comments
 (0)