Commit 266cca47 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Add more checks for native callback results.

R=svenpanne@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/10928083

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12474 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f6cd2403
...@@ -1149,6 +1149,7 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallHelper( ...@@ -1149,6 +1149,7 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallHelper(
result = heap->undefined_value(); result = heap->undefined_value();
} else { } else {
result = *reinterpret_cast<Object**>(*value); result = *reinterpret_cast<Object**>(*value);
result->VerifyApiCallResultType();
} }
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_IF_SCHEDULED_EXCEPTION(isolate);
...@@ -1225,6 +1226,7 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallAsFunctionOrConstructor( ...@@ -1225,6 +1226,7 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallAsFunctionOrConstructor(
result = heap->undefined_value(); result = heap->undefined_value();
} else { } else {
result = *reinterpret_cast<Object**>(*value); result = *reinterpret_cast<Object**>(*value);
result->VerifyApiCallResultType();
} }
} }
// Check for exceptions and return result. // Check for exceptions and return result.
......
...@@ -561,6 +561,9 @@ v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSReceiver> receiver, ...@@ -561,6 +561,9 @@ v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSReceiver> receiver,
result = enum_fun(info); result = enum_fun(info);
} }
} }
#if ENABLE_EXTRA_CHECKS
CHECK(result.IsEmpty() || v8::Utils::OpenHandle(*result)->IsJSObject());
#endif
return result; return result;
} }
...@@ -581,6 +584,9 @@ v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver, ...@@ -581,6 +584,9 @@ v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver,
// Leaving JavaScript. // Leaving JavaScript.
VMState state(isolate, EXTERNAL); VMState state(isolate, EXTERNAL);
result = enum_fun(info); result = enum_fun(info);
#if ENABLE_EXTRA_CHECKS
CHECK(result.IsEmpty() || v8::Utils::OpenHandle(*result)->IsJSObject());
#endif
} }
} }
return result; return result;
......
...@@ -1664,6 +1664,23 @@ bool Object::IsStringObjectWithCharacterAt(uint32_t index) { ...@@ -1664,6 +1664,23 @@ bool Object::IsStringObjectWithCharacterAt(uint32_t index) {
} }
void Object::VerifyApiCallResultType() {
#if ENABLE_EXTRA_CHECKS
if (!(IsSmi() ||
IsString() ||
IsSpecObject() ||
IsHeapNumber() ||
IsUndefined() ||
IsTrue() ||
IsFalse() ||
IsNull())) {
FATAL("API call returned invalid object");
}
#endif // ENABLE_EXTRA_CHECKS
}
FixedArrayBase* FixedArrayBase::cast(Object* object) { FixedArrayBase* FixedArrayBase::cast(Object* object) {
ASSERT(object->IsFixedArray() || object->IsFixedDoubleArray()); ASSERT(object->IsFixedArray() || object->IsFixedDoubleArray());
return reinterpret_cast<FixedArrayBase*>(object); return reinterpret_cast<FixedArrayBase*>(object);
......
...@@ -211,18 +211,7 @@ MaybeObject* JSObject::GetPropertyWithCallback(Object* receiver, ...@@ -211,18 +211,7 @@ MaybeObject* JSObject::GetPropertyWithCallback(Object* receiver,
return isolate->heap()->undefined_value(); return isolate->heap()->undefined_value();
} }
Object* return_value = *v8::Utils::OpenHandle(*result); Object* return_value = *v8::Utils::OpenHandle(*result);
#if ENABLE_EXTRA_CHECKS return_value->VerifyApiCallResultType();
if (!(return_value->IsSmi() ||
return_value->IsString() ||
return_value->IsSpecObject() ||
return_value->IsHeapNumber() ||
return_value->IsUndefined() ||
return_value->IsTrue() ||
return_value->IsFalse() ||
return_value->IsNull())) {
FATAL("API call returned invalid object");
}
#endif
return return_value; return return_value;
} }
...@@ -3805,7 +3794,9 @@ MaybeObject* JSObject::DeletePropertyWithInterceptor(String* name) { ...@@ -3805,7 +3794,9 @@ MaybeObject* JSObject::DeletePropertyWithInterceptor(String* name) {
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_IF_SCHEDULED_EXCEPTION(isolate);
if (!result.IsEmpty()) { if (!result.IsEmpty()) {
ASSERT(result->IsBoolean()); ASSERT(result->IsBoolean());
return *v8::Utils::OpenHandle(*result); Handle<Object> result_internal = v8::Utils::OpenHandle(*result);
result_internal->VerifyApiCallResultType();
return *result_internal;
} }
} }
MaybeObject* raw_result = MaybeObject* raw_result =
...@@ -3840,7 +3831,9 @@ MaybeObject* JSObject::DeleteElementWithInterceptor(uint32_t index) { ...@@ -3840,7 +3831,9 @@ MaybeObject* JSObject::DeleteElementWithInterceptor(uint32_t index) {
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_IF_SCHEDULED_EXCEPTION(isolate);
if (!result.IsEmpty()) { if (!result.IsEmpty()) {
ASSERT(result->IsBoolean()); ASSERT(result->IsBoolean());
return *v8::Utils::OpenHandle(*result); Handle<Object> result_internal = v8::Utils::OpenHandle(*result);
result_internal->VerifyApiCallResultType();
return *result_internal;
} }
MaybeObject* raw_result = this_handle->GetElementsAccessor()->Delete( MaybeObject* raw_result = this_handle->GetElementsAccessor()->Delete(
*this_handle, *this_handle,
...@@ -9133,7 +9126,9 @@ MaybeObject* JSObject::GetElementWithCallback(Object* receiver, ...@@ -9133,7 +9126,9 @@ MaybeObject* JSObject::GetElementWithCallback(Object* receiver,
} }
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_IF_SCHEDULED_EXCEPTION(isolate);
if (result.IsEmpty()) return isolate->heap()->undefined_value(); if (result.IsEmpty()) return isolate->heap()->undefined_value();
return *v8::Utils::OpenHandle(*result); Handle<Object> result_internal = v8::Utils::OpenHandle(*result);
result_internal->VerifyApiCallResultType();
return *result_internal;
} }
// __defineGetter__ callback // __defineGetter__ callback
...@@ -9952,7 +9947,11 @@ MaybeObject* JSObject::GetElementWithInterceptor(Object* receiver, ...@@ -9952,7 +9947,11 @@ MaybeObject* JSObject::GetElementWithInterceptor(Object* receiver,
result = getter(index, info); result = getter(index, info);
} }
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_IF_SCHEDULED_EXCEPTION(isolate);
if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result); if (!result.IsEmpty()) {
Handle<Object> result_internal = v8::Utils::OpenHandle(*result);
result_internal->VerifyApiCallResultType();
return *result_internal;
}
} }
Heap* heap = holder_handle->GetHeap(); Heap* heap = holder_handle->GetHeap();
...@@ -10254,7 +10253,9 @@ MaybeObject* JSObject::GetPropertyWithInterceptor( ...@@ -10254,7 +10253,9 @@ MaybeObject* JSObject::GetPropertyWithInterceptor(
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_IF_SCHEDULED_EXCEPTION(isolate);
if (!result.IsEmpty()) { if (!result.IsEmpty()) {
*attributes = NONE; *attributes = NONE;
return *v8::Utils::OpenHandle(*result); Handle<Object> result_internal = v8::Utils::OpenHandle(*result);
result_internal->VerifyApiCallResultType();
return *result_internal;
} }
} }
......
...@@ -970,6 +970,8 @@ class Object : public MaybeObject { ...@@ -970,6 +970,8 @@ class Object : public MaybeObject {
static void VerifyPointer(Object* p); static void VerifyPointer(Object* p);
#endif #endif
inline void VerifyApiCallResultType();
// Prints this object without details. // Prints this object without details.
inline void ShortPrint() { inline void ShortPrint() {
ShortPrint(stdout); ShortPrint(stdout);
......
...@@ -1005,7 +1005,9 @@ RUNTIME_FUNCTION(MaybeObject*, LoadCallbackProperty) { ...@@ -1005,7 +1005,9 @@ RUNTIME_FUNCTION(MaybeObject*, LoadCallbackProperty) {
} }
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_IF_SCHEDULED_EXCEPTION(isolate);
if (result.IsEmpty()) return HEAP->undefined_value(); if (result.IsEmpty()) return HEAP->undefined_value();
return *v8::Utils::OpenHandle(*result); Handle<Object> result_internal = v8::Utils::OpenHandle(*result);
result_internal->VerifyApiCallResultType();
return *result_internal;
} }
...@@ -1070,6 +1072,8 @@ RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly) { ...@@ -1070,6 +1072,8 @@ RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly) {
} }
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_IF_SCHEDULED_EXCEPTION(isolate);
if (!r.IsEmpty()) { if (!r.IsEmpty()) {
Handle<Object> result = v8::Utils::OpenHandle(*r);
result->VerifyApiCallResultType();
return *v8::Utils::OpenHandle(*r); return *v8::Utils::OpenHandle(*r);
} }
} }
...@@ -1126,7 +1130,9 @@ static MaybeObject* LoadWithInterceptor(Arguments* args, ...@@ -1126,7 +1130,9 @@ static MaybeObject* LoadWithInterceptor(Arguments* args,
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_IF_SCHEDULED_EXCEPTION(isolate);
if (!r.IsEmpty()) { if (!r.IsEmpty()) {
*attrs = NONE; *attrs = NONE;
return *v8::Utils::OpenHandle(*r); Handle<Object> result = v8::Utils::OpenHandle(*r);
result->VerifyApiCallResultType();
return *result;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment