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 21894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21905 static Local<Object> receiver; | 21905 static Local<Object> receiver; |
21906 static Local<Object> holder; | 21906 static Local<Object> holder; |
21907 static Local<Object> callee; | 21907 static Local<Object> callee; |
21908 static int count; | 21908 static int count; |
21909 | 21909 |
21910 static void OptimizationCallback( | 21910 static void OptimizationCallback( |
21911 const v8::FunctionCallbackInfo<v8::Value>& info) { | 21911 const v8::FunctionCallbackInfo<v8::Value>& info) { |
21912 CHECK(callee == info.Callee()); | 21912 CHECK(callee == info.Callee()); |
21913 CHECK(data == info.Data()); | 21913 CHECK(data == info.Data()); |
21914 CHECK(receiver == info.This()); | 21914 CHECK(receiver == info.This()); |
| 21915 if (info.Length() == 1) { |
| 21916 CHECK_EQ(v8_num(1), info[0]); |
| 21917 } |
21915 CHECK(holder == info.Holder()); | 21918 CHECK(holder == info.Holder()); |
21916 count++; | 21919 count++; |
21917 } | 21920 } |
21918 | 21921 |
21919 // TODO(dcarney): move this to v8.h | 21922 // TODO(dcarney): move this to v8.h |
21920 static void SetAccessorProperty(Local<Object> object, | 21923 static void SetAccessorProperty(Local<Object> object, |
21921 Local<String> name, | 21924 Local<String> name, |
21922 Local<Function> getter, | 21925 Local<Function> getter, |
21923 Local<Function> setter = Local<Function>()) { | 21926 Local<Function> setter = Local<Function>()) { |
21924 i::Isolate* isolate = CcTest::i_isolate(); | 21927 i::Isolate* isolate = CcTest::i_isolate(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21967 Local<Object> function_holder = | 21970 Local<Object> function_holder = |
21968 Local<Object>::Cast(function_receiver->GetPrototype()); | 21971 Local<Object>::Cast(function_receiver->GetPrototype()); |
21969 // Install function on hidden prototype object. | 21972 // Install function on hidden prototype object. |
21970 data = Object::New(isolate); | 21973 data = Object::New(isolate); |
21971 Local<FunctionTemplate> function_template = FunctionTemplate::New( | 21974 Local<FunctionTemplate> function_template = FunctionTemplate::New( |
21972 isolate, OptimizationCallback, data, signature); | 21975 isolate, OptimizationCallback, data, signature); |
21973 Local<Function> function = function_template->GetFunction(); | 21976 Local<Function> function = function_template->GetFunction(); |
21974 Local<Object> global_holder = Local<Object>::Cast( | 21977 Local<Object> global_holder = Local<Object>::Cast( |
21975 inner_global->GetPrototype()); | 21978 inner_global->GetPrototype()); |
21976 global_holder->Set(v8_str("g_f"), function); | 21979 global_holder->Set(v8_str("g_f"), function); |
21977 SetAccessorProperty(global_holder, v8_str("g_p1"), function); | 21980 SetAccessorProperty(global_holder, v8_str("g_acc"), function, function); |
21978 function_holder->Set(v8_str("f"), function); | 21981 function_holder->Set(v8_str("f"), function); |
21979 SetAccessorProperty(function_holder, v8_str("p1"), function); | 21982 SetAccessorProperty(function_holder, v8_str("acc"), function, function); |
21980 // Initialize expected values. | 21983 // Initialize expected values. |
21981 callee = function; | 21984 callee = function; |
21982 count = 0; | 21985 count = 0; |
21983 if (global) { | 21986 if (global) { |
21984 receiver = context->Global(); | 21987 receiver = context->Global(); |
21985 holder = inner_global; | 21988 holder = inner_global; |
21986 } else { | 21989 } else { |
21987 holder = function_receiver; | 21990 holder = function_receiver; |
21988 // If not using a signature, add something else to the prototype chain | 21991 // If not using a signature, add something else to the prototype chain |
21989 // to test the case that holder != receiver | 21992 // to test the case that holder != receiver |
(...skipping 10 matching lines...) Expand all Loading... |
22000 } | 22003 } |
22001 // With no signature, the holder is not set. | 22004 // With no signature, the holder is not set. |
22002 if (!use_signature) holder = receiver; | 22005 if (!use_signature) holder = receiver; |
22003 // build wrap_function | 22006 // build wrap_function |
22004 int key = (use_signature ? 1 : 0) + 2 * (global ? 1 : 0); | 22007 int key = (use_signature ? 1 : 0) + 2 * (global ? 1 : 0); |
22005 i::ScopedVector<char> wrap_function(200); | 22008 i::ScopedVector<char> wrap_function(200); |
22006 if (global) { | 22009 if (global) { |
22007 i::OS::SNPrintF( | 22010 i::OS::SNPrintF( |
22008 wrap_function, | 22011 wrap_function, |
22009 "function wrap_f_%d() { var f = g_f; return f(); }\n" | 22012 "function wrap_f_%d() { var f = g_f; return f(); }\n" |
22010 "function wrap_p1_%d() { return this.g_p1; }\n", | 22013 "function wrap_get_%d() { return this.g_acc; }\n" |
22011 key, key); | 22014 "function wrap_set_%d() { this.g_acc = 1; }\n", |
| 22015 key, key, key); |
22012 } else { | 22016 } else { |
22013 i::OS::SNPrintF( | 22017 i::OS::SNPrintF( |
22014 wrap_function, | 22018 wrap_function, |
22015 "function wrap_f_%d() { return receiver_subclass.f(); }\n" | 22019 "function wrap_f_%d() { return receiver_subclass.f(); }\n" |
22016 "function wrap_p1_%d() { return receiver_subclass.p1; }\n", | 22020 "function wrap_get_%d() { return receiver_subclass.acc; }\n" |
22017 key, key); | 22021 "function wrap_set_%d() { receiver_subclass.acc = 1; }\n", |
| 22022 key, key, key); |
22018 } | 22023 } |
22019 // build source string | 22024 // build source string |
22020 i::ScopedVector<char> source(500); | 22025 i::ScopedVector<char> source(500); |
22021 i::OS::SNPrintF( | 22026 i::OS::SNPrintF( |
22022 source, | 22027 source, |
22023 "%s\n" // wrap functions | 22028 "%s\n" // wrap functions |
22024 "function wrap_f() { wrap_f_%d(); }\n" | 22029 "function wrap_f() { wrap_f_%d(); }\n" |
22025 "function wrap_p1() { wrap_p1_%d(); }\n" | 22030 "function wrap_get() { wrap_get_%d(); }\n" |
| 22031 "function wrap_set() { wrap_set_%d(); }\n" |
| 22032 "\n" |
22026 "wrap_f();\n" | 22033 "wrap_f();\n" |
22027 "wrap_f();\n" | 22034 "wrap_f();\n" |
22028 "%%OptimizeFunctionOnNextCall(wrap_f_%d);\n" | 22035 "%%OptimizeFunctionOnNextCall(wrap_f_%d);\n" |
22029 "wrap_f();\n" | 22036 "wrap_f();\n" |
22030 "wrap_p1();\n" | 22037 "\n" |
22031 "wrap_p1();\n" | 22038 "wrap_get();\n" |
22032 "%%OptimizeFunctionOnNextCall(wrap_p1_%d);\n" | 22039 "wrap_get();\n" |
22033 "wrap_p1();\n", | 22040 "%%OptimizeFunctionOnNextCall(wrap_get_%d);\n" |
22034 wrap_function.start(), key, key, key, key); | 22041 "wrap_get();\n" |
| 22042 "\n" |
| 22043 "wrap_set();\n" |
| 22044 "wrap_set();\n" |
| 22045 "%%OptimizeFunctionOnNextCall(wrap_set_%d);\n" |
| 22046 "wrap_set();\n", |
| 22047 wrap_function.start(), key, key, key, key, key, key); |
22035 v8::TryCatch try_catch; | 22048 v8::TryCatch try_catch; |
22036 CompileRun(source.start()); | 22049 CompileRun(source.start()); |
22037 ASSERT(!try_catch.HasCaught()); | 22050 ASSERT(!try_catch.HasCaught()); |
22038 CHECK_EQ(6, count); | 22051 CHECK_EQ(9, count); |
22039 } | 22052 } |
22040 }; | 22053 }; |
22041 | 22054 |
22042 | 22055 |
22043 Local<Object> ApiCallOptimizationChecker::data; | 22056 Local<Object> ApiCallOptimizationChecker::data; |
22044 Local<Object> ApiCallOptimizationChecker::receiver; | 22057 Local<Object> ApiCallOptimizationChecker::receiver; |
22045 Local<Object> ApiCallOptimizationChecker::holder; | 22058 Local<Object> ApiCallOptimizationChecker::holder; |
22046 Local<Object> ApiCallOptimizationChecker::callee; | 22059 Local<Object> ApiCallOptimizationChecker::callee; |
22047 int ApiCallOptimizationChecker::count = 0; | 22060 int ApiCallOptimizationChecker::count = 0; |
22048 | 22061 |
22049 | 22062 |
22050 TEST(TestFunctionCallOptimization) { | 22063 TEST(TestFunctionCallOptimization) { |
22051 i::FLAG_allow_natives_syntax = true; | 22064 i::FLAG_allow_natives_syntax = true; |
22052 ApiCallOptimizationChecker checker; | 22065 ApiCallOptimizationChecker checker; |
22053 checker.Run(true, true); | 22066 checker.Run(true, true); |
22054 checker.Run(false, true); | 22067 checker.Run(false, true); |
22055 checker.Run(true, false); | 22068 checker.Run(true, false); |
22056 checker.Run(false, false); | 22069 checker.Run(false, false); |
22057 } | 22070 } |
OLD | NEW |