Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index c0afb6d4d44ceca2fda95abe98e228160f45d708..e190b711b9b9eccbec3dcc7365263fd6b4b59e9e 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -141,10 +141,13 @@ static void ExpectUndefined(const char* code) { |
static int signature_callback_count; |
+static Local<Value> signature_expected_receiver; |
static void IncrementingSignatureCallback( |
const v8::FunctionCallbackInfo<v8::Value>& args) { |
ApiTestFuzzer::Fuzz(); |
signature_callback_count++; |
+ CHECK_EQ(signature_expected_receiver, args.Holder()); |
+ CHECK_EQ(signature_expected_receiver, args.This()); |
v8::Handle<v8::Array> result = v8::Array::New(args.Length()); |
for (int i = 0; i < args.Length(); i++) |
result->Set(v8::Integer::New(i), args[i]); |
@@ -213,26 +216,50 @@ THREADED_TEST(ReceiverSignature) { |
v8::FunctionTemplate::New(IncrementingSignatureCallback, |
v8::Handle<Value>(), |
sig)); |
+ fun->PrototypeTemplate()->SetAccessorProperty( |
+ v8_str("n"), |
+ v8::FunctionTemplate::New(IncrementingSignatureCallback, |
+ v8::Handle<Value>(), |
+ sig)); |
env->Global()->Set(v8_str("Fun"), fun->GetFunction()); |
+ Local<Value> fun_instance = fun->InstanceTemplate()->NewInstance(); |
+ env->Global()->Set(v8_str("fun_instance"), fun_instance); |
signature_callback_count = 0; |
+ int expected_count = 0; |
+ signature_expected_receiver = fun_instance; |
CompileRun( |
- "var o = new Fun();" |
- "o.m();"); |
- CHECK_EQ(1, signature_callback_count); |
+ "var o = fun_instance;" |
+ "var key_n = 'n';" |
+ "for (var i = 0; i < 10; i++) o.m();" |
+ "for (var i = 0; i < 10; i++) o.n;" |
+ "for (var i = 0; i < 10; i++) o[key_n];"); |
+ expected_count += 30; |
+ CHECK_EQ(expected_count, signature_callback_count); |
v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(); |
sub_fun->Inherit(fun); |
- env->Global()->Set(v8_str("SubFun"), sub_fun->GetFunction()); |
+ fun_instance = sub_fun->InstanceTemplate()->NewInstance(); |
+ env->Global()->Set(v8_str("fun_instance"), fun_instance); |
+ signature_expected_receiver = fun_instance; |
CompileRun( |
- "var o = new SubFun();" |
- "o.m();"); |
- CHECK_EQ(2, signature_callback_count); |
- |
+ "var o = fun_instance;" |
+ "var key_n = 'n';" |
+ "for (var i = 0; i < 10; i++) o.m();" |
+ "for (var i = 0; i < 10; i++) o.n;" |
+ "for (var i = 0; i < 10; i++) o[key_n];"); |
+ expected_count += 30; |
+ CHECK_EQ(expected_count, signature_callback_count); |
v8::TryCatch try_catch; |
CompileRun( |
"var o = { };" |
"o.m = Fun.prototype.m;" |
"o.m();"); |
- CHECK_EQ(2, signature_callback_count); |
+ CHECK_EQ(expected_count, signature_callback_count); |
+ CHECK(try_catch.HasCaught()); |
+ CompileRun( |
+ "var o = { };" |
+ "o.n = Fun.prototype.n;" |
+ "o.n;"); |
+ CHECK_EQ(expected_count, signature_callback_count); |
CHECK(try_catch.HasCaught()); |
try_catch.Reset(); |
v8::Handle<v8::FunctionTemplate> unrel_fun = v8::FunctionTemplate::New(); |
@@ -242,7 +269,14 @@ THREADED_TEST(ReceiverSignature) { |
"var o = new UnrelFun();" |
"o.m = Fun.prototype.m;" |
"o.m();"); |
- CHECK_EQ(2, signature_callback_count); |
+ CHECK_EQ(expected_count, signature_callback_count); |
+ CHECK(try_catch.HasCaught()); |
+ try_catch.Reset(); |
+ CompileRun( |
+ "var o = new UnrelFun();" |
+ "o.n = Fun.prototype.n;" |
+ "o.n;"); |
+ CHECK_EQ(expected_count, signature_callback_count); |
CHECK(try_catch.HasCaught()); |
} |