Skip to content

Commit 2aa070b

Browse files
ripsawridgeCommit bot
authored andcommitted
InstanceOfStub incorrectly interprets the hole as a prototype.
Repair this to match what the runtime correctly does, by first checking if the function is a constructor before we access the prototype. [email protected] BUG= Review URL: https://codereview.chromium.org/1810953002 Cr-Commit-Position: refs/heads/master@{#34863}
1 parent 165b68e commit 2aa070b

7 files changed

Lines changed: 30 additions & 5 deletions

File tree

src/arm/code-stubs-arm.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,8 +1371,12 @@ void InstanceOfStub::Generate(MacroAssembler* masm) {
13711371
__ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE);
13721372
__ b(ne, &slow_case);
13731373

1374-
// Ensure that {function} has an instance prototype.
1374+
// Go to the runtime if the function is not a constructor.
13751375
__ ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1376+
__ tst(scratch, Operand(1 << Map::kIsConstructor));
1377+
__ b(eq, &slow_case);
1378+
1379+
// Ensure that {function} has an instance prototype.
13761380
__ tst(scratch, Operand(1 << Map::kHasNonInstancePrototype));
13771381
__ b(ne, &slow_case);
13781382

src/arm64/code-stubs-arm64.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,8 +1557,11 @@ void InstanceOfStub::Generate(MacroAssembler* masm) {
15571557
__ JumpIfNotObjectType(function, function_map, scratch, JS_FUNCTION_TYPE,
15581558
&slow_case);
15591559

1560-
// Ensure that {function} has an instance prototype.
1560+
// Go to the runtime if the function is not a constructor.
15611561
__ Ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1562+
__ Tbz(scratch, Map::kIsConstructor, &slow_case);
1563+
1564+
// Ensure that {function} has an instance prototype.
15621565
__ Tbnz(scratch, Map::kHasNonInstancePrototype, &slow_case);
15631566

15641567
// Get the "prototype" (or initial map) of the {function}.

src/ia32/code-stubs-ia32.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,11 @@ void InstanceOfStub::Generate(MacroAssembler* masm) {
21372137
__ CmpObjectType(function, JS_FUNCTION_TYPE, function_map);
21382138
__ j(not_equal, &slow_case);
21392139

2140+
// Go to the runtime if the function is not a constructor.
2141+
__ test_b(FieldOperand(function_map, Map::kBitFieldOffset),
2142+
static_cast<uint8_t>(1 << Map::kIsConstructor));
2143+
__ j(zero, &slow_case);
2144+
21402145
// Ensure that {function} has an instance prototype.
21412146
__ test_b(FieldOperand(function_map, Map::kBitFieldOffset),
21422147
static_cast<uint8_t>(1 << Map::kHasNonInstancePrototype));

src/mips/code-stubs-mips.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,8 +1503,12 @@ void InstanceOfStub::Generate(MacroAssembler* masm) {
15031503
__ GetObjectType(function, function_map, scratch);
15041504
__ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
15051505

1506-
// Ensure that {function} has an instance prototype.
1506+
// Go to the runtime if the function is not a constructor.
15071507
__ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1508+
__ And(at, scratch, Operand(1 << Map::kIsConstructor));
1509+
__ Branch(&slow_case, eq, at, Operand(zero_reg));
1510+
1511+
// Ensure that {function} has an instance prototype.
15081512
__ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype));
15091513
__ Branch(&slow_case, ne, at, Operand(zero_reg));
15101514

src/mips64/code-stubs-mips64.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,12 @@ void InstanceOfStub::Generate(MacroAssembler* masm) {
14991499
__ GetObjectType(function, function_map, scratch);
15001500
__ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE));
15011501

1502-
// Ensure that {function} has an instance prototype.
1502+
// Go to the runtime if the function is not a constructor.
15031503
__ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset));
1504+
__ And(at, scratch, Operand(1 << Map::kIsConstructor));
1505+
__ Branch(&slow_case, eq, at, Operand(zero_reg));
1506+
1507+
// Ensure that {function} has an instance prototype.
15041508
__ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype));
15051509
__ Branch(&slow_case, ne, at, Operand(zero_reg));
15061510

src/x64/code-stubs-x64.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,11 @@ void InstanceOfStub::Generate(MacroAssembler* masm) {
20922092
__ CmpObjectType(function, JS_FUNCTION_TYPE, function_map);
20932093
__ j(not_equal, &slow_case);
20942094

2095+
// Go to the runtime if the function is not a constructor.
2096+
__ testb(FieldOperand(function_map, Map::kBitFieldOffset),
2097+
Immediate(1 << Map::kIsConstructor));
2098+
__ j(zero, &slow_case);
2099+
20952100
// Ensure that {function} has an instance prototype.
20962101
__ testb(FieldOperand(function_map, Map::kBitFieldOffset),
20972102
Immediate(1 << Map::kHasNonInstancePrototype));

test/mjsunit/regress/regress-crbug-573858.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var throw_type_error = Object.getOwnPropertyDescriptor(
99

1010
function create_initial_map() { this instanceof throw_type_error }
1111
%OptimizeFunctionOnNextCall(create_initial_map);
12-
create_initial_map();
12+
assertThrows(create_initial_map);
1313

1414
function test() { new throw_type_error }
1515
%OptimizeFunctionOnNextCall(test);

0 commit comments

Comments
 (0)