interpreter-tester.cc 2.57 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "test/cctest/interpreter/interpreter-tester.h"

7 8
#include "src/objects-inl.h"

9 10 11 12 13 14 15 16 17 18 19 20
namespace v8 {
namespace internal {
namespace interpreter {

MaybeHandle<Object> CallInterpreter(Isolate* isolate,
                                    Handle<JSFunction> function) {
  return Execution::Call(isolate, function,
                         isolate->factory()->undefined_value(), 0, nullptr);
}

InterpreterTester::InterpreterTester(
    Isolate* isolate, const char* source, MaybeHandle<BytecodeArray> bytecode,
21
    MaybeHandle<FeedbackMetadata> feedback_metadata, const char* filter)
22 23 24
    : isolate_(isolate),
      source_(source),
      bytecode_(bytecode),
25
      feedback_metadata_(feedback_metadata) {
26 27 28 29 30
  i::FLAG_always_opt = false;
}

InterpreterTester::InterpreterTester(
    Isolate* isolate, Handle<BytecodeArray> bytecode,
31
    MaybeHandle<FeedbackMetadata> feedback_metadata, const char* filter)
32 33
    : InterpreterTester(isolate, nullptr, bytecode, feedback_metadata, filter) {
}
34 35 36 37

InterpreterTester::InterpreterTester(Isolate* isolate, const char* source,
                                     const char* filter)
    : InterpreterTester(isolate, source, MaybeHandle<BytecodeArray>(),
38
                        MaybeHandle<FeedbackMetadata>(), filter) {}
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

InterpreterTester::~InterpreterTester() {}

Local<Message> InterpreterTester::CheckThrowsReturnMessage() {
  TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate_));
  auto callable = GetCallable<>();
  MaybeHandle<Object> no_result = callable();
  CHECK(isolate_->has_pending_exception());
  CHECK(try_catch.HasCaught());
  CHECK(no_result.is_null());
  isolate_->OptionalRescheduleException(true);
  CHECK(!try_catch.Message().IsEmpty());
  return try_catch.Message();
}

Handle<Object> InterpreterTester::NewObject(const char* script) {
  return v8::Utils::OpenHandle(*CompileRun(script));
}

Handle<String> InterpreterTester::GetName(Isolate* isolate, const char* name) {
  Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name);
  return isolate->factory()->string_table()->LookupString(isolate, result);
}

std::string InterpreterTester::SourceForBody(const char* body) {
  return "function " + function_name() + "() {\n" + std::string(body) + "\n}";
}

std::string InterpreterTester::function_name() {
  return std::string(kFunctionName);
}

71 72
const char InterpreterTester::kFunctionName[] = "f";

73 74 75
}  // namespace interpreter
}  // namespace internal
}  // namespace v8