v8/test/unittests/interpreter/interpreter-intrinsics-unittest.cc
jameslahm b3d004aaf9 [test] Move cctest/interpreter to unittests
... /interpreter.

This CL moves cctest/interpreter/{bytecode-expectations-printer,
test-bytecode-generator, test-interpreter-intrinsics,
interpreter-tester, test-interpreter, test-source-positions,
source-position-matcher} to unittests/interpreter/{
bytecode-expectations-printer, bytecode-generator-unittest,
interpreter-intrinsics-unittest, interpreter-tester,
interpreter-unittest, source-positions-unittest, source-position-matcher}.

Bug: v8:12781
Change-Id: I187583bd34f709dd0d7dfc0f92e18f191da0e30f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3609752
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81057}
2022-06-10 08:37:10 +00:00

66 lines
2.0 KiB
C++

// 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 "src/interpreter/interpreter-intrinsics.h"
#include "src/api/api-inl.h"
#include "src/heap/heap-inl.h"
#include "src/init/v8.h"
#include "src/objects/objects-inl.h"
#include "test/unittests/interpreter/interpreter-tester.h"
namespace v8 {
namespace internal {
namespace interpreter {
namespace {
class InvokeIntrinsicHelper {
public:
InvokeIntrinsicHelper(Isolate* isolate, Zone* zone,
Runtime::FunctionId function_id)
: isolate_(isolate),
zone_(zone),
factory_(isolate->factory()),
function_id_(function_id) {}
template <class... A>
Handle<Object> Invoke(A... args) {
CHECK(IntrinsicsHelper::IsSupported(function_id_));
int parameter_count = sizeof...(args);
// Move the parameter to locals, since the order of the
// arguments in the stack is reversed.
BytecodeArrayBuilder builder(zone_, parameter_count + 1, parameter_count,
nullptr);
for (int i = 0; i < parameter_count; i++) {
builder.MoveRegister(builder.Parameter(i), builder.Local(i));
}
RegisterList reg_list =
InterpreterTester::NewRegisterList(0, parameter_count);
builder.CallRuntime(function_id_, reg_list).Return();
InterpreterTester tester(isolate_, builder.ToBytecodeArray(isolate_));
auto callable = tester.GetCallable<A...>();
return callable(args...).ToHandleChecked();
}
Handle<Object> NewObject(const char* script) {
return v8::Utils::OpenHandle(*CompileRun(script));
}
Handle<Object> Undefined() { return factory_->undefined_value(); }
Handle<Object> Null() { return factory_->null_value(); }
private:
Isolate* isolate_;
Zone* zone_;
Factory* factory_;
Runtime::FunctionId function_id_;
};
} // namespace
} // namespace interpreter
} // namespace internal
} // namespace v8