Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 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 "test/cctest/interpreter/interpreter-tester.h" |
| 6 | |
| 7 | namespace v8 { |
| 8 | namespace internal { |
| 9 | namespace interpreter { |
| 10 | |
| 11 | MaybeHandle<Object> CallInterpreter(Isolate* isolate, |
| 12 | Handle<JSFunction> function) { |
| 13 | return Execution::Call(isolate, function, |
| 14 | isolate->factory()->undefined_value(), 0, nullptr); |
| 15 | } |
| 16 | |
| 17 | InterpreterTester::InterpreterTester( |
| 18 | Isolate* isolate, const char* source, MaybeHandle<BytecodeArray> bytecode, |
| 19 | MaybeHandle<TypeFeedbackVector> feedback_vector, const char* filter) |
| 20 | : isolate_(isolate), |
| 21 | source_(source), |
| 22 | bytecode_(bytecode), |
| 23 | feedback_vector_(feedback_vector) { |
| 24 | i::FLAG_ignition = true; |
| 25 | i::FLAG_always_opt = false; |
| 26 | // Ensure handler table is generated. |
| 27 | isolate->interpreter()->Initialize(); |
| 28 | } |
| 29 | |
| 30 | InterpreterTester::InterpreterTester( |
| 31 | Isolate* isolate, Handle<BytecodeArray> bytecode, |
| 32 | MaybeHandle<TypeFeedbackVector> feedback_vector, const char* filter) |
| 33 | : InterpreterTester(isolate, nullptr, bytecode, feedback_vector, filter) {} |
| 34 | |
| 35 | InterpreterTester::InterpreterTester(Isolate* isolate, const char* source, |
| 36 | const char* filter) |
| 37 | : InterpreterTester(isolate, source, MaybeHandle<BytecodeArray>(), |
| 38 | MaybeHandle<TypeFeedbackVector>(), filter) {} |
| 39 | |
| 40 | InterpreterTester::~InterpreterTester() {} |
| 41 | |
| 42 | Local<Message> InterpreterTester::CheckThrowsReturnMessage() { |
| 43 | TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate_)); |
| 44 | auto callable = GetCallable<>(); |
| 45 | MaybeHandle<Object> no_result = callable(); |
| 46 | CHECK(isolate_->has_pending_exception()); |
| 47 | CHECK(try_catch.HasCaught()); |
| 48 | CHECK(no_result.is_null()); |
| 49 | isolate_->OptionalRescheduleException(true); |
| 50 | CHECK(!try_catch.Message().IsEmpty()); |
| 51 | return try_catch.Message(); |
| 52 | } |
| 53 | |
| 54 | Handle<Object> InterpreterTester::NewObject(const char* script) { |
| 55 | return v8::Utils::OpenHandle(*CompileRun(script)); |
| 56 | } |
| 57 | |
| 58 | Handle<String> InterpreterTester::GetName(Isolate* isolate, const char* name) { |
| 59 | Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name); |
| 60 | return isolate->factory()->string_table()->LookupString(isolate, result); |
| 61 | } |
| 62 | |
| 63 | std::string InterpreterTester::SourceForBody(const char* body) { |
| 64 | return "function " + function_name() + "() {\n" + std::string(body) + "\n}"; |
| 65 | } |
| 66 | |
| 67 | std::string InterpreterTester::function_name() { |
| 68 | return std::string(kFunctionName); |
| 69 | } |
| 70 | |
| 71 | } // namespace interpreter |
| 72 | } // namespace internal |
| 73 | } // namespace v8 |