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

Side by Side Diff: test/cctest/test-api.cc

Issue 23549019: store ics for js api accessors (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: no snprintf Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 217 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent());
218 env->Enter(); 218 env->Enter();
219 CHECK(env->InContext()); 219 CHECK(env->InContext());
220 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 220 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent());
221 env->Exit(); 221 env->Exit();
222 CHECK(!env->InContext()); 222 CHECK(!env->InContext());
223 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 223 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent());
224 } 224 }
225 225
226 226
227 static void TestSignature(const char* loop_js, Local<Value> receiver) {
228 i::ScopedVector<char> source(200);
229 i::OS::SNPrintF(source,
230 "for (var i = 0; i < 10; i++) {"
231 " %s"
232 "}",
233 loop_js);
234 signature_callback_count = 0;
235 signature_expected_receiver = receiver;
236 bool expected_to_throw = receiver.IsEmpty();
237 v8::TryCatch try_catch;
238 CompileRun(source.start());
239 CHECK_EQ(expected_to_throw, try_catch.HasCaught());
240 if (!expected_to_throw) {
241 CHECK_EQ(10, signature_callback_count);
242 } else {
243 CHECK_EQ(v8_str("TypeError: Illegal invocation"),
244 try_catch.Exception()->ToString());
245 }
246 }
247
248
227 THREADED_TEST(ReceiverSignature) { 249 THREADED_TEST(ReceiverSignature) {
228 LocalContext env; 250 LocalContext env;
229 v8::HandleScope scope(env->GetIsolate()); 251 v8::HandleScope scope(env->GetIsolate());
252 // Setup templates.
230 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); 253 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New();
231 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); 254 v8::Handle<v8::Signature> sig = v8::Signature::New(fun);
232 fun->PrototypeTemplate()->Set( 255 v8::Handle<v8::FunctionTemplate> callback_sig =
233 v8_str("m"), 256 v8::FunctionTemplate::New(
234 v8::FunctionTemplate::New(IncrementingSignatureCallback, 257 IncrementingSignatureCallback, Local<Value>(), sig);
235 v8::Handle<Value>(), 258 v8::Handle<v8::FunctionTemplate> callback =
236 sig)); 259 v8::FunctionTemplate::New(IncrementingSignatureCallback);
237 fun->PrototypeTemplate()->SetAccessorProperty(
238 v8_str("n"),
239 v8::FunctionTemplate::New(IncrementingSignatureCallback,
240 v8::Handle<Value>(),
241 sig));
242 env->Global()->Set(v8_str("Fun"), fun->GetFunction());
243 Local<Value> fun_instance = fun->InstanceTemplate()->NewInstance();
244 env->Global()->Set(v8_str("fun_instance"), fun_instance);
245 signature_callback_count = 0;
246 int expected_count = 0;
247 signature_expected_receiver = fun_instance;
248 CompileRun(
249 "var o = fun_instance;"
250 "var key_n = 'n';"
251 "for (var i = 0; i < 10; i++) o.m();"
252 "for (var i = 0; i < 10; i++) o.n;"
253 "for (var i = 0; i < 10; i++) o[key_n];");
254 expected_count += 30;
255 CHECK_EQ(expected_count, signature_callback_count);
256 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(); 260 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New();
257 sub_fun->Inherit(fun); 261 sub_fun->Inherit(fun);
258 fun_instance = sub_fun->InstanceTemplate()->NewInstance(); 262 v8::Handle<v8::FunctionTemplate> unrel_fun = v8::FunctionTemplate::New();
263 // Install properties.
264 v8::Handle<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate();
265 fun_proto->Set(v8_str("prop_sig"), callback_sig);
266 fun_proto->Set(v8_str("prop"), callback);
267 fun_proto->SetAccessorProperty(
268 v8_str("accessor_sig"), callback_sig, callback_sig);
269 fun_proto->SetAccessorProperty(v8_str("accessor"), callback, callback);
270 // Instantiate templates.
271 Local<Value> fun_instance = fun->InstanceTemplate()->NewInstance();
272 Local<Value> sub_fun_instance = sub_fun->InstanceTemplate()->NewInstance();
273 // Setup global variables.
274 env->Global()->Set(v8_str("Fun"), fun->GetFunction());
275 env->Global()->Set(v8_str("UnrelFun"), unrel_fun->GetFunction());
259 env->Global()->Set(v8_str("fun_instance"), fun_instance); 276 env->Global()->Set(v8_str("fun_instance"), fun_instance);
260 signature_expected_receiver = fun_instance; 277 env->Global()->Set(v8_str("sub_fun_instance"), sub_fun_instance);
261 CompileRun( 278 CompileRun(
262 "var o = fun_instance;" 279 "var accessor_sig_key = 'accessor_sig';"
263 "var key_n = 'n';" 280 "var accessor_key = 'accessor';"
264 "for (var i = 0; i < 10; i++) o.m();" 281 "var prop_sig_key = 'prop_sig';"
265 "for (var i = 0; i < 10; i++) o.n;" 282 "var prop_key = 'prop';"
266 "for (var i = 0; i < 10; i++) o[key_n];"); 283 ""
267 expected_count += 30; 284 "function copy_props(obj) {"
268 CHECK_EQ(expected_count, signature_callback_count); 285 " var keys = [accessor_sig_key, accessor_key, prop_sig_key, prop_key];"
269 v8::TryCatch try_catch; 286 " var source = Fun.prototype;"
270 CompileRun( 287 " for (var i in keys) {"
271 "var o = { };" 288 " var key = keys[i];"
272 "o.m = Fun.prototype.m;" 289 " var desc = Object.getOwnPropertyDescriptor(source, key);"
273 "o.m();"); 290 " Object.defineProperty(obj, key, desc);"
274 CHECK_EQ(expected_count, signature_callback_count); 291 " }"
275 CHECK(try_catch.HasCaught()); 292 "}"
276 CompileRun( 293 ""
277 "var o = { };" 294 "var obj = {};"
278 "o.n = Fun.prototype.n;" 295 "copy_props(obj);"
279 "o.n;"); 296 "var unrel = new UnrelFun();"
280 CHECK_EQ(expected_count, signature_callback_count); 297 "copy_props(unrel);");
281 CHECK(try_catch.HasCaught()); 298 // Test with and without ICs
282 try_catch.Reset(); 299 const char* test_objects[] = {
283 v8::Handle<v8::FunctionTemplate> unrel_fun = v8::FunctionTemplate::New(); 300 "fun_instance", "sub_fun_instance", "obj", "unrel" };
284 sub_fun->Inherit(fun); 301 unsigned bad_signature_start_offset = 2;
285 env->Global()->Set(v8_str("UnrelFun"), unrel_fun->GetFunction()); 302 for (unsigned i = 0; i < ARRAY_SIZE(test_objects); i++) {
286 CompileRun( 303 i::ScopedVector<char> source(200);
287 "var o = new UnrelFun();" 304 i::OS::SNPrintF(
288 "o.m = Fun.prototype.m;" 305 source, "var test_object = %s; test_object", test_objects[i]);
289 "o.m();"); 306 Local<Value> test_object = CompileRun(source.start());
290 CHECK_EQ(expected_count, signature_callback_count); 307 TestSignature("test_object.prop();", test_object);
291 CHECK(try_catch.HasCaught()); 308 TestSignature("test_object.accessor;", test_object);
292 try_catch.Reset(); 309 TestSignature("test_object[accessor_key];", test_object);
293 CompileRun( 310 TestSignature("test_object.accessor = 1;", test_object);
294 "var o = new UnrelFun();" 311 TestSignature("test_object[accessor_key] = 1;", test_object);
295 "o.n = Fun.prototype.n;" 312 if (i >= bad_signature_start_offset) test_object = Local<Value>();
296 "o.n;"); 313 TestSignature("test_object.prop_sig();", test_object);
297 CHECK_EQ(expected_count, signature_callback_count); 314 TestSignature("test_object.accessor_sig;", test_object);
298 CHECK(try_catch.HasCaught()); 315 TestSignature("test_object[accessor_sig_key];", test_object);
316 TestSignature("test_object.accessor_sig = 1;", test_object);
317 TestSignature("test_object[accessor_sig_key] = 1;", test_object);
318 }
299 } 319 }
300 320
301 321
302 THREADED_TEST(ArgumentSignature) { 322 THREADED_TEST(ArgumentSignature) {
303 LocalContext env; 323 LocalContext env;
304 v8::HandleScope scope(env->GetIsolate()); 324 v8::HandleScope scope(env->GetIsolate());
305 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(); 325 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New();
306 cons->SetClassName(v8_str("Cons")); 326 cons->SetClassName(v8_str("Cons"));
307 v8::Handle<v8::Signature> sig = 327 v8::Handle<v8::Signature> sig =
308 v8::Signature::New(v8::Handle<v8::FunctionTemplate>(), 1, &cons); 328 v8::Signature::New(v8::Handle<v8::FunctionTemplate>(), 1, &cons);
(...skipping 20156 matching lines...) Expand 10 before | Expand all | Expand 10 after
20465 "setAge(100);" 20485 "setAge(100);"
20466 "setAge(101);" 20486 "setAge(101);"
20467 "setAge(102);" 20487 "setAge(102);"
20468 "%OptimizeFunctionOnNextCall(setAge);" 20488 "%OptimizeFunctionOnNextCall(setAge);"
20469 "setAge(103);"); 20489 "setAge(103);");
20470 ExpectInt32("obj.age", 100000); 20490 ExpectInt32("obj.age", 100000);
20471 ExpectInt32("obj.interceptor_age", 103); 20491 ExpectInt32("obj.interceptor_age", 103);
20472 } 20492 }
20473 20493
20474 #endif // V8_OS_POSIX 20494 #endif // V8_OS_POSIX
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698