Revision: 14995
Author:   [email protected]
Date:     Fri Jun  7 01:46:39 2013
Log:      Add Value::Cast.

It's needed for upcasting Persistent<Object> to Persistent<Value> after
handlepocalypse (with Persistent::As or Persistent::Cast).

BUG=
[email protected]

Review URL: https://codereview.chromium.org/16206014

Patch from Marja Hölttä <[email protected]>.
http://code.google.com/p/v8/source/detail?r=14995

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Fri Jun  7 01:15:00 2013
+++ /branches/bleeding_edge/include/v8.h        Fri Jun  7 01:46:39 2013
@@ -1469,6 +1469,8 @@
   bool Equals(Handle<Value> that) const;
   bool StrictEquals(Handle<Value> that) const;

+  template <class T> V8_INLINE(static Value* Cast(T* value));
+
  private:
   V8_INLINE(bool QuickIsUndefined() const);
   V8_INLINE(bool QuickIsNull() const);
@@ -5995,6 +5997,11 @@
   if (!I::HasHeapObjectTag(obj)) return false;
   return (I::GetInstanceType(obj) < I::kFirstNonstringType);
 }
+
+
+template <class T> Value* Value::Cast(T* value) {
+  return static_cast<Value*>(value);
+}


 Symbol* Symbol::Cast(v8::Value* value) {
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Fri Jun  7 01:15:00 2013
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Fri Jun  7 01:46:39 2013
@@ -2896,6 +2896,24 @@
   new_global->Dispose();
   CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count);
 }
+
+
+THREADED_TEST(GlobalHandleUpcast) {
+  v8::Isolate* isolate = v8::Isolate::GetCurrent();
+  v8::HandleScope scope(isolate);
+  v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
+  v8::Persistent<String> global_string(isolate, local);
+#ifdef V8_USE_UNSAFE_HANDLES
+  v8::Persistent<Value> global_value =
+      v8::Persistent<Value>::Cast(global_string);
+#else
+  v8::Persistent<Value>& global_value =
+      v8::Persistent<Value>::Cast(global_string);
+#endif
+  CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString());
+  CHECK(global_string == v8::Persistent<String>::Cast(global_value));
+  global_string.Dispose();
+}


 THREADED_TEST(LocalHandle) {

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to