Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Unified Diff: include/v8.h

Issue 5581006: Checking heap objects in API. (Closed)
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 7b954983af19a451f4a6d26710e81dca89c3d246..1e018cb832d068fe98933c868d960fabe1dd52ea 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -437,6 +437,7 @@ class V8EXPORT HandleScope {
* Creates a new handle with the given value.
*/
static internal::Object** CreateHandle(internal::Object* value);
+ static internal::Object** CreateHandleFromHeapObject(internal::Object* value);
private:
// Make it impossible to create heap-allocated or illegal handle
@@ -3483,6 +3484,9 @@ class Internals {
uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
return *reinterpret_cast<T*>(addr);
}
+
+ static inline bool IsHeapObject(void*) { return false; }
+ static inline bool IsHeapObject(Date*) { return true; }
};
} // namespace internal
@@ -3499,7 +3503,12 @@ Local<T>::Local() : Handle<T>() { }
template <class T>
Local<T> Local<T>::New(Handle<T> that) {
if (that.IsEmpty()) return Local<T>();
- internal::Object** p = reinterpret_cast<internal::Object**>(*that);
+ T* that_ptr = *that;
+ internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
+ if (internal::Internals::IsHeapObject(that_ptr)) {
+ return Local<T>(
+ reinterpret_cast<T*>(HandleScope::CreateHandleFromHeapObject(*p)));
+ }
return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
}
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698