2016-03-22 11:35:09 +00:00
|
|
|
// 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"
|
|
|
|
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2019-02-14 21:10:30 +00:00
|
|
|
#include "src/heap/heap-inl.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2017-01-09 13:43:28 +00:00
|
|
|
|
2016-03-22 11:35:09 +00:00
|
|
|
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,
|
2017-02-07 14:05:02 +00:00
|
|
|
MaybeHandle<FeedbackMetadata> feedback_metadata, const char* filter)
|
2016-03-22 11:35:09 +00:00
|
|
|
: isolate_(isolate),
|
|
|
|
source_(source),
|
|
|
|
bytecode_(bytecode),
|
2017-01-26 10:03:00 +00:00
|
|
|
feedback_metadata_(feedback_metadata) {
|
2016-03-22 11:35:09 +00:00
|
|
|
i::FLAG_always_opt = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
InterpreterTester::InterpreterTester(
|
|
|
|
Isolate* isolate, Handle<BytecodeArray> bytecode,
|
2017-02-07 14:05:02 +00:00
|
|
|
MaybeHandle<FeedbackMetadata> feedback_metadata, const char* filter)
|
2019-05-14 16:15:30 +00:00
|
|
|
: InterpreterTester(isolate, nullptr, bytecode, feedback_metadata, filter) {
|
|
|
|
}
|
2016-03-22 11:35:09 +00:00
|
|
|
|
|
|
|
InterpreterTester::InterpreterTester(Isolate* isolate, const char* source,
|
|
|
|
const char* filter)
|
|
|
|
: InterpreterTester(isolate, source, MaybeHandle<BytecodeArray>(),
|
2017-02-07 14:05:02 +00:00
|
|
|
MaybeHandle<FeedbackMetadata>(), filter) {}
|
2016-03-22 11:35:09 +00:00
|
|
|
|
2018-09-13 09:22:50 +00:00
|
|
|
InterpreterTester::~InterpreterTester() = default;
|
2016-03-22 11:35:09 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-09-04 10:47:27 +00:00
|
|
|
const char InterpreterTester::kFunctionName[] = "f";
|
|
|
|
|
2016-03-22 11:35:09 +00:00
|
|
|
} // namespace interpreter
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|