Index: gin/arguments_unittest.cc |
diff --git a/gin/arguments_unittest.cc b/gin/arguments_unittest.cc |
index d2b51361995cdc2f38a9cb4ccc5481833422ab96..a5f03e5f36f0de213e834a9ed362b84a446d40e6 100644 |
--- a/gin/arguments_unittest.cc |
+++ b/gin/arguments_unittest.cc |
@@ -64,4 +64,67 @@ TEST_F(ArgumentsTest, TestArgumentsHolderCreationContext) { |
} |
} |
+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, 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 |