return Local<S>::Cast(*this);
}
- /** Create a local handle for the content of another handle.
- * The referee is kept alive by the local handle even when
- * the original handle is destroyed/disposed.
+ /**
+ * Create a local handle for the content of another handle.
+ * The referee is kept alive by the local handle even when
+ * the original handle is destroyed/disposed.
*/
V8_INLINE(static Local<T> New(Handle<T> that));
+ V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that));
};
* Creates a new handle with the given value.
*/
static internal::Object** CreateHandle(internal::Object* value);
+ static internal::Object** CreateHandle(internal::Isolate* isolate,
+ internal::Object* value);
// Faster version, uses HeapObject to obtain the current Isolate.
static internal::Object** CreateHandle(internal::HeapObject* value);
template <class T>
+ Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) {
+ if (that.IsEmpty()) return Local<T>();
+ T* that_ptr = *that;
+ internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
+ return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
+ reinterpret_cast<internal::Isolate*>(isolate), *p)));
+}
+
+
+template <class T>
Persistent<T> Persistent<T>::New(Handle<T> that) {
if (that.IsEmpty()) return Persistent<T>();
internal::Object** p = reinterpret_cast<internal::Object**>(*that);
}
+i::Object** HandleScope::CreateHandle(i::Isolate* isolate, i::Object* value) {
+ ASSERT(isolate == i::Isolate::Current());
+ return i::HandleScope::CreateHandle(value, isolate);
+}
+
+
i::Object** HandleScope::CreateHandle(i::HeapObject* value) {
ASSERT(value->IsHeapObject());
return reinterpret_cast<i::Object**>(
}
+THREADED_TEST(LocalHandle) {
+ v8::HandleScope scope;
+ v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
+ CHECK_EQ(local->Length(), 3);
+
+ local = v8::Local<String>::New(v8::Isolate::GetCurrent(), v8_str("str"));
+ CHECK_EQ(local->Length(), 3);
+}
+
+
class WeakCallCounter {
public:
explicit WeakCallCounter(int id) : id_(id), number_of_weak_calls_(0) { }