Line data Source code
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 : #include "src/api-inl.h"
8 : #include "src/heap/heap-inl.h"
9 : #include "src/objects-inl.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 : namespace interpreter {
14 :
15 20815 : MaybeHandle<Object> CallInterpreter(Isolate* isolate,
16 : Handle<JSFunction> function) {
17 : return Execution::Call(isolate, function,
18 20875 : isolate->factory()->undefined_value(), 0, nullptr);
19 : }
20 :
21 0 : InterpreterTester::InterpreterTester(
22 : Isolate* isolate, const char* source, MaybeHandle<BytecodeArray> bytecode,
23 : MaybeHandle<FeedbackMetadata> feedback_metadata, const char* filter)
24 : : isolate_(isolate),
25 : source_(source),
26 : bytecode_(bytecode),
27 22025 : feedback_metadata_(feedback_metadata) {
28 22025 : i::FLAG_always_opt = false;
29 0 : }
30 :
31 19400 : InterpreterTester::InterpreterTester(
32 : Isolate* isolate, Handle<BytecodeArray> bytecode,
33 : MaybeHandle<FeedbackMetadata> feedback_metadata, const char* filter)
34 : : InterpreterTester(
35 : isolate, nullptr, bytecode,
36 : FLAG_lite_mode ? MaybeHandle<FeedbackMetadata>() : feedback_metadata,
37 19400 : filter) {}
38 :
39 2625 : InterpreterTester::InterpreterTester(Isolate* isolate, const char* source,
40 : const char* filter)
41 : : InterpreterTester(isolate, source, MaybeHandle<BytecodeArray>(),
42 2625 : MaybeHandle<FeedbackMetadata>(), filter) {}
43 :
44 : InterpreterTester::~InterpreterTester() = default;
45 :
46 60 : Local<Message> InterpreterTester::CheckThrowsReturnMessage() {
47 120 : TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate_));
48 : auto callable = GetCallable<>();
49 60 : MaybeHandle<Object> no_result = callable();
50 120 : CHECK(isolate_->has_pending_exception());
51 60 : CHECK(try_catch.HasCaught());
52 60 : CHECK(no_result.is_null());
53 60 : isolate_->OptionalRescheduleException(true);
54 120 : CHECK(!try_catch.Message().IsEmpty());
55 120 : return try_catch.Message();
56 : }
57 :
58 100 : Handle<Object> InterpreterTester::NewObject(const char* script) {
59 100 : return v8::Utils::OpenHandle(*CompileRun(script));
60 : }
61 :
62 0 : Handle<String> InterpreterTester::GetName(Isolate* isolate, const char* name) {
63 0 : Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name);
64 0 : return isolate->factory()->string_table()->LookupString(isolate, result);
65 : }
66 :
67 1455 : std::string InterpreterTester::SourceForBody(const char* body) {
68 10185 : return "function " + function_name() + "() {\n" + std::string(body) + "\n}";
69 : }
70 :
71 615 : std::string InterpreterTester::function_name() {
72 21100 : return std::string(kFunctionName);
73 : }
74 :
75 : const char InterpreterTester::kFunctionName[] = "f";
76 :
77 : } // namespace interpreter
78 : } // namespace internal
79 79968 : } // namespace v8
|