Pass Isolate to Local<T>::New()

Our profiling revealed that Local<T>::New() is one of bottlenecks of DOM bindings.

BUG=
TEST=cctest/test-api/LocalHandle

Review URL: https://codereview.chromium.org/11316331
Patch from Kentaro Hara <haraken@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13138 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent cec0745a
......@@ -308,11 +308,13 @@ template <class T> class Local : public Handle<T> {
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));
};
......@@ -494,6 +496,8 @@ class V8EXPORT HandleScope {
* 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);
......@@ -4284,6 +4288,16 @@ Local<T> Local<T>::New(Handle<T> that) {
}
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>();
......
......@@ -769,6 +769,12 @@ i::Object** HandleScope::CreateHandle(i::Object* value) {
}
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**>(
......
......@@ -2360,6 +2360,16 @@ THREADED_TEST(GlobalHandle) {
}
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) { }
......
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