[Reland][gin] Add Arguments::GetAll()

Add an Arguments::GetAll() function that returns all arguments as a
std::vector<v8::Local<v8::Value>>. This is more clear, concise, and
slightly more performant than the alternative of using
Arguments::GetRemaining() since it doesn't require trying to convert
and avoids unnecessary calls.

Add a test for the new method.

Reverted due to a compile error, now fixed.

BUG=None

Review-Url: https://codereview.chromium.org/2822373002
Cr-Commit-Position: refs/heads/master@{#465627}
diff --git a/gin/arguments_unittest.cc b/gin/arguments_unittest.cc
index d2b5136..3a262c7 100644
--- a/gin/arguments_unittest.cc
+++ b/gin/arguments_unittest.cc
@@ -64,4 +64,67 @@
   }
 }
 
+TEST_F(ArgumentsTest, TestGetAll) {
+  v8::Isolate* isolate = instance_->isolate();
+  v8::HandleScope handle_scope(isolate);
+  v8::Local<v8::Context> context = context_.Get(instance_->isolate());
+
+  using V8List = std::vector<v8::Local<v8::Value>>;
+
+  V8List list1 = {
+      gin::ConvertToV8(isolate, 1), gin::StringToV8(isolate, "some string"),
+      gin::ConvertToV8(context, std::vector<double>({2.0, 3.0}))
+          .ToLocalChecked(),
+  };
+  bool called1 = false;
+
+  V8List list2 = {
+      gin::StringToV8(isolate, "some other string"),
+      gin::ConvertToV8(isolate, 42),
+  };
+  bool called2 = false;
+
+  V8List list3;  // Empty list.
+  bool called3 = false;
+
+  auto check_arguments = [](V8List* expected, bool* called,
+                            gin::Arguments* arguments) {
+    *called = true;
+    V8List actual = arguments->GetAll();
+    ASSERT_EQ(expected->size(), actual.size());
+    for (size_t i = 0; i < expected->size(); ++i)
+      EXPECT_EQ(expected->at(i), actual[i]) << i;
+  };
+
+  // Create an object that will compare GetHolderCreationContext() with
+  // |creation_context|.
+  v8::Local<v8::ObjectTemplate> object_template =
+      ObjectTemplateBuilder(isolate)
+          .SetMethod("check1", base::Bind(check_arguments, &list1, &called1))
+          .SetMethod("check2", base::Bind(check_arguments, &list2, &called2))
+          .SetMethod("check3", base::Bind(check_arguments, &list3, &called3))
+          .Build();
+
+  v8::Local<v8::Object> object =
+      object_template->NewInstance(context).ToLocalChecked();
+
+  auto do_check = [object, context](V8List& args, base::StringPiece key) {
+    v8::Local<v8::Value> val;
+    ASSERT_TRUE(
+        object->Get(context, gin::StringToSymbol(context->GetIsolate(), key))
+            .ToLocal(&val));
+    ASSERT_TRUE(val->IsFunction());
+    val.As<v8::Function>()
+        ->Call(context, object, static_cast<int>(args.size()), args.data())
+        .ToLocalChecked();
+  };
+
+  do_check(list1, "check1");
+  EXPECT_TRUE(called1);
+  do_check(list2, "check2");
+  EXPECT_TRUE(called2);
+  do_check(list3, "check3");
+  EXPECT_TRUE(called3);
+}
+
 }  // namespace gin