Index: src/x64/macro-assembler-x64.cc |
diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc |
index 32a92a6c651f9402f3089f82afc39d8c1e19982f..1b0f2fa2d4fb196b3184ef9cf9e8ba8c6fe7ac82 100644 |
--- a/src/x64/macro-assembler-x64.cc |
+++ b/src/x64/macro-assembler-x64.cc |
@@ -751,6 +751,41 @@ void MacroAssembler::CallApiFunctionAndReturn(Address function_address, |
Cmp(Operand(rsi, 0), factory->the_hole_value()); |
j(not_equal, &promote_scheduled_exception); |
+#if ENABLE_EXTRA_CHECKS |
+ // Check if the function returned a valid JavaScript value. |
+ Label ok; |
+ Register return_value = rax; |
+ Register map = rcx; |
+ |
+ JumpIfSmi(return_value, &ok, Label::kNear); |
+ movq(map, FieldOperand(return_value, HeapObject::kMapOffset)); |
+ |
+ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
+ j(below, &ok, Label::kNear); |
+ |
+ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
+ j(above_equal, &ok, Label::kNear); |
+ |
+ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
+ j(equal, &ok, Label::kNear); |
+ |
+ CompareRoot(return_value, Heap::kUndefinedValueRootIndex); |
+ j(equal, &ok, Label::kNear); |
+ |
+ CompareRoot(return_value, Heap::kTrueValueRootIndex); |
+ j(equal, &ok, Label::kNear); |
+ |
+ CompareRoot(return_value, Heap::kFalseValueRootIndex); |
+ j(equal, &ok, Label::kNear); |
+ |
+ CompareRoot(return_value, Heap::kNullValueRootIndex); |
+ j(equal, &ok, Label::kNear); |
+ |
+ Abort("API call returned invalid object"); |
+ |
+ bind(&ok); |
+#endif |
+ |
LeaveApiExitFrame(); |
ret(stack_space * kPointerSize); |