Remove usage of deprecagted V8 API from gin/

[email protected]
[email protected]
BUG=324225

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237750 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gin/converter.cc b/gin/converter.cc
index 04fe7ea..c7a572a 100644
--- a/gin/converter.cc
+++ b/gin/converter.cc
@@ -21,7 +21,7 @@
 namespace gin {
 
 Handle<Value> Converter<bool>::ToV8(Isolate* isolate, bool val) {
-  return Boolean::New(val).As<Value>();
+  return Boolean::New(isolate, val).As<Value>();
 }
 
 bool Converter<bool>::FromV8(Isolate* isolate, Handle<Value> val, bool* out) {
@@ -30,7 +30,7 @@
 }
 
 Handle<Value> Converter<int32_t>::ToV8(Isolate* isolate, int32_t val) {
-  return Integer::New(val, isolate).As<Value>();
+  return Integer::New(isolate, val).As<Value>();
 }
 
 bool Converter<int32_t>::FromV8(Isolate* isolate, Handle<Value> val,
@@ -42,7 +42,7 @@
 }
 
 Handle<Value> Converter<uint32_t>::ToV8(Isolate* isolate, uint32_t val) {
-  return Integer::NewFromUnsigned(val, isolate).As<Value>();
+  return Integer::NewFromUnsigned(isolate, val).As<Value>();
 }
 
 bool Converter<uint32_t>::FromV8(Isolate* isolate, Handle<Value> val,
diff --git a/gin/converter.h b/gin/converter.h
index e36977f..4ff7043 100644
--- a/gin/converter.h
+++ b/gin/converter.h
@@ -127,7 +127,8 @@
 struct Converter<std::vector<T> > {
   static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
                                     const std::vector<T>& val) {
-    v8::Handle<v8::Array> result(v8::Array::New(static_cast<int>(val.size())));
+    v8::Handle<v8::Array> result(
+        v8::Array::New(isolate, static_cast<int>(val.size())));
     for (size_t i = 0; i < val.size(); ++i) {
       result->Set(static_cast<int>(i), Converter<T>::ToV8(isolate, val[i]));
     }
diff --git a/gin/converter_unittest.cc b/gin/converter_unittest.cc
index 58ae625..9b831b9 100644
--- a/gin/converter_unittest.cc
+++ b/gin/converter_unittest.cc
@@ -34,25 +34,25 @@
   HandleScope handle_scope(instance_->isolate());
 
   EXPECT_TRUE(Converter<bool>::ToV8(instance_->isolate(), true)->StrictEquals(
-      Boolean::New(true)));
+      Boolean::New(instance_->isolate(), true)));
   EXPECT_TRUE(Converter<bool>::ToV8(instance_->isolate(), false)->StrictEquals(
-      Boolean::New(false)));
+      Boolean::New(instance_->isolate(), false)));
 
   struct {
     Handle<Value> input;
     bool expected;
   } test_data[] = {
-    { Boolean::New(false).As<Value>(), false },
-    { Boolean::New(true).As<Value>(), true },
-    { Number::New(0).As<Value>(), false },
-    { Number::New(1).As<Value>(), true },
-    { Number::New(-1).As<Value>(), true },
-    { Number::New(0.1).As<Value>(), true },
-    { String::New("").As<Value>(), false },
-    { String::New("foo").As<Value>(), true },
-    { Object::New().As<Value>(), true },
-    { Null().As<Value>(), false },
-    { Undefined().As<Value>(), false },
+    { Boolean::New(instance_->isolate(), false).As<Value>(), false },
+    { Boolean::New(instance_->isolate(), true).As<Value>(), true },
+    { Number::New(instance_->isolate(), 0).As<Value>(), false },
+    { Number::New(instance_->isolate(), 1).As<Value>(), true },
+    { Number::New(instance_->isolate(), -1).As<Value>(), true },
+    { Number::New(instance_->isolate(), 0.1).As<Value>(), true },
+    { String::NewFromUtf8(instance_->isolate(), "").As<Value>(), false },
+    { String::NewFromUtf8(instance_->isolate(), "foo").As<Value>(), true },
+    { Object::New(instance_->isolate()).As<Value>(), true },
+    { Null(instance_->isolate()).As<Value>(), false },
+    { Undefined(instance_->isolate()).As<Value>(), false },
   };
 
   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
@@ -82,19 +82,19 @@
     bool expect_sucess;
     int expected_result;
   } test_data_from[] = {
-    { Boolean::New(false).As<Value>(), false, 0 },
-    { Boolean::New(true).As<Value>(), false, 0 },
-    { Integer::New(-1).As<Value>(), true, -1 },
-    { Integer::New(0).As<Value>(), true, 0 },
-    { Integer::New(1).As<Value>(), true, 1 },
-    { Number::New(-1).As<Value>(), true, -1 },
-    { Number::New(1.1).As<Value>(), false, 0 },
-    { String::New("42").As<Value>(), false, 0 },
-    { String::New("foo").As<Value>(), false, 0 },
-    { Object::New().As<Value>(), false, 0 },
-    { Array::New().As<Value>(), false, 0 },
-    { v8::Null().As<Value>(), false, 0 },
-    { v8::Undefined().As<Value>(), false, 0 },
+    { Boolean::New(instance_->isolate(), false).As<Value>(), false, 0 },
+    { Boolean::New(instance_->isolate(), true).As<Value>(), false, 0 },
+    { Integer::New(instance_->isolate(), -1).As<Value>(), true, -1 },
+    { Integer::New(instance_->isolate(), 0).As<Value>(), true, 0 },
+    { Integer::New(instance_->isolate(), 1).As<Value>(), true, 1 },
+    { Number::New(instance_->isolate(), -1).As<Value>(), true, -1 },
+    { Number::New(instance_->isolate(), 1.1).As<Value>(), false, 0 },
+    { String::NewFromUtf8(instance_->isolate(), "42").As<Value>(), false, 0 },
+    { String::NewFromUtf8(instance_->isolate(), "foo").As<Value>(), false, 0 },
+    { Object::New(instance_->isolate()).As<Value>(), false, 0 },
+    { Array::New(instance_->isolate()).As<Value>(), false, 0 },
+    { v8::Null(instance_->isolate()).As<Value>(), false, 0 },
+    { v8::Undefined(instance_->isolate()).As<Value>(), false, 0 },
   };
 
   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data_from); ++i) {
@@ -120,8 +120,8 @@
   ASSERT_FALSE(js_array.IsEmpty());
   EXPECT_EQ(3u, js_array->Length());
   for (size_t i = 0; i < expected.size(); ++i) {
-    EXPECT_TRUE(Integer::New(expected[i])->StrictEquals(
-        js_array->Get(static_cast<int>(i))));
+    EXPECT_TRUE(Integer::New(instance_->isolate(), expected[i])
+                    ->StrictEquals(js_array->Get(static_cast<int>(i))));
   }
 
   std::vector<int> actual;
diff --git a/gin/dictionary.cc b/gin/dictionary.cc
index e8b2ac3..d3361228 100644
--- a/gin/dictionary.cc
+++ b/gin/dictionary.cc
@@ -21,7 +21,7 @@
 
 Dictionary Dictionary::CreateEmpty(v8::Isolate* isolate) {
   Dictionary dictionary(isolate);
-  dictionary.object_ = v8::Object::New();
+  dictionary.object_ = v8::Object::New(isolate);
   return dictionary;
 }
 
diff --git a/gin/function_template.cc b/gin/function_template.cc
index e8878e0..07882e8 100644
--- a/gin/function_template.cc
+++ b/gin/function_template.cc
@@ -20,7 +20,8 @@
     return;
   }
 
-  v8::Handle<v8::ObjectTemplate> templ(v8::ObjectTemplate::New());
+  v8::Handle<v8::ObjectTemplate> templ(
+      v8::ObjectTemplate::New(isolate_data->isolate()));
   templ->SetInternalFieldCount(kNumberOfInternalFields);
   isolate_data->SetObjectTemplate(&internal::CallbackHolderBase::kWrapperInfo,
                                   templ);
diff --git a/gin/function_template.h.pump b/gin/function_template.h.pump
index 5812c80..1f308ce 100644
--- a/gin/function_template.h.pump
+++ b/gin/function_template.h.pump
@@ -173,6 +173,7 @@
   typedef internal::CallbackHolder<R($for ARG , [[P$(ARG)]])> HolderT;
   scoped_refptr<HolderT> holder(new HolderT(callback));
   return v8::FunctionTemplate::New(
+      isolate,
       &internal::DispatchToCallback<R$for ARG [[, P$(ARG)]]>,
       ConvertToV8<internal::CallbackHolderBase*>(isolate, holder.get()));
 }
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc
index b5501b66..c9f435c 100644
--- a/gin/isolate_holder.cc
+++ b/gin/isolate_holder.cc
@@ -48,7 +48,8 @@
   EnsureV8Initialized(true);
   isolate_ = v8::Isolate::New();
   v8::ResourceConstraints constraints;
-  constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory());
+  constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
+                                base::SysInfo::NumberOfProcessors());
   v8::SetResourceConstraints(isolate_, &constraints);
   v8::Isolate::Scope isolate_scope(isolate_);
   v8::HandleScope handle_scope(isolate_);
diff --git a/gin/per_isolate_data.h b/gin/per_isolate_data.h
index 4801125..11bbc03e 100644
--- a/gin/per_isolate_data.h
+++ b/gin/per_isolate_data.h
@@ -37,6 +37,8 @@
   v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info);
   v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info);
 
+  v8::Isolate* isolate() { return isolate_; }
+
  private:
   typedef std::map<
       WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap;
diff --git a/gin/wrappable_unittest.cc b/gin/wrappable_unittest.cc
index da57cc3..c653866b 100644
--- a/gin/wrappable_unittest.cc
+++ b/gin/wrappable_unittest.cc
@@ -75,12 +75,12 @@
   PerIsolateData* data = PerIsolateData::From(isolate);
   DCHECK(data->GetObjectTemplate(&MyObject::kWrapperInfo).IsEmpty());
 
-  v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
+  v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
   templ->SetInternalFieldCount(kNumberOfInternalFields);
   templ->SetAccessorProperty(
       StringToSymbol(isolate, "value"),
-      v8::FunctionTemplate::New(MyObjectGetValue),
-      v8::FunctionTemplate::New(MyObjectSetValue));
+      v8::FunctionTemplate::New(isolate, MyObjectGetValue),
+      v8::FunctionTemplate::New(isolate, MyObjectSetValue));
 
   data->SetObjectTemplate(&MyObject::kWrapperInfo, templ);
 }