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

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

Issue 661020: Version 2.1.2.1... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 10 years, 10 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/version.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 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 6415 matching lines...) Expand 10 before | Expand all | Expand 10 after
6426 " if (i == 50) {" 6426 " if (i == 50) {"
6427 " saved_result = result;" 6427 " saved_result = result;"
6428 " o.method = function(x) { return x - 1 };" 6428 " o.method = function(x) { return x - 1 };"
6429 " }" 6429 " }"
6430 "}"); 6430 "}");
6431 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 6431 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
6432 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 6432 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
6433 CHECK_GE(interceptor_call_count, 50); 6433 CHECK_GE(interceptor_call_count, 50);
6434 } 6434 }
6435 6435
6436 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) {
6437 int interceptor_call_count = 0;
6438 v8::HandleScope scope;
6439 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
6440 v8::Handle<v8::FunctionTemplate> method_templ =
6441 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
6442 v8_str("method_data"),
6443 v8::Signature::New(fun_templ));
6444 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
6445 proto_templ->Set(v8_str("method"), method_templ);
6446 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
6447 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
6448 NULL, NULL, NULL, NULL,
6449 v8::External::Wrap(&interceptor_call_count));
6450 LocalContext context;
6451 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
6452 GenerateSomeGarbage();
6453 context->Global()->Set(v8_str("o"), fun->NewInstance());
6454 v8::TryCatch try_catch;
6455 v8::Handle<Value> value = CompileRun(
6456 "o.foo = 17;"
6457 "var receiver = {};"
6458 "receiver.__proto__ = o;"
6459 "var result = 0;"
6460 "var saved_result = 0;"
6461 "for (var i = 0; i < 100; i++) {"
6462 " result = receiver.method(41);"
6463 " if (i == 50) {"
6464 " saved_result = result;"
6465 " receiver = 333;"
6466 " }"
6467 "}");
6468 CHECK(try_catch.HasCaught());
6469 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
6470 try_catch.Exception()->ToString());
6471 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
6472 CHECK_GE(interceptor_call_count, 50);
6473 }
6474
6436 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { 6475 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) {
6437 int interceptor_call_count = 0; 6476 int interceptor_call_count = 0;
6438 v8::HandleScope scope; 6477 v8::HandleScope scope;
6439 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 6478 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
6440 v8::Handle<v8::FunctionTemplate> method_templ = 6479 v8::Handle<v8::FunctionTemplate> method_templ =
6441 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 6480 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
6442 v8_str("method_data"), 6481 v8_str("method_data"),
6443 v8::Signature::New(fun_templ)); 6482 v8::Signature::New(fun_templ));
6444 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 6483 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
6445 proto_templ->Set(v8_str("method"), method_templ); 6484 proto_templ->Set(v8_str("method"), method_templ);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
6514 "var receiver = {};" 6553 "var receiver = {};"
6515 "receiver.__proto__ = o;" 6554 "receiver.__proto__ = o;"
6516 "var result = 0;" 6555 "var result = 0;"
6517 "for (var i = 0; i < 100; i++) {" 6556 "for (var i = 0; i < 100; i++) {"
6518 " result = receiver.method(41);" 6557 " result = receiver.method(41);"
6519 "}"); 6558 "}");
6520 6559
6521 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 6560 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
6522 } 6561 }
6523 6562
6524 THREADED_TEST(CallICFastApi_SimpleSignature_Miss) { 6563 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) {
6525 v8::HandleScope scope; 6564 v8::HandleScope scope;
6526 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 6565 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
6527 v8::Handle<v8::FunctionTemplate> method_templ = 6566 v8::Handle<v8::FunctionTemplate> method_templ =
6528 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 6567 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
6529 v8_str("method_data"), 6568 v8_str("method_data"),
6530 v8::Signature::New(fun_templ)); 6569 v8::Signature::New(fun_templ));
6531 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 6570 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
6532 proto_templ->Set(v8_str("method"), method_templ); 6571 proto_templ->Set(v8_str("method"), method_templ);
6533 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 6572 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
6534 LocalContext context; 6573 LocalContext context;
(...skipping 10 matching lines...) Expand all
6545 " result = receiver.method(41);" 6584 " result = receiver.method(41);"
6546 " if (i == 50) {" 6585 " if (i == 50) {"
6547 " saved_result = result;" 6586 " saved_result = result;"
6548 " receiver = {method: function(x) { return x - 1 }};" 6587 " receiver = {method: function(x) { return x - 1 }};"
6549 " }" 6588 " }"
6550 "}"); 6589 "}");
6551 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 6590 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
6552 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 6591 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
6553 } 6592 }
6554 6593
6594 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) {
6595 v8::HandleScope scope;
6596 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
6597 v8::Handle<v8::FunctionTemplate> method_templ =
6598 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
6599 v8_str("method_data"),
6600 v8::Signature::New(fun_templ));
6601 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
6602 proto_templ->Set(v8_str("method"), method_templ);
6603 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
6604 LocalContext context;
6605 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
6606 GenerateSomeGarbage();
6607 context->Global()->Set(v8_str("o"), fun->NewInstance());
6608 v8::TryCatch try_catch;
6609 v8::Handle<Value> value = CompileRun(
6610 "o.foo = 17;"
6611 "var receiver = {};"
6612 "receiver.__proto__ = o;"
6613 "var result = 0;"
6614 "var saved_result = 0;"
6615 "for (var i = 0; i < 100; i++) {"
6616 " result = receiver.method(41);"
6617 " if (i == 50) {"
6618 " saved_result = result;"
6619 " receiver = 333;"
6620 " }"
6621 "}");
6622 CHECK(try_catch.HasCaught());
6623 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
6624 try_catch.Exception()->ToString());
6625 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
6626 }
6627
6555 6628
6556 static int interceptor_call_count = 0; 6629 static int interceptor_call_count = 0;
6557 6630
6558 static v8::Handle<Value> InterceptorICRefErrorGetter(Local<String> name, 6631 static v8::Handle<Value> InterceptorICRefErrorGetter(Local<String> name,
6559 const AccessorInfo& info) { 6632 const AccessorInfo& info) {
6560 ApiTestFuzzer::Fuzz(); 6633 ApiTestFuzzer::Fuzz();
6561 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { 6634 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) {
6562 return call_ic_function2; 6635 return call_ic_function2;
6563 } 6636 }
6564 return v8::Handle<Value>(); 6637 return v8::Handle<Value>();
(...skipping 3151 matching lines...) Expand 10 before | Expand all | Expand 10 after
9716 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); 9789 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value());
9717 } 9790 }
9718 9791
9719 script = v8::Script::Compile(v8_str("new C2();")); 9792 script = v8::Script::Compile(v8_str("new C2();"));
9720 for (int i = 0; i < 10; i++) { 9793 for (int i = 0; i < 10; i++) {
9721 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); 9794 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run());
9722 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); 9795 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value());
9723 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); 9796 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value());
9724 } 9797 }
9725 } 9798 }
OLDNEW
« no previous file with comments | « src/version.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698