blob: df60c452cd4b998e8e25f2313a73556fd85ad1ce [file] [log] [blame]
Ben Murdochda12d292016-06-02 14:46:10 +01001// 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
7namespace v8 {
8namespace internal {
9namespace interpreter {
10
11MaybeHandle<Object> CallInterpreter(Isolate* isolate,
12 Handle<JSFunction> function) {
13 return Execution::Call(isolate, function,
14 isolate->factory()->undefined_value(), 0, nullptr);
15}
16
17InterpreterTester::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
30InterpreterTester::InterpreterTester(
31 Isolate* isolate, Handle<BytecodeArray> bytecode,
32 MaybeHandle<TypeFeedbackVector> feedback_vector, const char* filter)
33 : InterpreterTester(isolate, nullptr, bytecode, feedback_vector, filter) {}
34
35InterpreterTester::InterpreterTester(Isolate* isolate, const char* source,
36 const char* filter)
37 : InterpreterTester(isolate, source, MaybeHandle<BytecodeArray>(),
38 MaybeHandle<TypeFeedbackVector>(), filter) {}
39
40InterpreterTester::~InterpreterTester() {}
41
42Local<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
54Handle<Object> InterpreterTester::NewObject(const char* script) {
55 return v8::Utils::OpenHandle(*CompileRun(script));
56}
57
58Handle<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
63std::string InterpreterTester::SourceForBody(const char* body) {
64 return "function " + function_name() + "() {\n" + std::string(body) + "\n}";
65}
66
67std::string InterpreterTester::function_name() {
68 return std::string(kFunctionName);
69}
70
71} // namespace interpreter
72} // namespace internal
73} // namespace v8