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

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

Issue 9240006: Fix handling of named interceptors in optimized code. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 8 years, 11 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/ast.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 8894 matching lines...) Expand 10 before | Expand all | Expand 10 after
8905 "}" 8905 "}"
8906 "proto1.y = function(x) { return x - 1; };" 8906 "proto1.y = function(x) { return x - 1; };"
8907 "var result = 0;" 8907 "var result = 0;"
8908 "for (var i = 0; i < 7; i++) {" 8908 "for (var i = 0; i < 7; i++) {"
8909 " result += o.y(42);" 8909 " result += o.y(42);"
8910 "}"); 8910 "}");
8911 CHECK_EQ(41 * 7, value->Int32Value()); 8911 CHECK_EQ(41 * 7, value->Int32Value());
8912 } 8912 }
8913 8913
8914 8914
8915 static v8::Handle<Value> call_ic_function5;
8916 static v8::Handle<Value> InterceptorCallICGetter5(Local<String> name,
8917 const AccessorInfo& info) {
8918 ApiTestFuzzer::Fuzz();
8919 if (v8_str("x")->Equals(name))
8920 return call_ic_function5;
8921 else
8922 return Local<Value>();
8923 }
8924
8925
8926 // This test checks that if interceptor doesn't provide a function, 8915 // This test checks that if interceptor doesn't provide a function,
8927 // cached constant function is used 8916 // cached constant function is used
8928 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { 8917 THREADED_TEST(InterceptorCallICConstantFunctionUsed) {
8929 v8::HandleScope scope; 8918 v8::HandleScope scope;
8930 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 8919 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
8931 templ->SetNamedPropertyHandler(NoBlockGetterX); 8920 templ->SetNamedPropertyHandler(NoBlockGetterX);
8932 LocalContext context; 8921 LocalContext context;
8933 context->Global()->Set(v8_str("o"), templ->NewInstance()); 8922 context->Global()->Set(v8_str("o"), templ->NewInstance());
8934 v8::Handle<Value> value = CompileRun( 8923 v8::Handle<Value> value = CompileRun(
8935 "function inc(x) { return x + 1; };" 8924 "function inc(x) { return x + 1; };"
8936 "inc(1);" 8925 "inc(1);"
8937 "o.x = inc;" 8926 "o.x = inc;"
8938 "var result = 0;" 8927 "var result = 0;"
8939 "for (var i = 0; i < 1000; i++) {" 8928 "for (var i = 0; i < 1000; i++) {"
8940 " result = o.x(42);" 8929 " result = o.x(42);"
8941 "}"); 8930 "}");
8942 CHECK_EQ(43, value->Int32Value()); 8931 CHECK_EQ(43, value->Int32Value());
8943 } 8932 }
8944 8933
8945 8934
8935 static v8::Handle<Value> call_ic_function5;
8936 static v8::Handle<Value> InterceptorCallICGetter5(Local<String> name,
8937 const AccessorInfo& info) {
8938 ApiTestFuzzer::Fuzz();
8939 if (v8_str("x")->Equals(name))
8940 return call_ic_function5;
8941 else
8942 return Local<Value>();
8943 }
8944
8945
8946 // This test checks that if interceptor provides a function, 8946 // This test checks that if interceptor provides a function,
8947 // even if we cached constant function, interceptor's function 8947 // even if we cached constant function, interceptor's function
8948 // is invoked 8948 // is invoked
8949 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { 8949 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) {
8950 v8::HandleScope scope; 8950 v8::HandleScope scope;
8951 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 8951 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
8952 templ->SetNamedPropertyHandler(InterceptorCallICGetter5); 8952 templ->SetNamedPropertyHandler(InterceptorCallICGetter5);
8953 LocalContext context; 8953 LocalContext context;
8954 context->Global()->Set(v8_str("o"), templ->NewInstance()); 8954 context->Global()->Set(v8_str("o"), templ->NewInstance());
8955 call_ic_function5 = 8955 call_ic_function5 =
8956 v8_compile("function f(x) { return x - 1; }; f")->Run(); 8956 v8_compile("function f(x) { return x - 1; }; f")->Run();
8957 v8::Handle<Value> value = CompileRun( 8957 v8::Handle<Value> value = CompileRun(
8958 "function inc(x) { return x + 1; };" 8958 "function inc(x) { return x + 1; };"
8959 "inc(1);" 8959 "inc(1);"
8960 "o.x = inc;" 8960 "o.x = inc;"
8961 "var result = 0;" 8961 "var result = 0;"
8962 "for (var i = 0; i < 1000; i++) {" 8962 "for (var i = 0; i < 1000; i++) {"
8963 " result = o.x(42);" 8963 " result = o.x(42);"
8964 "}"); 8964 "}");
8965 CHECK_EQ(41, value->Int32Value()); 8965 CHECK_EQ(41, value->Int32Value());
8966 } 8966 }
8967 8967
8968 8968
8969 static v8::Handle<Value> call_ic_function6;
8970 static v8::Handle<Value> InterceptorCallICGetter6(Local<String> name,
8971 const AccessorInfo& info) {
8972 ApiTestFuzzer::Fuzz();
8973 if (v8_str("x")->Equals(name))
8974 return call_ic_function6;
8975 else
8976 return Local<Value>();
8977 }
8978
8979
8980 // Same test as above, except the code is wrapped in a function
8981 // to test the optimized compiler.
8982 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) {
8983 i::FLAG_allow_natives_syntax = true;
8984 v8::HandleScope scope;
8985 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
8986 templ->SetNamedPropertyHandler(InterceptorCallICGetter6);
8987 LocalContext context;
8988 context->Global()->Set(v8_str("o"), templ->NewInstance());
8989 call_ic_function6 =
8990 v8_compile("function f(x) { return x - 1; }; f")->Run();
8991 v8::Handle<Value> value = CompileRun(
8992 "function inc(x) { return x + 1; };"
8993 "inc(1);"
8994 "o.x = inc;"
8995 "function test() {"
8996 " var result = 0;"
8997 " for (var i = 0; i < 1000; i++) {"
8998 " result = o.x(42);"
8999 " }"
9000 " return result;"
9001 "};"
9002 "test();"
9003 "test();"
9004 "test();"
9005 "%OptimizeFunctionOnNextCall(test);"
9006 "test()");
9007 CHECK_EQ(41, value->Int32Value());
9008 }
9009
9010
8969 // Test the case when we stored constant function into 9011 // Test the case when we stored constant function into
8970 // a stub, but it got invalidated later on 9012 // a stub, but it got invalidated later on
8971 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { 9013 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) {
8972 v8::HandleScope scope; 9014 v8::HandleScope scope;
8973 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9015 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
8974 templ->SetNamedPropertyHandler(NoBlockGetterX); 9016 templ->SetNamedPropertyHandler(NoBlockGetterX);
8975 LocalContext context; 9017 LocalContext context;
8976 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9018 context->Global()->Set(v8_str("o"), templ->NewInstance());
8977 v8::Handle<Value> value = CompileRun( 9019 v8::Handle<Value> value = CompileRun(
8978 "function inc(x) { return x + 1; };" 9020 "function inc(x) { return x + 1; };"
(...skipping 6905 matching lines...) Expand 10 before | Expand all | Expand 10 after
15884 CompileRun("throw 'exception';"); 15926 CompileRun("throw 'exception';");
15885 } 15927 }
15886 15928
15887 15929
15888 TEST(CallCompletedCallbackTwoExceptions) { 15930 TEST(CallCompletedCallbackTwoExceptions) {
15889 v8::HandleScope scope; 15931 v8::HandleScope scope;
15890 LocalContext env; 15932 LocalContext env;
15891 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); 15933 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException);
15892 CompileRun("throw 'first exception';"); 15934 CompileRun("throw 'first exception';");
15893 } 15935 }
OLDNEW
« no previous file with comments | « src/ast.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698