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