| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 134 } |
| 135 | 135 |
| 136 | 136 |
| 137 static void ExpectUndefined(const char* code) { | 137 static void ExpectUndefined(const char* code) { |
| 138 Local<Value> result = CompileRun(code); | 138 Local<Value> result = CompileRun(code); |
| 139 CHECK(result->IsUndefined()); | 139 CHECK(result->IsUndefined()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 | 142 |
| 143 static int signature_callback_count; | 143 static int signature_callback_count; |
| 144 static Local<Value> signature_expected_receiver; |
| 144 static void IncrementingSignatureCallback( | 145 static void IncrementingSignatureCallback( |
| 145 const v8::FunctionCallbackInfo<v8::Value>& args) { | 146 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 146 ApiTestFuzzer::Fuzz(); | 147 ApiTestFuzzer::Fuzz(); |
| 147 signature_callback_count++; | 148 signature_callback_count++; |
| 149 CHECK_EQ(signature_expected_receiver, args.Holder()); |
| 150 CHECK_EQ(signature_expected_receiver, args.This()); |
| 148 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); | 151 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); |
| 149 for (int i = 0; i < args.Length(); i++) | 152 for (int i = 0; i < args.Length(); i++) |
| 150 result->Set(v8::Integer::New(i), args[i]); | 153 result->Set(v8::Integer::New(i), args[i]); |
| 151 args.GetReturnValue().Set(result); | 154 args.GetReturnValue().Set(result); |
| 152 } | 155 } |
| 153 | 156 |
| 154 | 157 |
| 155 static void SignatureCallback( | 158 static void SignatureCallback( |
| 156 const v8::FunctionCallbackInfo<v8::Value>& args) { | 159 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 157 ApiTestFuzzer::Fuzz(); | 160 ApiTestFuzzer::Fuzz(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 THREADED_TEST(ReceiverSignature) { | 209 THREADED_TEST(ReceiverSignature) { |
| 207 LocalContext env; | 210 LocalContext env; |
| 208 v8::HandleScope scope(env->GetIsolate()); | 211 v8::HandleScope scope(env->GetIsolate()); |
| 209 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); | 212 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); |
| 210 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); | 213 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); |
| 211 fun->PrototypeTemplate()->Set( | 214 fun->PrototypeTemplate()->Set( |
| 212 v8_str("m"), | 215 v8_str("m"), |
| 213 v8::FunctionTemplate::New(IncrementingSignatureCallback, | 216 v8::FunctionTemplate::New(IncrementingSignatureCallback, |
| 214 v8::Handle<Value>(), | 217 v8::Handle<Value>(), |
| 215 sig)); | 218 sig)); |
| 219 fun->PrototypeTemplate()->SetAccessorProperty( |
| 220 v8_str("n"), |
| 221 v8::FunctionTemplate::New(IncrementingSignatureCallback, |
| 222 v8::Handle<Value>(), |
| 223 sig)); |
| 216 env->Global()->Set(v8_str("Fun"), fun->GetFunction()); | 224 env->Global()->Set(v8_str("Fun"), fun->GetFunction()); |
| 225 Local<Value> fun_instance = fun->InstanceTemplate()->NewInstance(); |
| 226 env->Global()->Set(v8_str("fun_instance"), fun_instance); |
| 217 signature_callback_count = 0; | 227 signature_callback_count = 0; |
| 228 int expected_count = 0; |
| 229 signature_expected_receiver = fun_instance; |
| 218 CompileRun( | 230 CompileRun( |
| 219 "var o = new Fun();" | 231 "var o = fun_instance;" |
| 220 "o.m();"); | 232 "var key_n = 'n';" |
| 221 CHECK_EQ(1, signature_callback_count); | 233 "for (var i = 0; i < 10; i++) o.m();" |
| 234 "for (var i = 0; i < 10; i++) o.n;" |
| 235 "for (var i = 0; i < 10; i++) o[key_n];"); |
| 236 expected_count += 30; |
| 237 CHECK_EQ(expected_count, signature_callback_count); |
| 222 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(); | 238 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(); |
| 223 sub_fun->Inherit(fun); | 239 sub_fun->Inherit(fun); |
| 224 env->Global()->Set(v8_str("SubFun"), sub_fun->GetFunction()); | 240 fun_instance = sub_fun->InstanceTemplate()->NewInstance(); |
| 241 env->Global()->Set(v8_str("fun_instance"), fun_instance); |
| 242 signature_expected_receiver = fun_instance; |
| 225 CompileRun( | 243 CompileRun( |
| 226 "var o = new SubFun();" | 244 "var o = fun_instance;" |
| 227 "o.m();"); | 245 "var key_n = 'n';" |
| 228 CHECK_EQ(2, signature_callback_count); | 246 "for (var i = 0; i < 10; i++) o.m();" |
| 229 | 247 "for (var i = 0; i < 10; i++) o.n;" |
| 248 "for (var i = 0; i < 10; i++) o[key_n];"); |
| 249 expected_count += 30; |
| 250 CHECK_EQ(expected_count, signature_callback_count); |
| 230 v8::TryCatch try_catch; | 251 v8::TryCatch try_catch; |
| 231 CompileRun( | 252 CompileRun( |
| 232 "var o = { };" | 253 "var o = { };" |
| 233 "o.m = Fun.prototype.m;" | 254 "o.m = Fun.prototype.m;" |
| 234 "o.m();"); | 255 "o.m();"); |
| 235 CHECK_EQ(2, signature_callback_count); | 256 CHECK_EQ(expected_count, signature_callback_count); |
| 257 CHECK(try_catch.HasCaught()); |
| 258 CompileRun( |
| 259 "var o = { };" |
| 260 "o.n = Fun.prototype.n;" |
| 261 "o.n;"); |
| 262 CHECK_EQ(expected_count, signature_callback_count); |
| 236 CHECK(try_catch.HasCaught()); | 263 CHECK(try_catch.HasCaught()); |
| 237 try_catch.Reset(); | 264 try_catch.Reset(); |
| 238 v8::Handle<v8::FunctionTemplate> unrel_fun = v8::FunctionTemplate::New(); | 265 v8::Handle<v8::FunctionTemplate> unrel_fun = v8::FunctionTemplate::New(); |
| 239 sub_fun->Inherit(fun); | 266 sub_fun->Inherit(fun); |
| 240 env->Global()->Set(v8_str("UnrelFun"), unrel_fun->GetFunction()); | 267 env->Global()->Set(v8_str("UnrelFun"), unrel_fun->GetFunction()); |
| 241 CompileRun( | 268 CompileRun( |
| 242 "var o = new UnrelFun();" | 269 "var o = new UnrelFun();" |
| 243 "o.m = Fun.prototype.m;" | 270 "o.m = Fun.prototype.m;" |
| 244 "o.m();"); | 271 "o.m();"); |
| 245 CHECK_EQ(2, signature_callback_count); | 272 CHECK_EQ(expected_count, signature_callback_count); |
| 273 CHECK(try_catch.HasCaught()); |
| 274 try_catch.Reset(); |
| 275 CompileRun( |
| 276 "var o = new UnrelFun();" |
| 277 "o.n = Fun.prototype.n;" |
| 278 "o.n;"); |
| 279 CHECK_EQ(expected_count, signature_callback_count); |
| 246 CHECK(try_catch.HasCaught()); | 280 CHECK(try_catch.HasCaught()); |
| 247 } | 281 } |
| 248 | 282 |
| 249 | 283 |
| 250 THREADED_TEST(ArgumentSignature) { | 284 THREADED_TEST(ArgumentSignature) { |
| 251 LocalContext env; | 285 LocalContext env; |
| 252 v8::HandleScope scope(env->GetIsolate()); | 286 v8::HandleScope scope(env->GetIsolate()); |
| 253 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(); | 287 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(); |
| 254 cons->SetClassName(v8_str("Cons")); | 288 cons->SetClassName(v8_str("Cons")); |
| 255 v8::Handle<v8::Signature> sig = | 289 v8::Handle<v8::Signature> sig = |
| (...skipping 20157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20413 "setAge(100);" | 20447 "setAge(100);" |
| 20414 "setAge(101);" | 20448 "setAge(101);" |
| 20415 "setAge(102);" | 20449 "setAge(102);" |
| 20416 "%OptimizeFunctionOnNextCall(setAge);" | 20450 "%OptimizeFunctionOnNextCall(setAge);" |
| 20417 "setAge(103);"); | 20451 "setAge(103);"); |
| 20418 ExpectInt32("obj.age", 100000); | 20452 ExpectInt32("obj.age", 100000); |
| 20419 ExpectInt32("obj.interceptor_age", 103); | 20453 ExpectInt32("obj.interceptor_age", 103); |
| 20420 } | 20454 } |
| 20421 | 20455 |
| 20422 #endif // V8_OS_POSIX | 20456 #endif // V8_OS_POSIX |
| OLD | NEW |