Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Unified Diff: gin/wrappable_unittest.cc

Issue 401823002: Added IsConstructorCall to gin::Arguments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gin/arguments.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/wrappable_unittest.cc
diff --git a/gin/wrappable_unittest.cc b/gin/wrappable_unittest.cc
index 9843329906468655a65d31916eb8ae1bd0a9194d..f3de48fe09ae278e34d2302b3aedd94beb017b11 100644
--- a/gin/wrappable_unittest.cc
+++ b/gin/wrappable_unittest.cc
@@ -97,8 +97,11 @@ class MyCallableObject : public Wrappable<MyCallableObject> {
virtual ~MyCallableObject() {
}
- void Call(int val) {
- result_ = val;
+ void Call(int val, const gin::Arguments& arguments) {
+ if (arguments.IsConstructCall())
+ arguments.ThrowTypeError("Cannot be called as constructor.");
+ else
+ result_ = val;
}
int result_;
@@ -245,4 +248,26 @@ TEST_F(WrappableTest, CallAsFunction) {
EXPECT_EQ(42, object->result());
}
+TEST_F(WrappableTest, CallAsConstructor) {
+ v8::Isolate* isolate = instance_->isolate();
+ v8::HandleScope handle_scope(isolate);
+
+ gin::Handle<MyCallableObject> object(MyCallableObject::Create(isolate));
+ EXPECT_EQ(0, object->result());
+ v8::Handle<v8::String> source = StringToV8(isolate,
+ "(function(obj) {"
+ "new obj(42);"
+ "})");
+ gin::TryCatch try_catch;
+ v8::Handle<v8::Script> script = v8::Script::Compile(source);
+ v8::Handle<v8::Value> val = script->Run();
+ v8::Handle<v8::Function> func;
+ EXPECT_TRUE(ConvertFromV8(isolate, val, &func));
+ v8::Handle<v8::Value> argv[] = {
+ ConvertToV8(isolate, object.get())
+ };
+ func->Call(v8::Undefined(isolate), 1, argv);
+ EXPECT_TRUE(try_catch.HasCaught());
+}
+
} // namespace gin
« no previous file with comments | « gin/arguments.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698