Skip to content

Commit dd24421

Browse files
committed
[JSC] DFG should not compile op_has_private_name as InById
https://bugs.webkit.org/show_bug.cgi?id=328284 Reviewed by Yusuke Suzuki. `#x in o` only looks at `o` itself. However, the DFG bytecode parser passes `op_has_private_name` to `handleInById`, which emits `InById` when it cannot emit `MatchStructure`. `InById` walks the prototype chain, so `#x in o` returns true when only the prototype of `o` has `#x`. This always happens with `--useAccessInlining=false`. With the default options, this is hidden because the inline cache gives up once the prototype has `#x`. This patch calls `handleInByAsMatchStructure` directly and falls back to `HasPrivateName`, as `op_has_private_brand` already does. Test: JSTests/stress/has-private-name-without-access-inlining.js * JSTests/stress/has-private-name-without-access-inlining.js: Added. (shouldBe): (Base): (Stamper.has): (Stamper): * Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::parseBlock): Canonical link: https://commits.webkit.org/324397@main
1 parent c22ca36 commit dd24421

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ requireOptions("--useAccessInlining=false")
2+
3+
function shouldBe(actual, expected) {
4+
if (actual !== expected)
5+
throw new Error("bad value: " + String(actual) + ", expected: " + String(expected));
6+
}
7+
8+
class Base {
9+
constructor(object) {
10+
return object;
11+
}
12+
}
13+
14+
class Stamper extends Base {
15+
#field;
16+
static has(object) {
17+
return #field in object;
18+
}
19+
}
20+
noInline(Stamper.has);
21+
22+
let prototype = { };
23+
let child = Object.create(prototype);
24+
for (let i = 0; i < testLoopCount; ++i)
25+
shouldBe(Stamper.has(child), false);
26+
27+
new Stamper(prototype);
28+
for (let i = 0; i < testLoopCount; ++i) {
29+
shouldBe(Stamper.has(child), false);
30+
shouldBe(Stamper.has(prototype), true);
31+
}

‎Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11189,7 +11189,7 @@ void ByteCodeParser::parseBlock(unsigned limit)
1118911189
auto bytecode = currentInstruction->as<OpHasPrivateName>();
1119011190
Node* base = get(bytecode.m_base);
1119111191
Node* property = get(bytecode.m_property);
11192-
bool compiledAsInById = false;
11192+
bool compiledAsMatchStructure = false;
1119311193

1119411194
if (!m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadIdent)
1119511195
&& !m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadType)
@@ -11204,12 +11204,11 @@ void ByteCodeParser::parseBlock(unsigned limit)
1120411204
ASSERT(identifier.isSymbolCell());
1120511205
FrozenValue* frozen = m_graph.freezeStrong(identifier.cell());
1120611206
addToGraph(CheckIsConstant, OpInfo(frozen), property);
11207-
handleInById(bytecode.m_dst, base, identifier, status, nextOpcodeIndex());
11208-
compiledAsInById = true;
11207+
compiledAsMatchStructure = handleInByAsMatchStructure(bytecode.m_dst, base, status);
1120911208
}
1121011209
}
1121111210

11212-
if (!compiledAsInById)
11211+
if (!compiledAsMatchStructure)
1121311212
set(bytecode.m_dst, addToGraph(HasPrivateName, base, property));
1121411213
NEXT_OPCODE(op_has_private_name);
1121511214
}

0 commit comments

Comments
 (0)