1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ecmascript/js_invoker.h"
17
18 #include "ecmascript/ecma_runtime_call_info.h"
19 #include "ecmascript/interpreter/interpreter-inl.h"
20 #include "ecmascript/js_tagged_value.h"
21 #include "ecmascript/js_thread.h"
22 #include "ecmascript/mem/c_containers.h"
23 #include "ecmascript/tagged_array-inl.h"
24 #include "libpandabase/utils/span.h"
25
26 namespace panda::ecmascript {
Invoke(JSThread * thread)27 JSTaggedValue JsInvoker::Invoke(JSThread *thread)
28 {
29 UNREACHABLE();
30 }
31
InvokeJsFunction(JSThread * thread,const JSHandle<JSFunction> & func,const JSHandle<JSTaggedValue> & obj,const JSHandle<JSTaggedValue> & newTgt,InternalCallParams * arguments)32 JSTaggedValue InvokeJsFunction(JSThread *thread, const JSHandle<JSFunction> &func, const JSHandle<JSTaggedValue> &obj,
33 const JSHandle<JSTaggedValue> &newTgt, InternalCallParams *arguments)
34 {
35 ASSERT(func->GetCallTarget() != nullptr);
36
37 CallParams params;
38 params.callTarget = ECMAObject::Cast(*func);
39 params.newTarget = newTgt.GetTaggedType();
40 params.thisArg = obj.GetTaggedType();
41 params.argc = arguments->GetLength();
42 params.argv = arguments->GetArgv();
43 return EcmaInterpreter::Execute(thread, params);
44 }
45 } // namespace panda::ecmascript
46