OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ | 5 #ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ |
6 #define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ | 6 #define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 #include "test/cctest/cctest.h" | 9 #include "test/cctest/cctest.h" |
10 | 10 |
11 #include "src/compiler.h" | 11 #include "src/compiler.h" |
12 #include "src/compiler/pipeline.h" | 12 #include "src/compiler/pipeline.h" |
13 #include "src/execution.h" | 13 #include "src/execution.h" |
14 #include "src/full-codegen.h" | 14 #include "src/full-codegen.h" |
15 #include "src/handles.h" | 15 #include "src/handles.h" |
16 #include "src/objects-inl.h" | 16 #include "src/objects-inl.h" |
17 #include "src/parser.h" | 17 #include "src/parser.h" |
18 #include "src/rewriter.h" | 18 #include "src/rewriter.h" |
19 #include "src/scopes.h" | 19 #include "src/scopes.h" |
20 | 20 |
21 #define USE_CRANKSHAFT 0 | 21 #define USE_CRANKSHAFT 0 |
22 | 22 |
23 namespace v8 { | 23 namespace v8 { |
24 namespace internal { | 24 namespace internal { |
25 namespace compiler { | 25 namespace compiler { |
26 | 26 |
| 27 static void AssertStackDepth(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 28 v8::HandleScope scope(args.GetIsolate()); |
| 29 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
| 30 args.GetIsolate(), 10, v8::StackTrace::kDetailed); |
| 31 CHECK_EQ(args[0]->ToInt32()->Value(), stackTrace->GetFrameCount()); |
| 32 } |
| 33 |
27 class FunctionTester : public InitializedHandleScope { | 34 class FunctionTester : public InitializedHandleScope { |
28 public: | 35 public: |
29 explicit FunctionTester(const char* source) | 36 explicit FunctionTester(const char* source) |
30 : isolate(main_isolate()), | 37 : isolate(main_isolate()), context(0, GetObjectTemplate()) { |
31 function((FLAG_allow_natives_syntax = true, NewFunction(source))) { | 38 FLAG_allow_natives_syntax = true; |
| 39 function = NewFunction(source); |
32 Compile(function); | 40 Compile(function); |
33 } | 41 } |
34 | 42 |
35 Isolate* isolate; | 43 Isolate* isolate; |
36 Handle<JSFunction> function; | 44 Handle<JSFunction> function; |
| 45 LocalContext context; |
37 | 46 |
38 Handle<JSFunction> Compile(Handle<JSFunction> function) { | 47 Handle<JSFunction> Compile(Handle<JSFunction> function) { |
39 #if V8_TURBOFAN_TARGET | 48 #if V8_TURBOFAN_TARGET |
40 CompilationInfoWithZone info(function); | 49 CompilationInfoWithZone info(function); |
41 | 50 |
42 CHECK(Parser::Parse(&info)); | 51 CHECK(Parser::Parse(&info)); |
43 StrictMode strict_mode = info.function()->strict_mode(); | 52 StrictMode strict_mode = info.function()->strict_mode(); |
44 info.SetStrictMode(strict_mode); | 53 info.SetStrictMode(strict_mode); |
45 info.SetOptimizing(BailoutId::None(), Handle<Code>(function->code())); | 54 info.SetOptimizing(BailoutId::None(), Handle<Code>(function->code())); |
46 CHECK(Rewriter::Rewrite(&info)); | 55 CHECK(Rewriter::Rewrite(&info)); |
(...skipping 16 matching lines...) Expand all Loading... |
63 if (FLAG_print_opt_code) { | 72 if (FLAG_print_opt_code) { |
64 CodeTracer::Scope tracing_scope(isolate->GetCodeTracer()); | 73 CodeTracer::Scope tracing_scope(isolate->GetCodeTracer()); |
65 code->Disassemble("test code", tracing_scope.file()); | 74 code->Disassemble("test code", tracing_scope.file()); |
66 } | 75 } |
67 #endif | 76 #endif |
68 function->ReplaceCode(*code); | 77 function->ReplaceCode(*code); |
69 #endif | 78 #endif |
70 return function; | 79 return function; |
71 } | 80 } |
72 | 81 |
| 82 Local<ObjectTemplate> GetObjectTemplate() { |
| 83 Local<ObjectTemplate> templ = ObjectTemplate::New(CcTest::isolate()); |
| 84 templ->Set(v8_str("AssertStackDepth"), |
| 85 v8::FunctionTemplate::New(CcTest::isolate(), AssertStackDepth)); |
| 86 return templ; |
| 87 } |
| 88 |
73 static void EnsureDeoptimizationSupport(CompilationInfo* info) { | 89 static void EnsureDeoptimizationSupport(CompilationInfo* info) { |
74 bool should_recompile = !info->shared_info()->has_deoptimization_support(); | 90 bool should_recompile = !info->shared_info()->has_deoptimization_support(); |
75 if (should_recompile) { | 91 if (should_recompile) { |
76 CompilationInfoWithZone unoptimized(info->shared_info()); | 92 CompilationInfoWithZone unoptimized(info->shared_info()); |
77 // Note that we use the same AST that we will use for generating the | 93 // Note that we use the same AST that we will use for generating the |
78 // optimized code. | 94 // optimized code. |
79 unoptimized.SetFunction(info->function()); | 95 unoptimized.SetFunction(info->function()); |
80 unoptimized.PrepareForCompilation(info->scope()); | 96 unoptimized.PrepareForCompilation(info->scope()); |
81 unoptimized.SetContext(info->context()); | 97 unoptimized.SetContext(info->context()); |
82 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); | 98 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 201 |
186 Handle<Object> true_value() { return isolate->factory()->true_value(); } | 202 Handle<Object> true_value() { return isolate->factory()->true_value(); } |
187 | 203 |
188 Handle<Object> false_value() { return isolate->factory()->false_value(); } | 204 Handle<Object> false_value() { return isolate->factory()->false_value(); } |
189 }; | 205 }; |
190 } | 206 } |
191 } | 207 } |
192 } // namespace v8::internal::compiler | 208 } // namespace v8::internal::compiler |
193 | 209 |
194 #endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ | 210 #endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ |
OLD | NEW |