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 22130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22141 CHECK(data == info.Data()); | 22141 CHECK(data == info.Data()); |
22142 CHECK(receiver == info.This()); | 22142 CHECK(receiver == info.This()); |
22143 if (info.Length() == 1) { | 22143 if (info.Length() == 1) { |
22144 CHECK_EQ(v8_num(1), info[0]); | 22144 CHECK_EQ(v8_num(1), info[0]); |
22145 } | 22145 } |
22146 CHECK(holder == info.Holder()); | 22146 CHECK(holder == info.Holder()); |
22147 count++; | 22147 count++; |
22148 info.GetReturnValue().Set(v8_str("returned")); | 22148 info.GetReturnValue().Set(v8_str("returned")); |
22149 } | 22149 } |
22150 | 22150 |
22151 public: | 22151 public: |
22152 enum SignatureType { | 22152 enum SignatureType { |
22153 kNoSignature, | 22153 kNoSignature, |
22154 kSignatureOnReceiver, | 22154 kSignatureOnReceiver, |
22155 kSignatureOnPrototype | 22155 kSignatureOnPrototype |
22156 }; | 22156 }; |
22157 | 22157 |
22158 void RunAll() { | 22158 void RunAll() { |
22159 SignatureType signature_types[] = | 22159 SignatureType signature_types[] = |
22160 {kNoSignature, kSignatureOnReceiver, kSignatureOnPrototype}; | 22160 {kNoSignature, kSignatureOnReceiver, kSignatureOnPrototype}; |
22161 for (unsigned i = 0; i < ARRAY_SIZE(signature_types); i++) { | 22161 for (unsigned i = 0; i < ARRAY_SIZE(signature_types); i++) { |
22162 SignatureType signature_type = signature_types[i]; | 22162 SignatureType signature_type = signature_types[i]; |
22163 for (int j = 0; j < 2; j++) { | 22163 for (int j = 0; j < 2; j++) { |
22164 bool global = j == 0; | 22164 bool global = j == 0; |
22165 int key = signature_type + | 22165 int key = signature_type + |
22166 ARRAY_SIZE(signature_types) * (global ? 1 : 0); | 22166 ARRAY_SIZE(signature_types) * (global ? 1 : 0); |
22167 Run(signature_type, global, key); | 22167 Run(signature_type, global, key); |
22168 } | |
22169 } | 22168 } |
22170 } | 22169 } |
| 22170 } |
22171 | 22171 |
22172 void Run(SignatureType signature_type, bool global, int key) { | 22172 void Run(SignatureType signature_type, bool global, int key) { |
22173 v8::Isolate* isolate = CcTest::isolate(); | 22173 v8::Isolate* isolate = CcTest::isolate(); |
22174 v8::HandleScope scope(isolate); | 22174 v8::HandleScope scope(isolate); |
22175 // Build a template for signature checks. | 22175 // Build a template for signature checks. |
22176 Local<v8::ObjectTemplate> signature_template; | 22176 Local<v8::ObjectTemplate> signature_template; |
22177 Local<v8::Signature> signature; | 22177 Local<v8::Signature> signature; |
22178 { | 22178 { |
22179 Local<v8::FunctionTemplate> parent_template = | 22179 Local<v8::FunctionTemplate> parent_template = |
22180 FunctionTemplate::New(isolate); | 22180 FunctionTemplate::New(isolate); |
22181 parent_template->SetHiddenPrototype(true); | 22181 parent_template->SetHiddenPrototype(true); |
22182 Local<v8::FunctionTemplate> function_template | 22182 Local<v8::FunctionTemplate> function_template |
22183 = FunctionTemplate::New(isolate); | 22183 = FunctionTemplate::New(isolate); |
22184 function_template->Inherit(parent_template); | 22184 function_template->Inherit(parent_template); |
22185 switch (signature_type) { | 22185 switch (signature_type) { |
22186 case kNoSignature: | 22186 case kNoSignature: |
22187 break; | 22187 break; |
22188 case kSignatureOnReceiver: | 22188 case kSignatureOnReceiver: |
22189 signature = v8::Signature::New(isolate, function_template); | 22189 signature = v8::Signature::New(isolate, function_template); |
22190 break; | 22190 break; |
22191 case kSignatureOnPrototype: | 22191 case kSignatureOnPrototype: |
22192 signature = v8::Signature::New(isolate, parent_template); | 22192 signature = v8::Signature::New(isolate, parent_template); |
22193 break; | 22193 break; |
22194 } | |
22195 signature_template = function_template->InstanceTemplate(); | |
22196 } | 22194 } |
22197 // Global object must pass checks. | 22195 signature_template = function_template->InstanceTemplate(); |
22198 Local<v8::Context> context = | 22196 } |
22199 v8::Context::New(isolate, NULL, signature_template); | 22197 // Global object must pass checks. |
22200 v8::Context::Scope context_scope(context); | 22198 Local<v8::Context> context = |
22201 // Install regular object that can pass signature checks. | 22199 v8::Context::New(isolate, NULL, signature_template); |
22202 Local<Object> function_receiver = signature_template->NewInstance(); | 22200 v8::Context::Scope context_scope(context); |
22203 context->Global()->Set(v8_str("function_receiver"), function_receiver); | 22201 // Install regular object that can pass signature checks. |
22204 // Get the holder objects. | 22202 Local<Object> function_receiver = signature_template->NewInstance(); |
22205 Local<Object> inner_global = | 22203 context->Global()->Set(v8_str("function_receiver"), function_receiver); |
22206 Local<Object>::Cast(context->Global()->GetPrototype()); | 22204 // Get the holder objects. |
22207 // Install functions on hidden prototype object if there is one. | 22205 Local<Object> inner_global = |
22208 data = Object::New(isolate); | 22206 Local<Object>::Cast(context->Global()->GetPrototype()); |
22209 Local<FunctionTemplate> function_template = FunctionTemplate::New( | 22207 // Install functions on hidden prototype object if there is one. |
22210 isolate, OptimizationCallback, data, signature); | 22208 data = Object::New(isolate); |
22211 Local<Function> function = function_template->GetFunction(); | 22209 Local<FunctionTemplate> function_template = FunctionTemplate::New( |
22212 Local<Object> global_holder = inner_global; | 22210 isolate, OptimizationCallback, data, signature); |
22213 Local<Object> function_holder = function_receiver; | 22211 Local<Function> function = function_template->GetFunction(); |
22214 if (signature_type == kSignatureOnPrototype) { | 22212 Local<Object> global_holder = inner_global; |
22215 function_holder = Local<Object>::Cast(function_holder->GetPrototype()); | 22213 Local<Object> function_holder = function_receiver; |
22216 global_holder = Local<Object>::Cast(global_holder->GetPrototype()); | 22214 if (signature_type == kSignatureOnPrototype) { |
| 22215 function_holder = Local<Object>::Cast(function_holder->GetPrototype()); |
| 22216 global_holder = Local<Object>::Cast(global_holder->GetPrototype()); |
| 22217 } |
| 22218 global_holder->Set(v8_str("g_f"), function); |
| 22219 global_holder->SetAccessorProperty(v8_str("g_acc"), function, function); |
| 22220 function_holder->Set(v8_str("f"), function); |
| 22221 function_holder->SetAccessorProperty(v8_str("acc"), function, function); |
| 22222 // Initialize expected values. |
| 22223 callee = function; |
| 22224 count = 0; |
| 22225 if (global) { |
| 22226 receiver = context->Global(); |
| 22227 holder = inner_global; |
| 22228 } else { |
| 22229 holder = function_receiver; |
| 22230 // If not using a signature, add something else to the prototype chain |
| 22231 // to test the case that holder != receiver |
| 22232 if (signature_type == kNoSignature) { |
| 22233 receiver = Local<Object>::Cast(CompileRun( |
| 22234 "var receiver_subclass = {};\n" |
| 22235 "receiver_subclass.__proto__ = function_receiver;\n" |
| 22236 "receiver_subclass")); |
| 22237 } else { |
| 22238 receiver = Local<Object>::Cast(CompileRun( |
| 22239 "var receiver_subclass = function_receiver;\n" |
| 22240 "receiver_subclass")); |
22217 } | 22241 } |
22218 global_holder->Set(v8_str("g_f"), function); | 22242 } |
22219 global_holder->SetAccessorProperty(v8_str("g_acc"), function, function); | 22243 // With no signature, the holder is not set. |
22220 function_holder->Set(v8_str("f"), function); | 22244 if (signature_type == kNoSignature) holder = receiver; |
22221 function_holder->SetAccessorProperty(v8_str("acc"), function, function); | 22245 // build wrap_function |
22222 // Initialize expected values. | 22246 i::ScopedVector<char> wrap_function(200); |
22223 callee = function; | 22247 if (global) { |
22224 count = 0; | |
22225 if (global) { | |
22226 receiver = context->Global(); | |
22227 holder = inner_global; | |
22228 } else { | |
22229 holder = function_receiver; | |
22230 // If not using a signature, add something else to the prototype chain | |
22231 // to test the case that holder != receiver | |
22232 if (signature_type == kNoSignature) { | |
22233 receiver = Local<Object>::Cast(CompileRun( | |
22234 "var receiver_subclass = {};\n" | |
22235 "receiver_subclass.__proto__ = function_receiver;\n" | |
22236 "receiver_subclass")); | |
22237 } else { | |
22238 receiver = Local<Object>::Cast(CompileRun( | |
22239 "var receiver_subclass = function_receiver;\n" | |
22240 "receiver_subclass")); | |
22241 } | |
22242 } | |
22243 // With no signature, the holder is not set. | |
22244 if (signature_type == kNoSignature) holder = receiver; | |
22245 // build wrap_function | |
22246 i::ScopedVector<char> wrap_function(200); | |
22247 if (global) { | |
22248 i::OS::SNPrintF( | |
22249 wrap_function, | |
22250 "function wrap_f_%d() { var f = g_f; return f(); }\n" | |
22251 "function wrap_get_%d() { return this.g_acc; }\n" | |
22252 "function wrap_set_%d() { return this.g_acc = 1; }\n", | |
22253 key, key, key); | |
22254 } else { | |
22255 i::OS::SNPrintF( | |
22256 wrap_function, | |
22257 "function wrap_f_%d() { return receiver_subclass.f(); }\n" | |
22258 "function wrap_get_%d() { return receiver_subclass.acc; }\n" | |
22259 "function wrap_set_%d() { return receiver_subclass.acc = 1; }\n", | |
22260 key, key, key); | |
22261 } | |
22262 // build source string | |
22263 i::ScopedVector<char> source(1000); | |
22264 i::OS::SNPrintF( | 22248 i::OS::SNPrintF( |
22265 source, | 22249 wrap_function, |
22266 "%s\n" // wrap functions | 22250 "function wrap_f_%d() { var f = g_f; return f(); }\n" |
22267 "function wrap_f() { return wrap_f_%d(); }\n" | 22251 "function wrap_get_%d() { return this.g_acc; }\n" |
22268 "function wrap_get() { return wrap_get_%d(); }\n" | 22252 "function wrap_set_%d() { return this.g_acc = 1; }\n", |
22269 "function wrap_set() { return wrap_set_%d(); }\n" | 22253 key, key, key); |
22270 "check = function(returned) {\n" | 22254 } else { |
22271 " if (returned !== 'returned') { throw returned; }\n" | 22255 i::OS::SNPrintF( |
22272 "}\n" | 22256 wrap_function, |
22273 "\n" | 22257 "function wrap_f_%d() { return receiver_subclass.f(); }\n" |
22274 "check(wrap_f());\n" | 22258 "function wrap_get_%d() { return receiver_subclass.acc; }\n" |
22275 "check(wrap_f());\n" | 22259 "function wrap_set_%d() { return receiver_subclass.acc = 1; }\n", |
22276 "%%OptimizeFunctionOnNextCall(wrap_f_%d);\n" | 22260 key, key, key); |
22277 "check(wrap_f());\n" | |
22278 "\n" | |
22279 "check(wrap_get());\n" | |
22280 "check(wrap_get());\n" | |
22281 "%%OptimizeFunctionOnNextCall(wrap_get_%d);\n" | |
22282 "check(wrap_get());\n" | |
22283 "\n" | |
22284 "check = function(returned) {\n" | |
22285 " if (returned !== 1) { throw returned; }\n" | |
22286 "}\n" | |
22287 "check(wrap_set());\n" | |
22288 "check(wrap_set());\n" | |
22289 "%%OptimizeFunctionOnNextCall(wrap_set_%d);\n" | |
22290 "check(wrap_set());\n", | |
22291 wrap_function.start(), key, key, key, key, key, key); | |
22292 v8::TryCatch try_catch; | |
22293 CompileRun(source.start()); | |
22294 ASSERT(!try_catch.HasCaught()); | |
22295 CHECK_EQ(9, count); | |
22296 } | 22261 } |
| 22262 // build source string |
| 22263 i::ScopedVector<char> source(1000); |
| 22264 i::OS::SNPrintF( |
| 22265 source, |
| 22266 "%s\n" // wrap functions |
| 22267 "function wrap_f() { return wrap_f_%d(); }\n" |
| 22268 "function wrap_get() { return wrap_get_%d(); }\n" |
| 22269 "function wrap_set() { return wrap_set_%d(); }\n" |
| 22270 "check = function(returned) {\n" |
| 22271 " if (returned !== 'returned') { throw returned; }\n" |
| 22272 "}\n" |
| 22273 "\n" |
| 22274 "check(wrap_f());\n" |
| 22275 "check(wrap_f());\n" |
| 22276 "%%OptimizeFunctionOnNextCall(wrap_f_%d);\n" |
| 22277 "check(wrap_f());\n" |
| 22278 "\n" |
| 22279 "check(wrap_get());\n" |
| 22280 "check(wrap_get());\n" |
| 22281 "%%OptimizeFunctionOnNextCall(wrap_get_%d);\n" |
| 22282 "check(wrap_get());\n" |
| 22283 "\n" |
| 22284 "check = function(returned) {\n" |
| 22285 " if (returned !== 1) { throw returned; }\n" |
| 22286 "}\n" |
| 22287 "check(wrap_set());\n" |
| 22288 "check(wrap_set());\n" |
| 22289 "%%OptimizeFunctionOnNextCall(wrap_set_%d);\n" |
| 22290 "check(wrap_set());\n", |
| 22291 wrap_function.start(), key, key, key, key, key, key); |
| 22292 v8::TryCatch try_catch; |
| 22293 CompileRun(source.start()); |
| 22294 ASSERT(!try_catch.HasCaught()); |
| 22295 CHECK_EQ(9, count); |
| 22296 } |
22297 }; | 22297 }; |
22298 | 22298 |
22299 | 22299 |
22300 Local<Object> ApiCallOptimizationChecker::data; | 22300 Local<Object> ApiCallOptimizationChecker::data; |
22301 Local<Object> ApiCallOptimizationChecker::receiver; | 22301 Local<Object> ApiCallOptimizationChecker::receiver; |
22302 Local<Object> ApiCallOptimizationChecker::holder; | 22302 Local<Object> ApiCallOptimizationChecker::holder; |
22303 Local<Object> ApiCallOptimizationChecker::callee; | 22303 Local<Object> ApiCallOptimizationChecker::callee; |
22304 int ApiCallOptimizationChecker::count = 0; | 22304 int ApiCallOptimizationChecker::count = 0; |
22305 | 22305 |
22306 | 22306 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22514 v8::internal::FLAG_stack_size = 150; | 22514 v8::internal::FLAG_stack_size = 150; |
22515 LocalContext current; | 22515 LocalContext current; |
22516 v8::Isolate* isolate = current->GetIsolate(); | 22516 v8::Isolate* isolate = current->GetIsolate(); |
22517 v8::HandleScope scope(isolate); | 22517 v8::HandleScope scope(isolate); |
22518 V8::SetCaptureStackTraceForUncaughtExceptions( | 22518 V8::SetCaptureStackTraceForUncaughtExceptions( |
22519 true, 10, v8::StackTrace::kDetailed); | 22519 true, 10, v8::StackTrace::kDetailed); |
22520 v8::TryCatch try_catch; | 22520 v8::TryCatch try_catch; |
22521 CompileRun("(function f(x) { f(x+1); })(0)"); | 22521 CompileRun("(function f(x) { f(x+1); })(0)"); |
22522 CHECK(try_catch.HasCaught()); | 22522 CHECK(try_catch.HasCaught()); |
22523 } | 22523 } |
OLD | NEW |