• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/interpreter/interpreter-inl.h"
17 
18 #include "ecmascript/frames.h"
19 #include "ecmascript/interpreter/frame_handler.h"
20 namespace panda::ecmascript {
21 // make EcmaRuntimeCallInfo in stack pointer as fallows:
22 //   +----------------------+   —
23 //   |        args...       |   ^
24 //   |----------------------|   |
25 //   |        numArgs       |   |
26 //   |----------------------|   |
27 //   |        this          |   |
28 //   |----------------------| EcmaRuntimeCallInfo
29 //   |       newTarget      |   |
30 //   |----------------------|   |
31 //   |        func          |   v
32 //   +----------------------+   —
33 //   |      base.type       |   ^
34 //   |----------------------|   |
35 //   |      base.prev       | InterpretedEntryFrame
36 //   |----------------------|   |
37 //   |          pc          |   v
38 //   +--------------------------+
NewRuntimeCallInfo(JSThread * thread,JSHandle<JSTaggedValue> func,JSHandle<JSTaggedValue> thisObj,JSHandle<JSTaggedValue> newTarget,uint32_t numArgs,bool needCheckStack)39 EcmaRuntimeCallInfo* EcmaInterpreter::NewRuntimeCallInfo(
40     JSThread *thread, JSHandle<JSTaggedValue> func, JSHandle<JSTaggedValue> thisObj, JSHandle<JSTaggedValue> newTarget,
41     uint32_t numArgs, bool needCheckStack)
42 {
43     JSTaggedType *prevSp = const_cast<JSTaggedType *>(thread->GetCurrentSPFrame());
44     JSTaggedType *newSp = GetInterpreterFrameEnd(thread, prevSp);
45     if (needCheckStack && UNLIKELY(thread->DoStackOverflowCheck(newSp - numArgs - NUM_MANDATORY_JSFUNC_ARGS))) {
46         return nullptr;
47     }
48 
49     for (uint32_t i = 0; i < numArgs; i++) {
50         *(--newSp) = JSTaggedValue::VALUE_UNDEFINED;
51     }
52     *(--newSp) = thisObj.GetTaggedType();
53     *(--newSp) = newTarget.GetTaggedType();
54     *(--newSp) = func.GetTaggedType();
55     *(--newSp) = numArgs + NUM_MANDATORY_JSFUNC_ARGS;
56     *(--newSp) = ToUintPtr(thread);
57     EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast<EcmaRuntimeCallInfo *>(newSp);
58 
59     // create entry frame.
60     InterpretedEntryFrame *entryState = InterpretedEntryFrame::GetFrameFromSp(newSp);
61     entryState->base.type = FrameType::INTERPRETER_ENTRY_FRAME;
62     entryState->base.prev = prevSp;
63     entryState->pc = nullptr;
64 
65     thread->SetCurrentSPFrame(newSp);
66     return ecmaRuntimeCallInfo;
67 }
68 }  // namespace panda::ecmascript
69