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

Unified Diff: include/v8.h

Issue 14788013: Add Persistent<T>::Reset which disposes the handle and redirects it to point to another object. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: code review (svenpanne) + fixes (val_ -> this->val_) Created 7 years, 7 months 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 | test/cctest/test-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 b113d74792108c62ff13627b8117598c17b1b297..ec9a9846c11e9b2b78dcff938fbfa64497df3955 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -676,6 +676,11 @@ template <class T> class Persistent // NOLINT
// TODO(dcarney): remove before cutover
V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const);
+ /**
+ * Disposes the current contents of the handle and replaces it.
+ */
+ V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other));
+
#ifndef V8_USE_UNSAFE_HANDLES
#ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
@@ -5349,6 +5354,22 @@ void Persistent<T>::SetWrapperClassId(uint16_t class_id) {
}
template <class T>
+void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) {
+ Dispose(isolate);
+#ifdef V8_USE_UNSAFE_HANDLES
+ *this = *New(isolate, other);
+#else
+ if (other.IsEmpty()) {
+ this->val_ = NULL;
+ return;
+ }
+ internal::Object** p = reinterpret_cast<internal::Object**>(other.val_);
+ this->val_ = reinterpret_cast<T*>(
+ V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p));
+#endif
+}
+
+template <class T>
void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) {
typedef internal::Internals I;
if (this->IsEmpty()) return;
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698