OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/v8.h" |
| 6 |
| 7 #include "src/execution.h" |
| 8 #include "src/handles.h" |
| 9 #include "src/interpreter/bytecode-array-builder.h" |
| 10 #include "src/interpreter/interpreter.h" |
| 11 #include "test/cctest/cctest.h" |
| 12 |
| 13 namespace v8 { |
| 14 namespace internal { |
| 15 |
| 16 class InterpreterCallable { |
| 17 public: |
| 18 InterpreterCallable(Isolate* isolate, Handle<JSFunction> function) |
| 19 : isolate_(isolate), function_(function) {} |
| 20 virtual ~InterpreterCallable() {} |
| 21 |
| 22 MaybeHandle<Object> operator()() { |
| 23 return Execution::Call(isolate_, function_, |
| 24 isolate_->factory()->undefined_value(), 0, nullptr, |
| 25 false); |
| 26 } |
| 27 |
| 28 private: |
| 29 Isolate* isolate_; |
| 30 Handle<JSFunction> function_; |
| 31 }; |
| 32 |
| 33 class InterpreterTester { |
| 34 public: |
| 35 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode) |
| 36 : isolate_(isolate), function_(GetBytecodeFunction(isolate, bytecode)) { |
| 37 i::FLAG_ignition = true; |
| 38 Handle<FixedArray> empty_array = isolate->factory()->empty_fixed_array(); |
| 39 Handle<FixedArray> interpreter_table = |
| 40 isolate->factory()->interpreter_table(); |
| 41 if (interpreter_table.is_identical_to(empty_array)) { |
| 42 // Ensure handler table is generated. |
| 43 isolate->interpreter()->Initialize(true); |
| 44 } |
| 45 } |
| 46 virtual ~InterpreterTester() {} |
| 47 |
| 48 InterpreterCallable GetCallable() { |
| 49 return InterpreterCallable(isolate_, function_); |
| 50 } |
| 51 |
| 52 private: |
| 53 Isolate* isolate_; |
| 54 Handle<JSFunction> function_; |
| 55 |
| 56 static Handle<JSFunction> GetBytecodeFunction( |
| 57 Isolate* isolate, Handle<BytecodeArray> bytecode_array) { |
| 58 Handle<JSFunction> function = v8::Utils::OpenHandle( |
| 59 *v8::Handle<v8::Function>::Cast(CompileRun("(function(){})"))); |
| 60 function->ReplaceCode(*isolate->builtins()->InterpreterEntryTrampoline()); |
| 61 function->shared()->set_function_data(*bytecode_array); |
| 62 return function; |
| 63 } |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(InterpreterTester); |
| 66 }; |
| 67 |
| 68 } // namespace internal |
| 69 } // namespace v8 |
| 70 |
| 71 using namespace v8::internal; |
| 72 using namespace v8::internal::interpreter; |
| 73 |
| 74 TEST(TestInterpreterReturn) { |
| 75 InitializedHandleScope handles; |
| 76 Handle<Object> undefined_value = |
| 77 handles.main_isolate()->factory()->undefined_value(); |
| 78 |
| 79 BytecodeArrayBuilder builder(handles.main_isolate()); |
| 80 // TODO(rmcilroy) set to 0 once BytecodeArray update to allow zero size |
| 81 // register file. |
| 82 builder.set_locals_count(1); |
| 83 builder.Return(); |
| 84 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 85 |
| 86 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 87 InterpreterCallable callable(tester.GetCallable()); |
| 88 Handle<Object> return_val = callable().ToHandleChecked(); |
| 89 CHECK(return_val.is_identical_to(undefined_value)); |
| 90 } |
OLD | NEW |