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

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

Issue 146023004: inline api getters in crankshaft (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 6 years, 10 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/hydrogen.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 21898 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 CHECK(holder == info.Holder()); 21915 CHECK(holder == info.Holder());
21916 count++; 21916 count++;
21917 } 21917 }
21918 21918
21919 // TODO(dcarney): move this to v8.h
21920 static void SetAccessorProperty(Local<Object> object,
21921 Local<String> name,
21922 Local<Function> getter,
21923 Local<Function> setter = Local<Function>()) {
21924 i::Isolate* isolate = CcTest::i_isolate();
21925 v8::AccessControl settings = v8::DEFAULT;
21926 v8::PropertyAttribute attribute = v8::None;
21927 i::Handle<i::Object> getter_i = v8::Utils::OpenHandle(*getter);
21928 i::Handle<i::Object> setter_i = v8::Utils::OpenHandle(*setter, true);
21929 if (setter_i.is_null()) setter_i = isolate->factory()->null_value();
21930 i::JSObject::DefineAccessor(v8::Utils::OpenHandle(*object),
21931 v8::Utils::OpenHandle(*name),
21932 getter_i,
21933 setter_i,
21934 static_cast<PropertyAttributes>(attribute),
21935 settings);
21936 }
21937
21919 public: 21938 public:
21920 void Run(bool use_signature, bool global) { 21939 void Run(bool use_signature, bool global) {
21921 v8::Isolate* isolate = CcTest::isolate(); 21940 v8::Isolate* isolate = CcTest::isolate();
21922 v8::HandleScope scope(isolate); 21941 v8::HandleScope scope(isolate);
21923 // Build a template for signature checks. 21942 // Build a template for signature checks.
21924 Local<v8::ObjectTemplate> signature_template; 21943 Local<v8::ObjectTemplate> signature_template;
21925 Local<v8::Signature> signature; 21944 Local<v8::Signature> signature;
21926 { 21945 {
21927 Local<v8::FunctionTemplate> parent_template = 21946 Local<v8::FunctionTemplate> parent_template =
21928 FunctionTemplate::New(isolate); 21947 FunctionTemplate::New(isolate);
(...skipping 16 matching lines...) Expand all
21945 // Get the holder objects. 21964 // Get the holder objects.
21946 Local<Object> inner_global = 21965 Local<Object> inner_global =
21947 Local<Object>::Cast(context->Global()->GetPrototype()); 21966 Local<Object>::Cast(context->Global()->GetPrototype());
21948 Local<Object> function_holder = 21967 Local<Object> function_holder =
21949 Local<Object>::Cast(function_receiver->GetPrototype()); 21968 Local<Object>::Cast(function_receiver->GetPrototype());
21950 // Install function on hidden prototype object. 21969 // Install function on hidden prototype object.
21951 data = Object::New(isolate); 21970 data = Object::New(isolate);
21952 Local<FunctionTemplate> function_template = FunctionTemplate::New( 21971 Local<FunctionTemplate> function_template = FunctionTemplate::New(
21953 isolate, OptimizationCallback, data, signature); 21972 isolate, OptimizationCallback, data, signature);
21954 Local<Function> function = function_template->GetFunction(); 21973 Local<Function> function = function_template->GetFunction();
21955 Local<Object>::Cast( 21974 Local<Object> global_holder = Local<Object>::Cast(
21956 inner_global->GetPrototype())->Set(v8_str("global_f"), function); 21975 inner_global->GetPrototype());
21976 global_holder->Set(v8_str("g_f"), function);
21977 SetAccessorProperty(global_holder, v8_str("g_p1"), function);
21957 function_holder->Set(v8_str("f"), function); 21978 function_holder->Set(v8_str("f"), function);
21979 SetAccessorProperty(function_holder, v8_str("p1"), function);
21958 // Initialize expected values. 21980 // Initialize expected values.
21959 callee = function; 21981 callee = function;
21960 count = 0; 21982 count = 0;
21961 if (global) { 21983 if (global) {
21962 receiver = context->Global(); 21984 receiver = context->Global();
21963 holder = inner_global; 21985 holder = inner_global;
21964 } else { 21986 } else {
21965 holder = function_receiver; 21987 holder = function_receiver;
21966 // If not using a signature, add something else to the prototype chain 21988 // If not using a signature, add something else to the prototype chain
21967 // to test the case that holder != receiver 21989 // to test the case that holder != receiver
21968 if (!use_signature) { 21990 if (!use_signature) {
21969 receiver = Local<Object>::Cast(CompileRun( 21991 receiver = Local<Object>::Cast(CompileRun(
21970 "var receiver_subclass = {};\n" 21992 "var receiver_subclass = {};\n"
21971 "receiver_subclass.__proto__ = function_receiver;\n" 21993 "receiver_subclass.__proto__ = function_receiver;\n"
21972 "receiver_subclass")); 21994 "receiver_subclass"));
21973 } else { 21995 } else {
21974 receiver = Local<Object>::Cast(CompileRun( 21996 receiver = Local<Object>::Cast(CompileRun(
21975 "var receiver_subclass = function_receiver;\n" 21997 "var receiver_subclass = function_receiver;\n"
21976 "receiver_subclass")); 21998 "receiver_subclass"));
21977 } 21999 }
21978 } 22000 }
21979 // With no signature, the holder is not set. 22001 // With no signature, the holder is not set.
21980 if (!use_signature) holder = receiver; 22002 if (!use_signature) holder = receiver;
21981 // build wrap_function 22003 // build wrap_function
21982 int key = (use_signature ? 1 : 0) + 2 * (global ? 1 : 0); 22004 int key = (use_signature ? 1 : 0) + 2 * (global ? 1 : 0);
21983 i::ScopedVector<char> wrap_function(100); 22005 i::ScopedVector<char> wrap_function(200);
21984 if (global) { 22006 if (global) {
21985 i::OS::SNPrintF( 22007 i::OS::SNPrintF(
21986 wrap_function, 22008 wrap_function,
21987 "function wrap_%d() { var f = global_f; return f(); }\n", 22009 "function wrap_f_%d() { var f = g_f; return f(); }\n"
21988 key); 22010 "function wrap_p1_%d() { return this.g_p1; }\n",
22011 key, key);
21989 } else { 22012 } else {
21990 i::OS::SNPrintF( 22013 i::OS::SNPrintF(
21991 wrap_function, 22014 wrap_function,
21992 "function wrap_%d() { return receiver_subclass.f(); }\n", 22015 "function wrap_f_%d() { return receiver_subclass.f(); }\n"
21993 key); 22016 "function wrap_p1_%d() { return receiver_subclass.p1; }\n",
22017 key, key);
21994 } 22018 }
21995 // build source string 22019 // build source string
21996 i::ScopedVector<char> source(500); 22020 i::ScopedVector<char> source(500);
21997 i::OS::SNPrintF( 22021 i::OS::SNPrintF(
21998 source, 22022 source,
21999 "%s\n" // wrap_function 22023 "%s\n" // wrap functions
22000 "function wrap2() { wrap_%d(); }\n" 22024 "function wrap_f() { wrap_f_%d(); }\n"
22001 "wrap2();\n" 22025 "function wrap_p1() { wrap_p1_%d(); }\n"
22002 "wrap2();\n" 22026 "wrap_f();\n"
22003 "%%OptimizeFunctionOnNextCall(wrap_%d);\n" 22027 "wrap_f();\n"
22004 "wrap2();\n", 22028 "%%OptimizeFunctionOnNextCall(wrap_f_%d);\n"
22005 wrap_function.start(), key, key); 22029 "wrap_f();\n"
22030 "wrap_p1();\n"
22031 "wrap_p1();\n"
22032 "%%OptimizeFunctionOnNextCall(wrap_p1_%d);\n"
22033 "wrap_p1();\n",
22034 wrap_function.start(), key, key, key, key);
22006 v8::TryCatch try_catch; 22035 v8::TryCatch try_catch;
22007 CompileRun(source.start()); 22036 CompileRun(source.start());
22008 ASSERT(!try_catch.HasCaught()); 22037 ASSERT(!try_catch.HasCaught());
22009 CHECK_EQ(3, count); 22038 CHECK_EQ(6, count);
22010 } 22039 }
22011 }; 22040 };
22012 22041
22013 22042
22014 Local<Object> ApiCallOptimizationChecker::data; 22043 Local<Object> ApiCallOptimizationChecker::data;
22015 Local<Object> ApiCallOptimizationChecker::receiver; 22044 Local<Object> ApiCallOptimizationChecker::receiver;
22016 Local<Object> ApiCallOptimizationChecker::holder; 22045 Local<Object> ApiCallOptimizationChecker::holder;
22017 Local<Object> ApiCallOptimizationChecker::callee; 22046 Local<Object> ApiCallOptimizationChecker::callee;
22018 int ApiCallOptimizationChecker::count = 0; 22047 int ApiCallOptimizationChecker::count = 0;
22019 22048
22020 22049
22021 TEST(TestFunctionCallOptimization) { 22050 TEST(TestFunctionCallOptimization) {
22022 i::FLAG_allow_natives_syntax = true; 22051 i::FLAG_allow_natives_syntax = true;
22023 ApiCallOptimizationChecker checker; 22052 ApiCallOptimizationChecker checker;
22024 checker.Run(true, true); 22053 checker.Run(true, true);
22025 checker.Run(false, true); 22054 checker.Run(false, true);
22026 checker.Run(true, false); 22055 checker.Run(true, false);
22027 checker.Run(false, false); 22056 checker.Run(false, false);
22028 } 22057 }
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698