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 12494012: new style of property/function callbacks (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: make arm look like other architectures Created 7 years, 7 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') | tools/gyp/v8.gyp » ('j') | 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 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 THREADED_TEST(GlobalProperties) { 798 THREADED_TEST(GlobalProperties) {
799 LocalContext env; 799 LocalContext env;
800 v8::HandleScope scope(env->GetIsolate()); 800 v8::HandleScope scope(env->GetIsolate());
801 v8::Handle<v8::Object> global = env->Global(); 801 v8::Handle<v8::Object> global = env->Global();
802 global->Set(v8_str("pi"), v8_num(3.1415926)); 802 global->Set(v8_str("pi"), v8_num(3.1415926));
803 Local<Value> pi = global->Get(v8_str("pi")); 803 Local<Value> pi = global->Get(v8_str("pi"));
804 CHECK_EQ(3.1415926, pi->NumberValue()); 804 CHECK_EQ(3.1415926, pi->NumberValue());
805 } 805 }
806 806
807 807
808 template<typename T>
809 static void CheckReturnValue(const T& t) {
810 v8::ReturnValue<v8::Value> rv = t.GetReturnValue();
811 i::Object** o = *reinterpret_cast<i::Object***>(&rv);
812 CHECK_EQ(t.GetIsolate(), v8::Isolate::GetCurrent());
813 CHECK((*o)->IsTheHole() || (*o)->IsUndefined());
814 }
815
808 static v8::Handle<Value> handle_call(const v8::Arguments& args) { 816 static v8::Handle<Value> handle_call(const v8::Arguments& args) {
809 ApiTestFuzzer::Fuzz(); 817 ApiTestFuzzer::Fuzz();
818 CheckReturnValue(args);
819 args.GetReturnValue().Set(v8_str("bad value"));
810 return v8_num(102); 820 return v8_num(102);
811 } 821 }
812 822
823 static v8::Handle<Value> handle_call_indirect(const v8::Arguments& args) {
824 ApiTestFuzzer::Fuzz();
825 CheckReturnValue(args);
826 args.GetReturnValue().Set(v8_str("bad value"));
827 args.GetReturnValue().Set(v8_num(102));
828 return v8::Handle<Value>();
829 }
830
831 static void handle_callback(const v8::FunctionCallbackInfo<Value>& info) {
832 ApiTestFuzzer::Fuzz();
833 CheckReturnValue(info);
834 info.GetReturnValue().Set(v8_str("bad value"));
835 info.GetReturnValue().Set(v8_num(102));
836 }
837
813 838
814 static v8::Handle<Value> construct_call(const v8::Arguments& args) { 839 static v8::Handle<Value> construct_call(const v8::Arguments& args) {
815 ApiTestFuzzer::Fuzz(); 840 ApiTestFuzzer::Fuzz();
841 CheckReturnValue(args);
816 args.This()->Set(v8_str("x"), v8_num(1)); 842 args.This()->Set(v8_str("x"), v8_num(1));
817 args.This()->Set(v8_str("y"), v8_num(2)); 843 args.This()->Set(v8_str("y"), v8_num(2));
844 args.GetReturnValue().Set(v8_str("bad value"));
818 return args.This(); 845 return args.This();
819 } 846 }
820 847
821 static v8::Handle<Value> Return239(Local<String> name, const AccessorInfo&) { 848 static v8::Handle<Value> construct_call_indirect(const v8::Arguments& args) {
822 ApiTestFuzzer::Fuzz(); 849 ApiTestFuzzer::Fuzz();
850 CheckReturnValue(args);
851 args.This()->Set(v8_str("x"), v8_num(1));
852 args.This()->Set(v8_str("y"), v8_num(2));
853 args.GetReturnValue().Set(v8_str("bad value"));
854 args.GetReturnValue().Set(args.This());
855 return v8::Handle<Value>();
856 }
857
858 static void construct_callback(
859 const v8::FunctionCallbackInfo<Value>& info) {
860 ApiTestFuzzer::Fuzz();
861 CheckReturnValue(info);
862 info.This()->Set(v8_str("x"), v8_num(1));
863 info.This()->Set(v8_str("y"), v8_num(2));
864 info.GetReturnValue().Set(v8_str("bad value"));
865 info.GetReturnValue().Set(info.This());
866 }
867
868
869 static v8::Handle<Value> Return239(
870 Local<String> name, const AccessorInfo& info) {
871 ApiTestFuzzer::Fuzz();
872 CheckReturnValue(info);
873 info.GetReturnValue().Set(v8_str("bad value"));
823 return v8_num(239); 874 return v8_num(239);
824 } 875 }
825 876
826 877 static v8::Handle<Value> Return239Indirect(
827 THREADED_TEST(FunctionTemplate) { 878 Local<String> name, const AccessorInfo& info) {
828 LocalContext env; 879 ApiTestFuzzer::Fuzz();
829 v8::HandleScope scope(env->GetIsolate()); 880 CheckReturnValue(info);
881 Handle<Value> value = v8_num(239);
882 info.GetReturnValue().Set(v8_str("bad value"));
883 info.GetReturnValue().Set(value);
884 return v8::Handle<Value>();
885 }
886
887 static void Return239Callback(
888 Local<String> name, const v8::PropertyCallbackInfo<Value>& info) {
889 ApiTestFuzzer::Fuzz();
890 CheckReturnValue(info);
891 info.GetReturnValue().Set(v8_str("bad value"));
892 info.GetReturnValue().Set(v8_num(239));
893 }
894
895
896 template<typename Handler>
897 static void TestFunctionTemplateInitializer(Handler handler) {
898 // Test constructor calls.
830 { 899 {
900 LocalContext env;
901 v8::HandleScope scope(env->GetIsolate());
831 Local<v8::FunctionTemplate> fun_templ = 902 Local<v8::FunctionTemplate> fun_templ =
832 v8::FunctionTemplate::New(handle_call); 903 v8::FunctionTemplate::New(handler);
833 Local<Function> fun = fun_templ->GetFunction(); 904 Local<Function> fun = fun_templ->GetFunction();
834 env->Global()->Set(v8_str("obj"), fun); 905 env->Global()->Set(v8_str("obj"), fun);
835 Local<Script> script = v8_compile("obj()"); 906 Local<Script> script = v8_compile("obj()");
836 CHECK_EQ(102, script->Run()->Int32Value()); 907 for (int i = 0; i < 30; i++) {
908 CHECK_EQ(102, script->Run()->Int32Value());
909 }
837 } 910 }
838 // Use SetCallHandler to initialize a function template, should work like the 911 // Use SetCallHandler to initialize a function template, should work like the
839 // previous one. 912 // previous one.
840 { 913 {
914 LocalContext env;
915 v8::HandleScope scope(env->GetIsolate());
841 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 916 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
842 fun_templ->SetCallHandler(handle_call); 917 fun_templ->SetCallHandler(handler);
843 Local<Function> fun = fun_templ->GetFunction(); 918 Local<Function> fun = fun_templ->GetFunction();
844 env->Global()->Set(v8_str("obj"), fun); 919 env->Global()->Set(v8_str("obj"), fun);
845 Local<Script> script = v8_compile("obj()"); 920 Local<Script> script = v8_compile("obj()");
846 CHECK_EQ(102, script->Run()->Int32Value()); 921 for (int i = 0; i < 30; i++) {
847 } 922 CHECK_EQ(102, script->Run()->Int32Value());
848 // Test constructor calls. 923 }
849 { 924 }
850 Local<v8::FunctionTemplate> fun_templ = 925 }
851 v8::FunctionTemplate::New(construct_call); 926
852 fun_templ->SetClassName(v8_str("funky")); 927
853 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), Return239); 928 template<typename Constructor, typename Accessor>
854 Local<Function> fun = fun_templ->GetFunction(); 929 static void TestFunctionTemplateAccessor(Constructor constructor,
855 env->Global()->Set(v8_str("obj"), fun); 930 Accessor accessor) {
856 Local<Script> script = v8_compile("var s = new obj(); s.x"); 931 LocalContext env;
932 v8::HandleScope scope(env->GetIsolate());
933 Local<v8::FunctionTemplate> fun_templ =
934 v8::FunctionTemplate::New(constructor);
935 fun_templ->SetClassName(v8_str("funky"));
936 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor);
937 Local<Function> fun = fun_templ->GetFunction();
938 env->Global()->Set(v8_str("obj"), fun);
939 Local<Value> result = v8_compile("(new obj()).toString()")->Run();
940 CHECK_EQ(v8_str("[object funky]"), result);
941 CompileRun("var obj_instance = new obj();");
942 Local<Script> script;
943 script = v8_compile("obj_instance.x");
944 for (int i = 0; i < 30; i++) {
857 CHECK_EQ(1, script->Run()->Int32Value()); 945 CHECK_EQ(1, script->Run()->Int32Value());
858 946 }
859 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); 947 script = v8_compile("obj_instance.m");
860 CHECK_EQ(v8_str("[object funky]"), result); 948 for (int i = 0; i < 30; i++) {
861 949 CHECK_EQ(239, script->Run()->Int32Value());
862 result = v8_compile("(new obj()).m")->Run(); 950 }
863 CHECK_EQ(239, result->Int32Value()); 951 }
864 } 952
953
954 THREADED_TEST(FunctionTemplate) {
955 TestFunctionTemplateInitializer(handle_call);
956 TestFunctionTemplateInitializer(handle_call_indirect);
957 TestFunctionTemplateInitializer(handle_callback);
958
959 TestFunctionTemplateAccessor(construct_call, Return239);
960 TestFunctionTemplateAccessor(construct_call_indirect, Return239Indirect);
961 TestFunctionTemplateAccessor(construct_callback, Return239Callback);
962 }
963
964
965 static v8::Handle<v8::Value> SimpleDirectCallback(const v8::Arguments& args) {
966 ApiTestFuzzer::Fuzz();
967 CheckReturnValue(args);
968 args.GetReturnValue().Set(v8_str("bad value"));
969 return v8_num(51423 + args.Length());
970 }
971
972 static v8::Handle<v8::Value> SimpleIndirectCallback(const v8::Arguments& args) {
973 ApiTestFuzzer::Fuzz();
974 CheckReturnValue(args);
975 args.GetReturnValue().Set(v8_num(51423 + args.Length()));
976 return v8::Handle<v8::Value>();
977 }
978
979 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
980 ApiTestFuzzer::Fuzz();
981 CheckReturnValue(info);
982 info.GetReturnValue().Set(v8_num(51423 + info.Length()));
983 }
984
985
986 template<typename Callback>
987 static void TestSimpleCallback(Callback callback) {
988 LocalContext env;
989 v8::HandleScope scope(env->GetIsolate());
990 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
991 object_template->Set("callback", v8::FunctionTemplate::New(callback));
992 v8::Local<v8::Object> object = object_template->NewInstance();
993 (*env)->Global()->Set(v8_str("callback_object"), object);
994 v8::Handle<v8::Script> script;
995 script = v8_compile("callback_object.callback(17)");
996 for (int i = 0; i < 30; i++) {
997 CHECK_EQ(51424, script->Run()->Int32Value());
998 }
999 script = v8_compile("callback_object.callback(17, 24)");
1000 for (int i = 0; i < 30; i++) {
1001 CHECK_EQ(51425, script->Run()->Int32Value());
1002 }
1003 }
1004
1005
1006 THREADED_TEST(SimpleCallback) {
1007 TestSimpleCallback(SimpleDirectCallback);
1008 TestSimpleCallback(SimpleIndirectCallback);
1009 TestSimpleCallback(SimpleCallback);
865 } 1010 }
866 1011
867 1012
868 THREADED_TEST(FunctionTemplateSetLength) { 1013 THREADED_TEST(FunctionTemplateSetLength) {
869 LocalContext env; 1014 LocalContext env;
870 v8::HandleScope scope(env->GetIsolate()); 1015 v8::HandleScope scope(env->GetIsolate());
871 { 1016 {
872 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New( 1017 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(
873 handle_call, Handle<v8::Value>(), Handle<v8::Signature>(), 23); 1018 handle_call, Handle<v8::Value>(), Handle<v8::Signature>(), 23);
874 Local<Function> fun = fun_templ->GetFunction(); 1019 Local<Function> fun = fun_templ->GetFunction();
(...skipping 3767 matching lines...) Expand 10 before | Expand all | Expand 10 after
4642 CHECK_EQ(v8_num(4), Handle<Value>(*xValue)); 4787 CHECK_EQ(v8_num(4), Handle<Value>(*xValue));
4643 xValue.Dispose(context->GetIsolate()); 4788 xValue.Dispose(context->GetIsolate());
4644 xValue = v8::Persistent<Value>(); 4789 xValue = v8::Persistent<Value>();
4645 } 4790 }
4646 } 4791 }
4647 4792
4648 4793
4649 THREADED_TEST(NoAccessors) { 4794 THREADED_TEST(NoAccessors) {
4650 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4795 v8::HandleScope scope(v8::Isolate::GetCurrent());
4651 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4796 Local<ObjectTemplate> templ = ObjectTemplate::New();
4652 templ->SetAccessor(v8_str("x"), NULL, NULL, v8_str("donut")); 4797 templ->SetAccessor(v8_str("x"),
4798 static_cast<v8::AccessorGetter>(NULL),
4799 NULL,
4800 v8_str("donut"));
4653 LocalContext context; 4801 LocalContext context;
4654 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4802 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4655 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 4803 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
4656 for (int i = 0; i < 10; i++) { 4804 for (int i = 0; i < 10; i++) {
4657 script->Run(); 4805 script->Run();
4658 } 4806 }
4659 } 4807 }
4660 4808
4661 4809
4662 static v8::Handle<Value> XPropertyGetter(Local<String> property, 4810 static v8::Handle<Value> XPropertyGetter(Local<String> property,
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
5301 LocalContext env1; 5449 LocalContext env1;
5302 Local<Script> script1 = Script::Compile(source); 5450 Local<Script> script1 = Script::Compile(source);
5303 CHECK_EQ(8901.0, script1->Run()->NumberValue()); 5451 CHECK_EQ(8901.0, script1->Run()->NumberValue());
5304 } 5452 }
5305 5453
5306 5454
5307 THREADED_TEST(UndetectableObject) { 5455 THREADED_TEST(UndetectableObject) {
5308 LocalContext env; 5456 LocalContext env;
5309 v8::HandleScope scope(env->GetIsolate()); 5457 v8::HandleScope scope(env->GetIsolate());
5310 5458
5311 Local<v8::FunctionTemplate> desc = 5459 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New();
5312 v8::FunctionTemplate::New(0, v8::Handle<Value>());
5313 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 5460 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
5314 5461
5315 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 5462 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
5316 env->Global()->Set(v8_str("undetectable"), obj); 5463 env->Global()->Set(v8_str("undetectable"), obj);
5317 5464
5318 ExpectString("undetectable.toString()", "[object Object]"); 5465 ExpectString("undetectable.toString()", "[object Object]");
5319 ExpectString("typeof undetectable", "undefined"); 5466 ExpectString("typeof undetectable", "undefined");
5320 ExpectString("typeof(undetectable)", "undefined"); 5467 ExpectString("typeof(undetectable)", "undefined");
5321 ExpectBoolean("typeof undetectable == 'undefined'", true); 5468 ExpectBoolean("typeof undetectable == 'undefined'", true);
5322 ExpectBoolean("typeof undetectable == 'object'", false); 5469 ExpectBoolean("typeof undetectable == 'object'", false);
(...skipping 22 matching lines...) Expand all
5345 ExpectBoolean("undetectable===undefined", false); 5492 ExpectBoolean("undetectable===undefined", false);
5346 ExpectBoolean("undefined===undetectable", false); 5493 ExpectBoolean("undefined===undetectable", false);
5347 ExpectBoolean("undetectable===undetectable", true); 5494 ExpectBoolean("undetectable===undetectable", true);
5348 } 5495 }
5349 5496
5350 5497
5351 THREADED_TEST(VoidLiteral) { 5498 THREADED_TEST(VoidLiteral) {
5352 LocalContext env; 5499 LocalContext env;
5353 v8::HandleScope scope(env->GetIsolate()); 5500 v8::HandleScope scope(env->GetIsolate());
5354 5501
5355 Local<v8::FunctionTemplate> desc = 5502 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New();
5356 v8::FunctionTemplate::New(0, v8::Handle<Value>());
5357 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 5503 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
5358 5504
5359 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 5505 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
5360 env->Global()->Set(v8_str("undetectable"), obj); 5506 env->Global()->Set(v8_str("undetectable"), obj);
5361 5507
5362 ExpectBoolean("undefined == void 0", true); 5508 ExpectBoolean("undefined == void 0", true);
5363 ExpectBoolean("undetectable == void 0", true); 5509 ExpectBoolean("undetectable == void 0", true);
5364 ExpectBoolean("null == void 0", true); 5510 ExpectBoolean("null == void 0", true);
5365 ExpectBoolean("undefined === void 0", true); 5511 ExpectBoolean("undefined === void 0", true);
5366 ExpectBoolean("undetectable === void 0", false); 5512 ExpectBoolean("undetectable === void 0", false);
(...skipping 22 matching lines...) Expand all
5389 " }" 5535 " }"
5390 "})()", 5536 "})()",
5391 "ReferenceError: x is not defined"); 5537 "ReferenceError: x is not defined");
5392 } 5538 }
5393 5539
5394 5540
5395 THREADED_TEST(ExtensibleOnUndetectable) { 5541 THREADED_TEST(ExtensibleOnUndetectable) {
5396 LocalContext env; 5542 LocalContext env;
5397 v8::HandleScope scope(env->GetIsolate()); 5543 v8::HandleScope scope(env->GetIsolate());
5398 5544
5399 Local<v8::FunctionTemplate> desc = 5545 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New();
5400 v8::FunctionTemplate::New(0, v8::Handle<Value>());
5401 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 5546 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
5402 5547
5403 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 5548 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
5404 env->Global()->Set(v8_str("undetectable"), obj); 5549 env->Global()->Set(v8_str("undetectable"), obj);
5405 5550
5406 Local<String> source = v8_str("undetectable.x = 42;" 5551 Local<String> source = v8_str("undetectable.x = 42;"
5407 "undetectable.x"); 5552 "undetectable.x");
5408 5553
5409 Local<Script> script = Script::Compile(source); 5554 Local<Script> script = Script::Compile(source);
5410 5555
(...skipping 4980 matching lines...) Expand 10 before | Expand all | Expand 10 after
10391 " result" 10536 " result"
10392 "} catch(e) {" 10537 "} catch(e) {"
10393 " e" 10538 " e"
10394 "};"); 10539 "};");
10395 CHECK_EQ(239 * 10, value->Int32Value()); 10540 CHECK_EQ(239 * 10, value->Int32Value());
10396 } 10541 }
10397 10542
10398 static v8::Handle<Value> InterceptorCallICFastApi(Local<String> name, 10543 static v8::Handle<Value> InterceptorCallICFastApi(Local<String> name,
10399 const AccessorInfo& info) { 10544 const AccessorInfo& info) {
10400 ApiTestFuzzer::Fuzz(); 10545 ApiTestFuzzer::Fuzz();
10546 CheckReturnValue(info);
10401 int* call_count = 10547 int* call_count =
10402 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); 10548 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value());
10403 ++(*call_count); 10549 ++(*call_count);
10404 if ((*call_count) % 20 == 0) { 10550 if ((*call_count) % 20 == 0) {
10405 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 10551 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
10406 } 10552 }
10407 return v8::Handle<Value>(); 10553 return v8::Handle<Value>();
10408 } 10554 }
10409 10555
10410 static v8::Handle<Value> FastApiCallback_TrivialSignature( 10556 static v8::Handle<Value> FastApiCallback_TrivialSignature(
10411 const v8::Arguments& args) { 10557 const v8::Arguments& args) {
10412 ApiTestFuzzer::Fuzz(); 10558 ApiTestFuzzer::Fuzz();
10559 CheckReturnValue(args);
10413 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 10560 v8::Isolate* isolate = v8::Isolate::GetCurrent();
10414 CHECK_EQ(isolate, args.GetIsolate()); 10561 CHECK_EQ(isolate, args.GetIsolate());
10415 CHECK_EQ(args.This(), args.Holder()); 10562 CHECK_EQ(args.This(), args.Holder());
10416 CHECK(args.Data()->Equals(v8_str("method_data"))); 10563 CHECK(args.Data()->Equals(v8_str("method_data")));
10417 return v8::Integer::New(args[0]->Int32Value() + 1); 10564 return v8::Integer::New(args[0]->Int32Value() + 1);
10418 } 10565 }
10419 10566
10420 static v8::Handle<Value> FastApiCallback_SimpleSignature( 10567 static v8::Handle<Value> FastApiCallback_SimpleSignature(
10421 const v8::Arguments& args) { 10568 const v8::Arguments& args) {
10422 ApiTestFuzzer::Fuzz(); 10569 ApiTestFuzzer::Fuzz();
10570 CheckReturnValue(args);
10423 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 10571 v8::Isolate* isolate = v8::Isolate::GetCurrent();
10424 CHECK_EQ(isolate, args.GetIsolate()); 10572 CHECK_EQ(isolate, args.GetIsolate());
10425 CHECK_EQ(args.This()->GetPrototype(), args.Holder()); 10573 CHECK_EQ(args.This()->GetPrototype(), args.Holder());
10426 CHECK(args.Data()->Equals(v8_str("method_data"))); 10574 CHECK(args.Data()->Equals(v8_str("method_data")));
10427 // Note, we're using HasRealNamedProperty instead of Has to avoid 10575 // Note, we're using HasRealNamedProperty instead of Has to avoid
10428 // invoking the interceptor again. 10576 // invoking the interceptor again.
10429 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); 10577 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo")));
10430 return v8::Integer::New(args[0]->Int32Value() + 1); 10578 return v8::Integer::New(args[0]->Int32Value() + 1);
10431 } 10579 }
10432 10580
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
10490 "function f() {" 10638 "function f() {"
10491 " for (var i = 1; i <= 5; i++) {" 10639 " for (var i = 1; i <= 5; i++) {"
10492 " try { nativeobject.callback(); } catch (e) { result += e; }" 10640 " try { nativeobject.callback(); } catch (e) { result += e; }"
10493 " }" 10641 " }"
10494 "}" 10642 "}"
10495 "f(); result;"); 10643 "f(); result;");
10496 CHECK_EQ(v8_str("ggggg"), result); 10644 CHECK_EQ(v8_str("ggggg"), result);
10497 } 10645 }
10498 10646
10499 10647
10500 v8::Handle<v8::Value> DirectGetterCallback(Local<String> name, 10648 static Handle<Value> DoDirectGetter() {
10501 const v8::AccessorInfo& info) {
10502 if (++p_getter_count % 3 == 0) { 10649 if (++p_getter_count % 3 == 0) {
10503 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 10650 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
10504 GenerateSomeGarbage(); 10651 GenerateSomeGarbage();
10505 } 10652 }
10653 return v8_str("Direct Getter Result");
10654 }
10655
10656 static v8::Handle<v8::Value> DirectGetter(Local<String> name,
10657 const v8::AccessorInfo& info) {
10658 CheckReturnValue(info);
10659 info.GetReturnValue().Set(v8_str("Garbage"));
10660 return DoDirectGetter();
10661 }
10662
10663 static v8::Handle<v8::Value> DirectGetterIndirect(
10664 Local<String> name,
10665 const v8::AccessorInfo& info) {
10666 CheckReturnValue(info);
10667 info.GetReturnValue().Set(DoDirectGetter());
10506 return v8::Handle<v8::Value>(); 10668 return v8::Handle<v8::Value>();
10507 } 10669 }
10508 10670
10671 static void DirectGetterCallback(
10672 Local<String> name,
10673 const v8::PropertyCallbackInfo<v8::Value>& info) {
10674 CheckReturnValue(info);
10675 info.GetReturnValue().Set(DoDirectGetter());
10676 }
10509 10677
10510 THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { 10678
10679 template<typename Accessor>
10680 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) {
10511 LocalContext context; 10681 LocalContext context;
10512 v8::HandleScope scope(context->GetIsolate()); 10682 v8::HandleScope scope(context->GetIsolate());
10513 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); 10683 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
10514 obj->SetAccessor(v8_str("p1"), DirectGetterCallback); 10684 obj->SetAccessor(v8_str("p1"), accessor);
10515 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 10685 context->Global()->Set(v8_str("o1"), obj->NewInstance());
10516 p_getter_count = 0; 10686 p_getter_count = 0;
10517 CompileRun( 10687 v8::Handle<v8::Value> result = CompileRun(
10518 "function f() {" 10688 "function f() {"
10519 " for (var i = 0; i < 30; i++) o1.p1;" 10689 " for (var i = 0; i < 30; i++) o1.p1;"
10690 " return o1.p1"
10520 "}" 10691 "}"
10521 "f();"); 10692 "f();");
10522 CHECK_EQ(30, p_getter_count); 10693 CHECK_EQ(v8_str("Direct Getter Result"), result);
10694 CHECK_EQ(31, p_getter_count);
10695 }
10696
10697 THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) {
10698 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterIndirect);
10699 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback);
10700 LoadICFastApi_DirectCall_GCMoveStub(DirectGetter);
10523 } 10701 }
10524 10702
10525 10703
10526 v8::Handle<v8::Value> ThrowingDirectGetterCallback( 10704 v8::Handle<v8::Value> ThrowingDirectGetterCallback(
10527 Local<String> name, const v8::AccessorInfo& info) { 10705 Local<String> name, const v8::AccessorInfo& info) {
10528 return v8::ThrowException(v8_str("g")); 10706 return v8::ThrowException(v8_str("g"));
10529 } 10707 }
10530 10708
10531 10709
10532 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { 10710 THREADED_TEST(LoadICFastApi_DirectCall_Throw) {
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
11191 "};" 11369 "};"
11192 "f();"); 11370 "f();");
11193 CHECK_EQ(true, value->BooleanValue()); 11371 CHECK_EQ(true, value->BooleanValue());
11194 } 11372 }
11195 11373
11196 11374
11197 // Test that we ignore null interceptors. 11375 // Test that we ignore null interceptors.
11198 THREADED_TEST(NullNamedInterceptor) { 11376 THREADED_TEST(NullNamedInterceptor) {
11199 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11377 v8::HandleScope scope(v8::Isolate::GetCurrent());
11200 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11378 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11201 templ->SetNamedPropertyHandler(0); 11379 templ->SetNamedPropertyHandler(static_cast<v8::NamedPropertyGetter>(0));
11202 LocalContext context; 11380 LocalContext context;
11203 templ->Set("x", v8_num(42)); 11381 templ->Set("x", v8_num(42));
11204 v8::Handle<v8::Object> obj = templ->NewInstance(); 11382 v8::Handle<v8::Object> obj = templ->NewInstance();
11205 context->Global()->Set(v8_str("obj"), obj); 11383 context->Global()->Set(v8_str("obj"), obj);
11206 v8::Handle<Value> value = CompileRun("obj.x"); 11384 v8::Handle<Value> value = CompileRun("obj.x");
11207 CHECK(value->IsInt32()); 11385 CHECK(value->IsInt32());
11208 CHECK_EQ(42, value->Int32Value()); 11386 CHECK_EQ(42, value->Int32Value());
11209 } 11387 }
11210 11388
11211 11389
11212 // Test that we ignore null interceptors. 11390 // Test that we ignore null interceptors.
11213 THREADED_TEST(NullIndexedInterceptor) { 11391 THREADED_TEST(NullIndexedInterceptor) {
11214 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11392 v8::HandleScope scope(v8::Isolate::GetCurrent());
11215 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11393 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11216 templ->SetIndexedPropertyHandler(0); 11394 templ->SetIndexedPropertyHandler(static_cast<v8::IndexedPropertyGetter>(0));
11217 LocalContext context; 11395 LocalContext context;
11218 templ->Set("42", v8_num(42)); 11396 templ->Set("42", v8_num(42));
11219 v8::Handle<v8::Object> obj = templ->NewInstance(); 11397 v8::Handle<v8::Object> obj = templ->NewInstance();
11220 context->Global()->Set(v8_str("obj"), obj); 11398 context->Global()->Set(v8_str("obj"), obj);
11221 v8::Handle<Value> value = CompileRun("obj[42]"); 11399 v8::Handle<Value> value = CompileRun("obj[42]");
11222 CHECK(value->IsInt32()); 11400 CHECK(value->IsInt32());
11223 CHECK_EQ(42, value->Int32Value()); 11401 CHECK_EQ(42, value->Int32Value());
11224 } 11402 }
11225 11403
11226 11404
(...skipping 7755 matching lines...) Expand 10 before | Expand all | Expand 10 after
18982 i::Semaphore* sem_; 19160 i::Semaphore* sem_;
18983 volatile int sem_value_; 19161 volatile int sem_value_;
18984 }; 19162 };
18985 19163
18986 19164
18987 THREADED_TEST(SemaphoreInterruption) { 19165 THREADED_TEST(SemaphoreInterruption) {
18988 ThreadInterruptTest().RunTest(); 19166 ThreadInterruptTest().RunTest();
18989 } 19167 }
18990 19168
18991 #endif // WIN32 19169 #endif // WIN32
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698