| 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 21915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21926 static void OptimizationCallback( | 21926 static void OptimizationCallback( |
| 21927 const v8::FunctionCallbackInfo<v8::Value>& info) { | 21927 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 21928 CHECK(callee == info.Callee()); | 21928 CHECK(callee == info.Callee()); |
| 21929 CHECK(data == info.Data()); | 21929 CHECK(data == info.Data()); |
| 21930 CHECK(receiver == info.This()); | 21930 CHECK(receiver == info.This()); |
| 21931 if (info.Length() == 1) { | 21931 if (info.Length() == 1) { |
| 21932 CHECK_EQ(v8_num(1), info[0]); | 21932 CHECK_EQ(v8_num(1), info[0]); |
| 21933 } | 21933 } |
| 21934 CHECK(holder == info.Holder()); | 21934 CHECK(holder == info.Holder()); |
| 21935 count++; | 21935 count++; |
| 21936 info.GetReturnValue().Set(v8_str("returned")); |
| 21936 } | 21937 } |
| 21937 | 21938 |
| 21938 // TODO(dcarney): move this to v8.h | 21939 // TODO(dcarney): move this to v8.h |
| 21939 static void SetAccessorProperty(Local<Object> object, | 21940 static void SetAccessorProperty(Local<Object> object, |
| 21940 Local<String> name, | 21941 Local<String> name, |
| 21941 Local<Function> getter, | 21942 Local<Function> getter, |
| 21942 Local<Function> setter = Local<Function>()) { | 21943 Local<Function> setter = Local<Function>()) { |
| 21943 i::Isolate* isolate = CcTest::i_isolate(); | 21944 i::Isolate* isolate = CcTest::i_isolate(); |
| 21944 v8::AccessControl settings = v8::DEFAULT; | 21945 v8::AccessControl settings = v8::DEFAULT; |
| 21945 v8::PropertyAttribute attribute = v8::None; | 21946 v8::PropertyAttribute attribute = v8::None; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22048 } | 22049 } |
| 22049 // With no signature, the holder is not set. | 22050 // With no signature, the holder is not set. |
| 22050 if (signature_type == kNoSignature) holder = receiver; | 22051 if (signature_type == kNoSignature) holder = receiver; |
| 22051 // build wrap_function | 22052 // build wrap_function |
| 22052 i::ScopedVector<char> wrap_function(200); | 22053 i::ScopedVector<char> wrap_function(200); |
| 22053 if (global) { | 22054 if (global) { |
| 22054 i::OS::SNPrintF( | 22055 i::OS::SNPrintF( |
| 22055 wrap_function, | 22056 wrap_function, |
| 22056 "function wrap_f_%d() { var f = g_f; return f(); }\n" | 22057 "function wrap_f_%d() { var f = g_f; return f(); }\n" |
| 22057 "function wrap_get_%d() { return this.g_acc; }\n" | 22058 "function wrap_get_%d() { return this.g_acc; }\n" |
| 22058 "function wrap_set_%d() { this.g_acc = 1; }\n", | 22059 "function wrap_set_%d() { return this.g_acc = 1; }\n", |
| 22059 key, key, key); | 22060 key, key, key); |
| 22060 } else { | 22061 } else { |
| 22061 i::OS::SNPrintF( | 22062 i::OS::SNPrintF( |
| 22062 wrap_function, | 22063 wrap_function, |
| 22063 "function wrap_f_%d() { return receiver_subclass.f(); }\n" | 22064 "function wrap_f_%d() { return receiver_subclass.f(); }\n" |
| 22064 "function wrap_get_%d() { return receiver_subclass.acc; }\n" | 22065 "function wrap_get_%d() { return receiver_subclass.acc; }\n" |
| 22065 "function wrap_set_%d() { receiver_subclass.acc = 1; }\n", | 22066 "function wrap_set_%d() { return receiver_subclass.acc = 1; }\n", |
| 22066 key, key, key); | 22067 key, key, key); |
| 22067 } | 22068 } |
| 22068 // build source string | 22069 // build source string |
| 22069 i::ScopedVector<char> source(500); | 22070 i::ScopedVector<char> source(1000); |
| 22070 i::OS::SNPrintF( | 22071 i::OS::SNPrintF( |
| 22071 source, | 22072 source, |
| 22072 "%s\n" // wrap functions | 22073 "%s\n" // wrap functions |
| 22073 "function wrap_f() { wrap_f_%d(); }\n" | 22074 "function wrap_f() { return wrap_f_%d(); }\n" |
| 22074 "function wrap_get() { wrap_get_%d(); }\n" | 22075 "function wrap_get() { return wrap_get_%d(); }\n" |
| 22075 "function wrap_set() { wrap_set_%d(); }\n" | 22076 "function wrap_set() { return wrap_set_%d(); }\n" |
| 22077 "check = function(returned) {\n" |
| 22078 " if (returned !== 'returned') { throw returned; }\n" |
| 22079 "}\n" |
| 22076 "\n" | 22080 "\n" |
| 22077 "wrap_f();\n" | 22081 "check(wrap_f());\n" |
| 22078 "wrap_f();\n" | 22082 "check(wrap_f());\n" |
| 22079 "%%OptimizeFunctionOnNextCall(wrap_f_%d);\n" | 22083 "%%OptimizeFunctionOnNextCall(wrap_f_%d);\n" |
| 22080 "wrap_f();\n" | 22084 "check(wrap_f());\n" |
| 22081 "\n" | 22085 "\n" |
| 22082 "wrap_get();\n" | 22086 "check(wrap_get());\n" |
| 22083 "wrap_get();\n" | 22087 "check(wrap_get());\n" |
| 22084 "%%OptimizeFunctionOnNextCall(wrap_get_%d);\n" | 22088 "%%OptimizeFunctionOnNextCall(wrap_get_%d);\n" |
| 22085 "wrap_get();\n" | 22089 "check(wrap_get());\n" |
| 22086 "\n" | 22090 "\n" |
| 22087 "wrap_set();\n" | 22091 "check = function(returned) {\n" |
| 22088 "wrap_set();\n" | 22092 " if (returned !== 1) { throw returned; }\n" |
| 22093 "}\n" |
| 22094 "check(wrap_set());\n" |
| 22095 "check(wrap_set());\n" |
| 22089 "%%OptimizeFunctionOnNextCall(wrap_set_%d);\n" | 22096 "%%OptimizeFunctionOnNextCall(wrap_set_%d);\n" |
| 22090 "wrap_set();\n", | 22097 "check(wrap_set());\n", |
| 22091 wrap_function.start(), key, key, key, key, key, key); | 22098 wrap_function.start(), key, key, key, key, key, key); |
| 22092 v8::TryCatch try_catch; | 22099 v8::TryCatch try_catch; |
| 22093 CompileRun(source.start()); | 22100 CompileRun(source.start()); |
| 22094 ASSERT(!try_catch.HasCaught()); | 22101 ASSERT(!try_catch.HasCaught()); |
| 22095 CHECK_EQ(9, count); | 22102 CHECK_EQ(9, count); |
| 22096 } | 22103 } |
| 22097 }; | 22104 }; |
| 22098 | 22105 |
| 22099 | 22106 |
| 22100 Local<Object> ApiCallOptimizationChecker::data; | 22107 Local<Object> ApiCallOptimizationChecker::data; |
| 22101 Local<Object> ApiCallOptimizationChecker::receiver; | 22108 Local<Object> ApiCallOptimizationChecker::receiver; |
| 22102 Local<Object> ApiCallOptimizationChecker::holder; | 22109 Local<Object> ApiCallOptimizationChecker::holder; |
| 22103 Local<Object> ApiCallOptimizationChecker::callee; | 22110 Local<Object> ApiCallOptimizationChecker::callee; |
| 22104 int ApiCallOptimizationChecker::count = 0; | 22111 int ApiCallOptimizationChecker::count = 0; |
| 22105 | 22112 |
| 22106 | 22113 |
| 22107 TEST(TestFunctionCallOptimization) { | 22114 TEST(TestFunctionCallOptimization) { |
| 22108 i::FLAG_allow_natives_syntax = true; | 22115 i::FLAG_allow_natives_syntax = true; |
| 22109 ApiCallOptimizationChecker checker; | 22116 ApiCallOptimizationChecker checker; |
| 22110 checker.RunAll(); | 22117 checker.RunAll(); |
| 22111 } | 22118 } |
| OLD | NEW |