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 "src/init/v8.h" 6 7 #include "src/api/api-inl.h" 8 #include "src/heap/heap-inl.h" 9 #include "src/interpreter/interpreter-intrinsics.h" 10 #include "src/objects/objects-inl.h" 11 #include "test/cctest/interpreter/interpreter-tester.h" 12 13 namespace v8 { 14 namespace internal { 15 namespace interpreter { 16 17 namespace { 18 19 class InvokeIntrinsicHelper { 20 public: InvokeIntrinsicHelper(Isolate * isolate,Zone * zone,Runtime::FunctionId function_id)21 InvokeIntrinsicHelper(Isolate* isolate, Zone* zone, 22 Runtime::FunctionId function_id) 23 : isolate_(isolate), 24 zone_(zone), 25 factory_(isolate->factory()), 26 function_id_(function_id) {} 27 28 template <class... A> Invoke(A...args)29 Handle<Object> Invoke(A... args) { 30 CHECK(IntrinsicsHelper::IsSupported(function_id_)); 31 int parameter_count = sizeof...(args); 32 // Move the parameter to locals, since the order of the 33 // arguments in the stack is reversed. 34 BytecodeArrayBuilder builder(zone_, parameter_count + 1, parameter_count, 35 nullptr); 36 for (int i = 0; i < parameter_count; i++) { 37 builder.MoveRegister(builder.Parameter(i), builder.Local(i)); 38 } 39 RegisterList reg_list = 40 InterpreterTester::NewRegisterList(0, parameter_count); 41 builder.CallRuntime(function_id_, reg_list).Return(); 42 InterpreterTester tester(isolate_, builder.ToBytecodeArray(isolate_)); 43 auto callable = tester.GetCallable<A...>(); 44 return callable(args...).ToHandleChecked(); 45 } 46 NewObject(const char * script)47 Handle<Object> NewObject(const char* script) { 48 return v8::Utils::OpenHandle(*CompileRun(script)); 49 } 50 Undefined()51 Handle<Object> Undefined() { return factory_->undefined_value(); } Null()52 Handle<Object> Null() { return factory_->null_value(); } 53 54 private: 55 Isolate* isolate_; 56 Zone* zone_; 57 Factory* factory_; 58 Runtime::FunctionId function_id_; 59 }; 60 61 } // namespace 62 63 } // namespace interpreter 64 } // namespace internal 65 } // namespace v8 66