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 8045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8056 | 8056 |
8057 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 8057 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
8058 LocalContext context(NULL, global_template); | 8058 LocalContext context(NULL, global_template); |
8059 | 8059 |
8060 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 8060 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); |
8061 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); | 8061 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); |
8062 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); | 8062 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); |
8063 Local<ObjectTemplate> proto = t->PrototypeTemplate(); | 8063 Local<ObjectTemplate> proto = t->PrototypeTemplate(); |
8064 Local<ObjectTemplate> instance = t->InstanceTemplate(); | 8064 Local<ObjectTemplate> instance = t->InstanceTemplate(); |
8065 | 8065 |
8066 // Only allow calls of f on instances of t. | |
8067 Local<v8::Signature> signature = v8::Signature::New(t); | |
8068 proto->Set(v8_str("f"), | 8066 proto->Set(v8_str("f"), |
8069 v8::FunctionTemplate::New(ShadowFunctionCallback, | 8067 v8::FunctionTemplate::New(ShadowFunctionCallback, Local<Value>())); |
8070 Local<Value>(), | |
8071 signature)); | |
8072 proto->Set(v8_str("x"), v8_num(12)); | 8068 proto->Set(v8_str("x"), v8_num(12)); |
8073 | 8069 |
8074 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); | 8070 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); |
8075 | 8071 |
8076 Local<Value> o = t->GetFunction()->NewInstance(); | 8072 Local<Value> o = t->GetFunction()->NewInstance(); |
8077 context->Global()->Set(v8_str("__proto__"), o); | 8073 context->Global()->Set(v8_str("__proto__"), o); |
8078 | 8074 |
8079 Local<Value> value = | 8075 Local<Value> value = |
8080 Script::Compile(v8_str("this.propertyIsEnumerable(0)"))->Run(); | 8076 Script::Compile(v8_str("this.propertyIsEnumerable(0)"))->Run(); |
8081 CHECK(value->IsBoolean()); | 8077 CHECK(value->IsBoolean()); |
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9766 CHECK_EQ(args.This(), args.Holder()); | 9762 CHECK_EQ(args.This(), args.Holder()); |
9767 CHECK(args.Data()->Equals(v8_str("method_data"))); | 9763 CHECK(args.Data()->Equals(v8_str("method_data"))); |
9768 return v8::Integer::New(args[0]->Int32Value() + 1); | 9764 return v8::Integer::New(args[0]->Int32Value() + 1); |
9769 } | 9765 } |
9770 | 9766 |
9771 static v8::Handle<Value> FastApiCallback_SimpleSignature( | 9767 static v8::Handle<Value> FastApiCallback_SimpleSignature( |
9772 const v8::Arguments& args) { | 9768 const v8::Arguments& args) { |
9773 ApiTestFuzzer::Fuzz(); | 9769 ApiTestFuzzer::Fuzz(); |
9774 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 9770 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
9775 CHECK_EQ(isolate, args.GetIsolate()); | 9771 CHECK_EQ(isolate, args.GetIsolate()); |
9776 CHECK_EQ(args.This()->GetPrototype(), args.Holder()); | 9772 CHECK_EQ(args.This(), args.Holder()); |
9777 CHECK(args.Data()->Equals(v8_str("method_data"))); | 9773 CHECK(args.Data()->Equals(v8_str("method_data"))); |
9778 // Note, we're using HasRealNamedProperty instead of Has to avoid | 9774 // Note, we're using HasRealNamedProperty instead of Has to avoid |
9779 // invoking the interceptor again. | 9775 // invoking the interceptor again. |
9780 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); | 9776 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); |
9781 return v8::Integer::New(args[0]->Int32Value() + 1); | 9777 return v8::Integer::New(args[0]->Int32Value() + 1); |
9782 } | 9778 } |
9783 | 9779 |
9784 // Helper to maximize the odds of object moving. | 9780 // Helper to maximize the odds of object moving. |
9785 static void GenerateSomeGarbage() { | 9781 static void GenerateSomeGarbage() { |
9786 CompileRun( | 9782 CompileRun( |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9916 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9912 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9917 CompileRun( | 9913 CompileRun( |
9918 "var result = 0;" | 9914 "var result = 0;" |
9919 "for (var i = 0; i < 100; i++) {" | 9915 "for (var i = 0; i < 100; i++) {" |
9920 " result = o.method(41);" | 9916 " result = o.method(41);" |
9921 "}"); | 9917 "}"); |
9922 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 9918 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
9923 CHECK_EQ(100, interceptor_call_count); | 9919 CHECK_EQ(100, interceptor_call_count); |
9924 } | 9920 } |
9925 | 9921 |
9922 | |
9926 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature) { | 9923 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature) { |
9927 int interceptor_call_count = 0; | 9924 int interceptor_call_count = 0; |
9928 v8::HandleScope scope; | 9925 v8::HandleScope scope; |
9929 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9926 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9930 v8::Handle<v8::FunctionTemplate> method_templ = | 9927 v8::Handle<v8::FunctionTemplate> method_templ = |
9931 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9928 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9932 v8_str("method_data"), | 9929 v8_str("method_data"), |
9933 v8::Signature::New(fun_templ)); | 9930 v8::Signature::New(fun_templ)); |
9934 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9931 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9935 proto_templ->Set(v8_str("method"), method_templ); | 9932 proto_templ->Set(v8_str("method"), method_templ); |
9936 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 9933 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
9937 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 9934 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
9938 NULL, NULL, NULL, NULL, | 9935 NULL, NULL, NULL, NULL, |
9939 v8::External::Wrap(&interceptor_call_count)); | 9936 v8::External::Wrap(&interceptor_call_count)); |
9940 LocalContext context; | 9937 LocalContext context; |
9941 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9938 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9942 GenerateSomeGarbage(); | 9939 GenerateSomeGarbage(); |
9943 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9940 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9944 CompileRun( | 9941 CompileRun( |
9945 "o.foo = 17;" | 9942 "o.foo = 17;" |
9946 "var receiver = {};" | 9943 "var receiver = o;" |
rossberg
2012/11/20 11:00:09
Nit: if you want, remove 'receiver' altogether.
| |
9947 "receiver.__proto__ = o;" | |
9948 "var result = 0;" | 9944 "var result = 0;" |
9949 "for (var i = 0; i < 100; i++) {" | 9945 "for (var i = 0; i < 100; i++) {" |
9950 " result = receiver.method(41);" | 9946 " result = receiver.method(41);" |
9951 "}"); | 9947 "}"); |
9952 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 9948 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
9953 CHECK_EQ(100, interceptor_call_count); | 9949 CHECK_EQ(100, interceptor_call_count); |
9954 } | 9950 } |
9955 | 9951 |
9952 | |
9956 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { | 9953 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { |
9957 int interceptor_call_count = 0; | 9954 int interceptor_call_count = 0; |
9958 v8::HandleScope scope; | 9955 v8::HandleScope scope; |
9959 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9956 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9960 v8::Handle<v8::FunctionTemplate> method_templ = | 9957 v8::Handle<v8::FunctionTemplate> method_templ = |
9961 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9958 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9962 v8_str("method_data"), | 9959 v8_str("method_data"), |
9963 v8::Signature::New(fun_templ)); | 9960 v8::Signature::New(fun_templ)); |
9964 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9961 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
9965 proto_templ->Set(v8_str("method"), method_templ); | 9962 proto_templ->Set(v8_str("method"), method_templ); |
9966 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 9963 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
9967 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 9964 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
9968 NULL, NULL, NULL, NULL, | 9965 NULL, NULL, NULL, NULL, |
9969 v8::External::Wrap(&interceptor_call_count)); | 9966 v8::External::Wrap(&interceptor_call_count)); |
9970 LocalContext context; | 9967 LocalContext context; |
9971 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 9968 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
9972 GenerateSomeGarbage(); | 9969 GenerateSomeGarbage(); |
9973 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 9970 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
9974 CompileRun( | 9971 CompileRun( |
9975 "o.foo = 17;" | 9972 "o.foo = 17;" |
9976 "var receiver = {};" | 9973 "var receiver = o;" |
9977 "receiver.__proto__ = o;" | |
9978 "var result = 0;" | 9974 "var result = 0;" |
9979 "var saved_result = 0;" | 9975 "var saved_result = 0;" |
9980 "for (var i = 0; i < 100; i++) {" | 9976 "for (var i = 0; i < 100; i++) {" |
9981 " result = receiver.method(41);" | 9977 " result = receiver.method(41);" |
9982 " if (i == 50) {" | 9978 " if (i == 50) {" |
9983 " saved_result = result;" | 9979 " saved_result = result;" |
9984 " receiver = {method: function(x) { return x - 1 }};" | 9980 " receiver = {method: function(x) { return x - 1 }};" |
9985 " }" | 9981 " }" |
9986 "}"); | 9982 "}"); |
9987 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 9983 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); |
9988 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 9984 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
9989 CHECK_GE(interceptor_call_count, 50); | 9985 CHECK_GE(interceptor_call_count, 50); |
9990 } | 9986 } |
9991 | 9987 |
9988 | |
9992 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { | 9989 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { |
9993 int interceptor_call_count = 0; | 9990 int interceptor_call_count = 0; |
9994 v8::HandleScope scope; | 9991 v8::HandleScope scope; |
9995 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 9992 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
9996 v8::Handle<v8::FunctionTemplate> method_templ = | 9993 v8::Handle<v8::FunctionTemplate> method_templ = |
9997 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 9994 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
9998 v8_str("method_data"), | 9995 v8_str("method_data"), |
9999 v8::Signature::New(fun_templ)); | 9996 v8::Signature::New(fun_templ)); |
10000 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 9997 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10001 proto_templ->Set(v8_str("method"), method_templ); | 9998 proto_templ->Set(v8_str("method"), method_templ); |
10002 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 9999 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
10003 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 10000 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
10004 NULL, NULL, NULL, NULL, | 10001 NULL, NULL, NULL, NULL, |
10005 v8::External::Wrap(&interceptor_call_count)); | 10002 v8::External::Wrap(&interceptor_call_count)); |
10006 LocalContext context; | 10003 LocalContext context; |
10007 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 10004 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
10008 GenerateSomeGarbage(); | 10005 GenerateSomeGarbage(); |
10009 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 10006 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
10007 v8::TryCatch try_catch; | |
10010 CompileRun( | 10008 CompileRun( |
10011 "o.foo = 17;" | 10009 "o.foo = 17;" |
10012 "var receiver = {};" | 10010 "var receiver = o;" |
10013 "receiver.__proto__ = o;" | |
10014 "var result = 0;" | 10011 "var result = 0;" |
10015 "var saved_result = 0;" | 10012 "var saved_result = 0;" |
10016 "for (var i = 0; i < 100; i++) {" | 10013 "for (var i = 0; i < 100; i++) {" |
10017 " result = receiver.method(41);" | 10014 " result = receiver.method(41);" |
10018 " if (i == 50) {" | 10015 " if (i == 50) {" |
10019 " saved_result = result;" | 10016 " saved_result = result;" |
10020 " o.method = function(x) { return x - 1 };" | 10017 " result = 0;" |
10018 " receiver = 333;" | |
10021 " }" | 10019 " }" |
10022 "}"); | 10020 "}"); |
10023 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 10021 CHECK(try_catch.HasCaught()); |
10022 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), | |
10023 try_catch.Exception()->ToString()); | |
10024 CHECK_EQ(0, context->Global()->Get(v8_str("result"))->Int32Value()); | |
10024 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 10025 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
10025 CHECK_GE(interceptor_call_count, 50); | 10026 CHECK_GE(interceptor_call_count, 50); |
10026 } | 10027 } |
10027 | 10028 |
10028 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { | 10029 |
10030 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError1) { | |
10029 int interceptor_call_count = 0; | 10031 int interceptor_call_count = 0; |
10030 v8::HandleScope scope; | 10032 v8::HandleScope scope; |
10031 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 10033 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
10032 v8::Handle<v8::FunctionTemplate> method_templ = | 10034 v8::Handle<v8::FunctionTemplate> method_templ = |
10033 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 10035 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
10034 v8_str("method_data"), | 10036 v8_str("method_data"), |
10035 v8::Signature::New(fun_templ)); | 10037 v8::Signature::New(fun_templ)); |
10036 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 10038 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10037 proto_templ->Set(v8_str("method"), method_templ); | 10039 proto_templ->Set(v8_str("method"), method_templ); |
10038 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 10040 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
10039 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 10041 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
10040 NULL, NULL, NULL, NULL, | 10042 NULL, NULL, NULL, NULL, |
10041 v8::External::Wrap(&interceptor_call_count)); | 10043 v8::External::Wrap(&interceptor_call_count)); |
10042 LocalContext context; | 10044 LocalContext context; |
10043 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 10045 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
10044 GenerateSomeGarbage(); | 10046 GenerateSomeGarbage(); |
10045 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 10047 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
10046 v8::TryCatch try_catch; | 10048 v8::TryCatch try_catch; |
10047 CompileRun( | 10049 CompileRun( |
10048 "o.foo = 17;" | 10050 "o.foo = 17;" |
10049 "var receiver = {};" | 10051 "var receiver = o;" |
10050 "receiver.__proto__ = o;" | |
10051 "var result = 0;" | 10052 "var result = 0;" |
10052 "var saved_result = 0;" | |
10053 "for (var i = 0; i < 100; i++) {" | 10053 "for (var i = 0; i < 100; i++) {" |
10054 " result = receiver.method(41);" | |
10055 " if (i == 50) {" | 10054 " if (i == 50) {" |
10056 " saved_result = result;" | 10055 " saved_result = result;" |
10057 " receiver = 333;" | 10056 " result = 0;" |
10057 " receiver = {};" | |
10058 " receiver.__proto__ = o;" | |
10058 " }" | 10059 " }" |
10060 " result = receiver.method(41);" | |
10059 "}"); | 10061 "}"); |
10060 CHECK(try_catch.HasCaught()); | 10062 CHECK(try_catch.HasCaught()); |
10061 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), | 10063 CHECK_EQ(v8_str("TypeError: Illegal invocation"), |
10062 try_catch.Exception()->ToString()); | 10064 try_catch.Exception()->ToString()); |
10065 CHECK_EQ(0, context->Global()->Get(v8_str("result"))->Int32Value()); | |
10063 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 10066 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
10064 CHECK_GE(interceptor_call_count, 50); | 10067 CHECK_GE(interceptor_call_count, 50); |
10065 } | 10068 } |
10066 | 10069 |
10067 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { | 10070 |
10071 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError2) { | |
10068 int interceptor_call_count = 0; | 10072 int interceptor_call_count = 0; |
10069 v8::HandleScope scope; | 10073 v8::HandleScope scope; |
10070 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 10074 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
10071 v8::Handle<v8::FunctionTemplate> method_templ = | 10075 v8::Handle<v8::FunctionTemplate> method_templ = |
10072 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 10076 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
10073 v8_str("method_data"), | 10077 v8_str("method_data"), |
10074 v8::Signature::New(fun_templ)); | 10078 v8::Signature::New(fun_templ)); |
10075 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 10079 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10076 proto_templ->Set(v8_str("method"), method_templ); | 10080 proto_templ->Set(v8_str("method"), method_templ); |
10077 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 10081 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
10078 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, | 10082 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, |
10079 NULL, NULL, NULL, NULL, | 10083 NULL, NULL, NULL, NULL, |
10080 v8::External::Wrap(&interceptor_call_count)); | 10084 v8::External::Wrap(&interceptor_call_count)); |
10081 LocalContext context; | 10085 LocalContext context; |
10082 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 10086 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
10083 GenerateSomeGarbage(); | 10087 GenerateSomeGarbage(); |
10084 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 10088 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
10085 v8::TryCatch try_catch; | 10089 v8::TryCatch try_catch; |
10086 CompileRun( | 10090 CompileRun( |
10087 "o.foo = 17;" | 10091 "o.foo = 17;" |
10088 "var receiver = {};" | 10092 "var receiver = o;" |
10089 "receiver.__proto__ = o;" | |
10090 "var result = 0;" | 10093 "var result = 0;" |
10091 "var saved_result = 0;" | 10094 "var saved_result = 0;" |
10092 "for (var i = 0; i < 100; i++) {" | 10095 "for (var i = 0; i < 100; i++) {" |
10093 " result = receiver.method(41);" | 10096 " result = receiver.method(41);" |
10094 " if (i == 50) {" | 10097 " if (i == 50) {" |
10095 " saved_result = result;" | 10098 " saved_result = result;" |
10099 " result = 0;" | |
10096 " receiver = {method: receiver.method};" | 10100 " receiver = {method: receiver.method};" |
10097 " }" | 10101 " }" |
10098 "}"); | 10102 "}"); |
10099 CHECK(try_catch.HasCaught()); | 10103 CHECK(try_catch.HasCaught()); |
10100 CHECK_EQ(v8_str("TypeError: Illegal invocation"), | 10104 CHECK_EQ(v8_str("TypeError: Illegal invocation"), |
10101 try_catch.Exception()->ToString()); | 10105 try_catch.Exception()->ToString()); |
10106 CHECK_EQ(0, context->Global()->Get(v8_str("result"))->Int32Value()); | |
10102 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 10107 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
10103 CHECK_GE(interceptor_call_count, 50); | 10108 CHECK_GE(interceptor_call_count, 50); |
10104 } | 10109 } |
10105 | 10110 |
10111 | |
10106 THREADED_TEST(CallICFastApi_TrivialSignature) { | 10112 THREADED_TEST(CallICFastApi_TrivialSignature) { |
10107 v8::HandleScope scope; | 10113 v8::HandleScope scope; |
10108 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 10114 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
10109 v8::Handle<v8::FunctionTemplate> method_templ = | 10115 v8::Handle<v8::FunctionTemplate> method_templ = |
10110 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, | 10116 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, |
10111 v8_str("method_data"), | 10117 v8_str("method_data"), |
10112 v8::Handle<v8::Signature>()); | 10118 v8::Handle<v8::Signature>()); |
10113 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 10119 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10114 proto_templ->Set(v8_str("method"), method_templ); | 10120 proto_templ->Set(v8_str("method"), method_templ); |
10115 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 10121 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
10116 USE(templ); | 10122 USE(templ); |
10117 LocalContext context; | 10123 LocalContext context; |
10118 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 10124 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
10119 GenerateSomeGarbage(); | 10125 GenerateSomeGarbage(); |
10120 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 10126 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
10121 CompileRun( | 10127 CompileRun( |
10122 "var result = 0;" | 10128 "var result = 0;" |
10123 "for (var i = 0; i < 100; i++) {" | 10129 "for (var i = 0; i < 100; i++) {" |
10124 " result = o.method(41);" | 10130 " result = o.method(41);" |
10125 "}"); | 10131 "}"); |
10126 | 10132 |
10127 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 10133 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
10128 } | 10134 } |
10129 | 10135 |
10136 | |
10130 THREADED_TEST(CallICFastApi_SimpleSignature) { | 10137 THREADED_TEST(CallICFastApi_SimpleSignature) { |
10131 v8::HandleScope scope; | 10138 v8::HandleScope scope; |
10132 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 10139 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
10133 v8::Handle<v8::FunctionTemplate> method_templ = | 10140 v8::Handle<v8::FunctionTemplate> method_templ = |
10134 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 10141 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
10135 v8_str("method_data"), | 10142 v8_str("method_data"), |
10136 v8::Signature::New(fun_templ)); | 10143 v8::Signature::New(fun_templ)); |
10137 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 10144 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10138 proto_templ->Set(v8_str("method"), method_templ); | 10145 proto_templ->Set(v8_str("method"), method_templ); |
10139 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 10146 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
10140 CHECK(!templ.IsEmpty()); | 10147 CHECK(!templ.IsEmpty()); |
10141 LocalContext context; | 10148 LocalContext context; |
10142 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 10149 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
10143 GenerateSomeGarbage(); | 10150 GenerateSomeGarbage(); |
10144 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 10151 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
10145 CompileRun( | 10152 CompileRun( |
10146 "o.foo = 17;" | 10153 "o.foo = 17;" |
10147 "var receiver = {};" | 10154 "var receiver = o;" |
rossberg
2012/11/20 11:00:09
Ditto.
| |
10148 "receiver.__proto__ = o;" | |
10149 "var result = 0;" | 10155 "var result = 0;" |
10150 "for (var i = 0; i < 100; i++) {" | 10156 "for (var i = 0; i < 100; i++) {" |
10151 " result = receiver.method(41);" | 10157 " result = receiver.method(41);" |
10152 "}"); | 10158 "}"); |
10153 | 10159 |
10154 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 10160 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
10155 } | 10161 } |
10156 | 10162 |
10163 | |
10157 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) { | 10164 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) { |
10158 v8::HandleScope scope; | 10165 v8::HandleScope scope; |
10159 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 10166 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
10160 v8::Handle<v8::FunctionTemplate> method_templ = | 10167 v8::Handle<v8::FunctionTemplate> method_templ = |
10161 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 10168 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
10162 v8_str("method_data"), | 10169 v8_str("method_data"), |
10163 v8::Signature::New(fun_templ)); | 10170 v8::Signature::New(fun_templ)); |
10164 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 10171 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10165 proto_templ->Set(v8_str("method"), method_templ); | 10172 proto_templ->Set(v8_str("method"), method_templ); |
10166 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 10173 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
10167 CHECK(!templ.IsEmpty()); | 10174 CHECK(!templ.IsEmpty()); |
10168 LocalContext context; | 10175 LocalContext context; |
10169 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 10176 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
10170 GenerateSomeGarbage(); | 10177 GenerateSomeGarbage(); |
10171 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 10178 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
10172 CompileRun( | 10179 CompileRun( |
10173 "o.foo = 17;" | 10180 "o.foo = 17;" |
10174 "var receiver = {};" | 10181 "var receiver = o;" |
10175 "receiver.__proto__ = o;" | |
10176 "var result = 0;" | 10182 "var result = 0;" |
10177 "var saved_result = 0;" | 10183 "var saved_result = 0;" |
10178 "for (var i = 0; i < 100; i++) {" | 10184 "for (var i = 0; i < 100; i++) {" |
10179 " result = receiver.method(41);" | 10185 " result = receiver.method(41);" |
10180 " if (i == 50) {" | 10186 " if (i == 50) {" |
10181 " saved_result = result;" | 10187 " saved_result = result;" |
10182 " receiver = {method: function(x) { return x - 1 }};" | 10188 " receiver = {method: function(x) { return x - 1 }};" |
10183 " }" | 10189 " }" |
10184 "}"); | 10190 "}"); |
10185 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 10191 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); |
10186 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 10192 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
10187 } | 10193 } |
10188 | 10194 |
10195 | |
10189 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) { | 10196 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) { |
10190 v8::HandleScope scope; | 10197 v8::HandleScope scope; |
10191 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 10198 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
10192 v8::Handle<v8::FunctionTemplate> method_templ = | 10199 v8::Handle<v8::FunctionTemplate> method_templ = |
10193 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | 10200 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, |
10194 v8_str("method_data"), | 10201 v8_str("method_data"), |
10195 v8::Signature::New(fun_templ)); | 10202 v8::Signature::New(fun_templ)); |
10196 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 10203 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10197 proto_templ->Set(v8_str("method"), method_templ); | 10204 proto_templ->Set(v8_str("method"), method_templ); |
10198 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 10205 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
10199 CHECK(!templ.IsEmpty()); | 10206 CHECK(!templ.IsEmpty()); |
10200 LocalContext context; | 10207 LocalContext context; |
10201 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 10208 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
10202 GenerateSomeGarbage(); | 10209 GenerateSomeGarbage(); |
10203 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 10210 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
10204 v8::TryCatch try_catch; | 10211 v8::TryCatch try_catch; |
10205 CompileRun( | 10212 CompileRun( |
10206 "o.foo = 17;" | 10213 "o.foo = 17;" |
10207 "var receiver = {};" | 10214 "var receiver = o;" |
10208 "receiver.__proto__ = o;" | |
10209 "var result = 0;" | 10215 "var result = 0;" |
10210 "var saved_result = 0;" | 10216 "var saved_result = 0;" |
10211 "for (var i = 0; i < 100; i++) {" | 10217 "for (var i = 0; i < 100; i++) {" |
10212 " result = receiver.method(41);" | 10218 " result = receiver.method(41);" |
10213 " if (i == 50) {" | 10219 " if (i == 50) {" |
10214 " saved_result = result;" | 10220 " saved_result = result;" |
10221 " result = 0;" | |
10215 " receiver = 333;" | 10222 " receiver = 333;" |
10216 " }" | 10223 " }" |
10217 "}"); | 10224 "}"); |
10218 CHECK(try_catch.HasCaught()); | 10225 CHECK(try_catch.HasCaught()); |
10219 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), | 10226 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), |
10220 try_catch.Exception()->ToString()); | 10227 try_catch.Exception()->ToString()); |
10228 CHECK_EQ(0, context->Global()->Get(v8_str("result"))->Int32Value()); | |
10221 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 10229 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
10222 } | 10230 } |
10223 | 10231 |
10232 | |
10233 THREADED_TEST(CallICFastApi_SimpleSignature_TypeError) { | |
10234 v8::HandleScope scope; | |
10235 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | |
10236 v8::Handle<v8::FunctionTemplate> method_templ = | |
10237 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, | |
10238 v8_str("method_data"), | |
10239 v8::Signature::New(fun_templ)); | |
10240 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | |
10241 proto_templ->Set(v8_str("method"), method_templ); | |
10242 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | |
10243 CHECK(!templ.IsEmpty()); | |
10244 LocalContext context; | |
10245 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | |
10246 GenerateSomeGarbage(); | |
10247 context->Global()->Set(v8_str("o"), fun->NewInstance()); | |
10248 v8::TryCatch try_catch; | |
10249 CompileRun( | |
10250 "o.foo = 17;" | |
10251 "var receiver = o;" | |
10252 "var result = 0;" | |
10253 "var saved_result = 0;" | |
10254 "for (var i = 0; i < 100; i++) {" | |
10255 " result = receiver.method(41);" | |
10256 " if (i == 50) {" | |
10257 " saved_result = result;" | |
10258 " result = 0;" | |
10259 " receiver = {};" | |
10260 " receiver.__proto__ = o;" | |
10261 " }" | |
10262 "}"); | |
10263 CHECK(try_catch.HasCaught()); | |
10264 CHECK_EQ(v8_str("TypeError: Illegal invocation"), | |
10265 try_catch.Exception()->ToString()); | |
10266 CHECK_EQ(0, context->Global()->Get(v8_str("result"))->Int32Value()); | |
10267 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | |
10268 } | |
10269 | |
10224 | 10270 |
10225 v8::Handle<Value> keyed_call_ic_function; | 10271 v8::Handle<Value> keyed_call_ic_function; |
10226 | 10272 |
10227 static v8::Handle<Value> InterceptorKeyedCallICGetter( | 10273 static v8::Handle<Value> InterceptorKeyedCallICGetter( |
10228 Local<String> name, const AccessorInfo& info) { | 10274 Local<String> name, const AccessorInfo& info) { |
10229 ApiTestFuzzer::Fuzz(); | 10275 ApiTestFuzzer::Fuzz(); |
10230 if (v8_str("x")->Equals(name)) { | 10276 if (v8_str("x")->Equals(name)) { |
10231 return keyed_call_ic_function; | 10277 return keyed_call_ic_function; |
10232 } | 10278 } |
10233 return v8::Handle<Value>(); | 10279 return v8::Handle<Value>(); |
(...skipping 7762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17996 | 18042 |
17997 i::Semaphore* sem_; | 18043 i::Semaphore* sem_; |
17998 volatile int sem_value_; | 18044 volatile int sem_value_; |
17999 }; | 18045 }; |
18000 | 18046 |
18001 | 18047 |
18002 THREADED_TEST(SemaphoreInterruption) { | 18048 THREADED_TEST(SemaphoreInterruption) { |
18003 ThreadInterruptTest().RunTest(); | 18049 ThreadInterruptTest().RunTest(); |
18004 } | 18050 } |
18005 #endif // WIN32 | 18051 #endif // WIN32 |
OLD | NEW |