diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index 3e637416da..1db415292a 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -3534,11 +3534,18 @@ void CEntryStub::GenerateCore(MacroAssembler* masm, // Special handling of out of memory exceptions. JumpIfOOM(masm, r0, ip, throw_out_of_memory_exception); - // Retrieve the pending exception and clear the variable. - __ mov(r3, Operand(isolate->factory()->the_hole_value())); + // Retrieve the pending exception. __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress, isolate))); __ ldr(r0, MemOperand(ip)); + + // See if we just retrieved an OOM exception. + JumpIfOOM(masm, r0, ip, throw_out_of_memory_exception); + + // Clear the pending exception. + __ mov(r3, Operand(isolate->factory()->the_hole_value())); + __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress, + isolate))); __ str(r3, MemOperand(ip)); // Special handling of termination exceptions which are uncatchable diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc index 8d28c9c3ec..05dceb7e28 100644 --- a/src/ia32/code-stubs-ia32.cc +++ b/src/ia32/code-stubs-ia32.cc @@ -5065,8 +5065,13 @@ void CEntryStub::GenerateCore(MacroAssembler* masm, // Special handling of out of memory exceptions. JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); - // Retrieve the pending exception and clear the variable. + // Retrieve the pending exception. __ mov(eax, Operand::StaticVariable(pending_exception_address)); + + // See if we just retrieved an OOM exception. + JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); + + // Clear the pending exception. __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); __ mov(Operand::StaticVariable(pending_exception_address), edx); diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc index b43d583028..349adc512e 100644 --- a/src/x64/code-stubs-x64.cc +++ b/src/x64/code-stubs-x64.cc @@ -4152,12 +4152,19 @@ void CEntryStub::GenerateCore(MacroAssembler* masm, // Special handling of out of memory exceptions. JumpIfOOM(masm, rax, kScratchRegister, throw_out_of_memory_exception); - // Retrieve the pending exception and clear the variable. + // Retrieve the pending exception. ExternalReference pending_exception_address( Isolate::kPendingExceptionAddress, masm->isolate()); Operand pending_exception_operand = masm->ExternalOperand(pending_exception_address); __ movq(rax, pending_exception_operand); + + // See if we just retrieved an OOM exception. + JumpIfOOM(masm, rax, kScratchRegister, throw_out_of_memory_exception); + + // Clear the pending exception. + pending_exception_operand = + masm->ExternalOperand(pending_exception_address); __ LoadRoot(rdx, Heap::kTheHoleValueRootIndex); __ movq(pending_exception_operand, rdx);