Add empty-handle checks to API functions (#ifdef ENABLE_EXTRA_CHECKS)

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12445 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c2fedcc3
...@@ -1540,7 +1540,7 @@ Local<Script> Script::New(v8::Handle<String> source, ...@@ -1540,7 +1540,7 @@ Local<Script> Script::New(v8::Handle<String> source,
isolate->global_context(), isolate->global_context(),
NULL, NULL,
pre_data_impl, pre_data_impl,
Utils::OpenHandle(*script_data), Utils::OpenHandle(*script_data, true),
i::NOT_NATIVES_CODE); i::NOT_NATIVES_CODE);
has_pending_exception = result.is_null(); has_pending_exception = result.is_null();
EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>());
...@@ -4404,7 +4404,7 @@ Persistent<Context> v8::Context::New( ...@@ -4404,7 +4404,7 @@ Persistent<Context> v8::Context::New(
// Create the environment. // Create the environment.
env = isolate->bootstrapper()->CreateEnvironment( env = isolate->bootstrapper()->CreateEnvironment(
isolate, isolate,
Utils::OpenHandle(*global_object), Utils::OpenHandle(*global_object, true),
proxy_template, proxy_template,
extensions); extensions);
...@@ -5642,7 +5642,8 @@ bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) { ...@@ -5642,7 +5642,8 @@ bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) {
foreign = foreign =
isolate->factory()->NewForeign(FUNCTION_ADDR(EventCallbackWrapper)); isolate->factory()->NewForeign(FUNCTION_ADDR(EventCallbackWrapper));
} }
isolate->debugger()->SetEventListener(foreign, Utils::OpenHandle(*data)); isolate->debugger()->SetEventListener(foreign,
Utils::OpenHandle(*data, true));
return true; return true;
} }
...@@ -5657,7 +5658,8 @@ bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { ...@@ -5657,7 +5658,8 @@ bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) {
if (that != NULL) { if (that != NULL) {
foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that)); foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that));
} }
isolate->debugger()->SetEventListener(foreign, Utils::OpenHandle(*data)); isolate->debugger()->SetEventListener(foreign,
Utils::OpenHandle(*data, true));
return true; return true;
} }
...@@ -5668,7 +5670,7 @@ bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that, ...@@ -5668,7 +5670,7 @@ bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that,
ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false);
ENTER_V8(isolate); ENTER_V8(isolate);
isolate->debugger()->SetEventListener(Utils::OpenHandle(*that), isolate->debugger()->SetEventListener(Utils::OpenHandle(*that),
Utils::OpenHandle(*data)); Utils::OpenHandle(*data, true));
return true; return true;
} }
......
...@@ -159,6 +159,27 @@ class RegisteredExtension { ...@@ -159,6 +159,27 @@ class RegisteredExtension {
}; };
#define OPEN_HANDLE_LIST(V) \
V(Template, TemplateInfo) \
V(FunctionTemplate, FunctionTemplateInfo) \
V(ObjectTemplate, ObjectTemplateInfo) \
V(Signature, SignatureInfo) \
V(AccessorSignature, FunctionTemplateInfo) \
V(TypeSwitch, TypeSwitchInfo) \
V(Data, Object) \
V(RegExp, JSRegExp) \
V(Object, JSObject) \
V(Array, JSArray) \
V(String, String) \
V(Script, Object) \
V(Function, JSFunction) \
V(Message, JSObject) \
V(Context, Context) \
V(External, Foreign) \
V(StackTrace, JSArray) \
V(StackFrame, JSObject)
class Utils { class Utils {
public: public:
static bool ReportApiFailure(const char* location, const char* message); static bool ReportApiFailure(const char* location, const char* message);
...@@ -205,42 +226,13 @@ class Utils { ...@@ -205,42 +226,13 @@ class Utils {
static inline Local<TypeSwitch> ToLocal( static inline Local<TypeSwitch> ToLocal(
v8::internal::Handle<v8::internal::TypeSwitchInfo> obj); v8::internal::Handle<v8::internal::TypeSwitchInfo> obj);
static inline v8::internal::Handle<v8::internal::TemplateInfo> #define DECLARE_OPEN_HANDLE(From, To) \
OpenHandle(const Template* that); static inline v8::internal::Handle<v8::internal::To> \
static inline v8::internal::Handle<v8::internal::FunctionTemplateInfo> OpenHandle(const From* that, bool allow_empty_handle = false);
OpenHandle(const FunctionTemplate* that);
static inline v8::internal::Handle<v8::internal::ObjectTemplateInfo> OPEN_HANDLE_LIST(DECLARE_OPEN_HANDLE)
OpenHandle(const ObjectTemplate* that);
static inline v8::internal::Handle<v8::internal::Object> #undef DECLARE_OPEN_HANDLE
OpenHandle(const Data* data);
static inline v8::internal::Handle<v8::internal::JSRegExp>
OpenHandle(const RegExp* data);
static inline v8::internal::Handle<v8::internal::JSObject>
OpenHandle(const v8::Object* data);
static inline v8::internal::Handle<v8::internal::JSArray>
OpenHandle(const v8::Array* data);
static inline v8::internal::Handle<v8::internal::String>
OpenHandle(const String* data);
static inline v8::internal::Handle<v8::internal::Object>
OpenHandle(const Script* data);
static inline v8::internal::Handle<v8::internal::JSFunction>
OpenHandle(const Function* data);
static inline v8::internal::Handle<v8::internal::JSObject>
OpenHandle(const Message* message);
static inline v8::internal::Handle<v8::internal::JSArray>
OpenHandle(const StackTrace* stack_trace);
static inline v8::internal::Handle<v8::internal::JSObject>
OpenHandle(const StackFrame* stack_frame);
static inline v8::internal::Handle<v8::internal::Context>
OpenHandle(const v8::Context* context);
static inline v8::internal::Handle<v8::internal::SignatureInfo>
OpenHandle(const v8::Signature* sig);
static inline v8::internal::Handle<v8::internal::FunctionTemplateInfo>
OpenHandle(const v8::AccessorSignature* sig);
static inline v8::internal::Handle<v8::internal::TypeSwitchInfo>
OpenHandle(const v8::TypeSwitch* that);
static inline v8::internal::Handle<v8::internal::Foreign>
OpenHandle(const v8::External* that);
}; };
...@@ -257,7 +249,7 @@ v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom( ...@@ -257,7 +249,7 @@ v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom(
if (!is_null()) { if (!is_null()) {
handle = *this; handle = *this;
} }
return Utils::OpenHandle(*scope->Close(Utils::ToLocal(handle))); return Utils::OpenHandle(*scope->Close(Utils::ToLocal(handle)), true);
} }
...@@ -294,33 +286,18 @@ MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32) ...@@ -294,33 +286,18 @@ MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32)
// Implementations of OpenHandle // Implementations of OpenHandle
#define MAKE_OPEN_HANDLE(From, To) \ #define MAKE_OPEN_HANDLE(From, To) \
v8::internal::Handle<v8::internal::To> Utils::OpenHandle(\ v8::internal::Handle<v8::internal::To> Utils::OpenHandle( \
const v8::From* that) { \ const v8::From* that, bool allow_empty_handle) { \
return v8::internal::Handle<v8::internal::To>( \ EXTRA_CHECK(allow_empty_handle || that != NULL); \
return v8::internal::Handle<v8::internal::To>( \
reinterpret_cast<v8::internal::To**>(const_cast<v8::From*>(that))); \ reinterpret_cast<v8::internal::To**>(const_cast<v8::From*>(that))); \
} }
MAKE_OPEN_HANDLE(Template, TemplateInfo) OPEN_HANDLE_LIST(MAKE_OPEN_HANDLE)
MAKE_OPEN_HANDLE(FunctionTemplate, FunctionTemplateInfo)
MAKE_OPEN_HANDLE(ObjectTemplate, ObjectTemplateInfo)
MAKE_OPEN_HANDLE(Signature, SignatureInfo)
MAKE_OPEN_HANDLE(AccessorSignature, FunctionTemplateInfo)
MAKE_OPEN_HANDLE(TypeSwitch, TypeSwitchInfo)
MAKE_OPEN_HANDLE(Data, Object)
MAKE_OPEN_HANDLE(RegExp, JSRegExp)
MAKE_OPEN_HANDLE(Object, JSObject)
MAKE_OPEN_HANDLE(Array, JSArray)
MAKE_OPEN_HANDLE(String, String)
MAKE_OPEN_HANDLE(Script, Object)
MAKE_OPEN_HANDLE(Function, JSFunction)
MAKE_OPEN_HANDLE(Message, JSObject)
MAKE_OPEN_HANDLE(Context, Context)
MAKE_OPEN_HANDLE(External, Foreign)
MAKE_OPEN_HANDLE(StackTrace, JSArray)
MAKE_OPEN_HANDLE(StackFrame, JSObject)
#undef MAKE_OPEN_HANDLE #undef MAKE_OPEN_HANDLE
#undef OPEN_HANDLE_LIST
namespace internal { namespace internal {
......
...@@ -284,4 +284,12 @@ extern bool FLAG_enable_slow_asserts; ...@@ -284,4 +284,12 @@ extern bool FLAG_enable_slow_asserts;
#define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p) #define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p)
// "Extra checks" are lightweight checks that are enabled in some release
// builds.
#ifdef ENABLE_EXTRA_CHECKS
#define EXTRA_CHECK(condition) CHECK(condition)
#else
#define EXTRA_CHECK(condition) ((void) 0)
#endif
#endif // V8_CHECKS_H_ #endif // V8_CHECKS_H_
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