Skip to content

Commit

Permalink
Enable try operation APIs only for test mode
Browse files Browse the repository at this point in the history
Signed-off-by: HyukWoo Park <[email protected]>
  • Loading branch information
clover2123 authored and ksh8281 committed Oct 25, 2023
1 parent 28f1f0f commit 49fd86e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/es-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ jobs:
sudo apt-get install -y ninja-build gcc-multilib g++-multilib
- name: Build x86/x64
env:
BUILD_OPTIONS_X86: -DCMAKE_SYSTEM_PROCSEEOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=ON -DESCARGOT_DEBUGGER=1 -DESCARGOT_OUTPUT=cctest -GNinja
BUILD_OPTIONS_X64: -DESCARGOT_MODE=debug -DESCARGOT_THREADING=1 -DESCARGOT_DEBUGGER=1 -DESCARGOT_OUTPUT=cctest -GNinja
BUILD_OPTIONS_X86: -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=ON -DESCARGOT_DEBUGGER=1 -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=cctest -GNinja
BUILD_OPTIONS_X64: -DESCARGOT_MODE=debug -DESCARGOT_THREADING=1 -DESCARGOT_DEBUGGER=1 -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=cctest -GNinja
run: |
cmake -H. -Bout/cctest/x86 $BUILD_OPTIONS_X86
ninja -Cout/cctest/x86
Expand Down
12 changes: 12 additions & 0 deletions src/api/EscargotPublic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,11 @@ void ObjectRef::setIsHTMLDDA()
{
toImpl(this)->setIsHTMLDDA();
}
#else
void ObjectRef::setIsHTMLDDA()
{
// do nothing
}
#endif

void ObjectRef::removeFromHiddenClassChain()
Expand Down Expand Up @@ -3067,6 +3072,7 @@ GlobalObjectRef* ExecutionStateRef::resolveCallerLexicalGlobalObject()
return toRef(ctx->globalObject());
}

#if defined(ESCARGOT_ENABLE_TEST)
bool ExecutionStateRef::onTry()
{
return toImpl(this)->onTry();
Expand All @@ -3081,6 +3087,12 @@ bool ExecutionStateRef::onFinally()
{
return toImpl(this)->onFinally();
}
#else
// these three functions are used only for test purpose
bool ExecutionStateRef::onTry() { return false; }
bool ExecutionStateRef::onCatch() { return false; }
bool ExecutionStateRef::onFinally() { return false; }
#endif

void ExecutionStateRef::throwException(ValueRef* value)
{
Expand Down
4 changes: 2 additions & 2 deletions src/api/EscargotPublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ class ESCARGOT_EXPORT ExecutionStateRef {
GCManagedVector<FunctionObjectRef*> resolveCallstack(); // resolve list of callee
GlobalObjectRef* resolveCallerLexicalGlobalObject(); // resolve caller's lexical global object

// these 3 functions are used only for test purpose
bool onTry();
bool onCatch();
bool onFinally();
Expand Down Expand Up @@ -1396,9 +1397,8 @@ class ESCARGOT_EXPORT ObjectRef : public PointerValueRef {

void* extraData();
void setExtraData(void* e);
#if defined(ESCARGOT_ENABLE_TEST)
// this function is used only for test purpose
void setIsHTMLDDA();
#endif

void removeFromHiddenClassChain();

Expand Down
12 changes: 12 additions & 0 deletions src/interpreter/ByteCodeInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ALWAYS_INLINE size_t jumpTo(char* codeBuffer, const size_t jumpPosition)
return (size_t)&codeBuffer[jumpPosition];
}

#if defined(ESCARGOT_ENABLE_TEST)
template <typename T>
class ExecutionStateVariableChanger {
public:
Expand All @@ -83,6 +84,7 @@ class ExecutionStateVariableChanger {
ExecutionState& m_state;
T m_changer;
};
#endif


OpcodeTable::OpcodeTable()
Expand Down Expand Up @@ -3023,9 +3025,11 @@ NEVER_INLINE Value InterpreterSlowPath::tryOperation(ExecutionState*& state, siz

if (LIKELY(!code->m_isCatchResumeProcess && !code->m_isFinallyResumeProcess)) {
try {
#if defined(ESCARGOT_ENABLE_TEST)
ExecutionStateVariableChanger<void (*)(ExecutionState&, bool)> changer(*state, [](ExecutionState& state, bool in) {
state.m_onTry = in;
});
#endif

size_t newPc = programCounter + sizeof(TryOperation);
Interpreter::interpret(newState, byteCodeBlock, newPc, registerFile);
Expand Down Expand Up @@ -3077,9 +3081,11 @@ NEVER_INLINE Value InterpreterSlowPath::tryOperation(ExecutionState*& state, siz
stackTraceDataVector.clear();
registerFile[code->m_catchedValueRegisterIndex] = val;
try {
#if defined(ESCARGOT_ENABLE_TEST)
ExecutionStateVariableChanger<void (*)(ExecutionState&, bool)> changer(*state, [](ExecutionState& state, bool in) {
state.m_onCatch = in;
});
#endif
Interpreter::interpret(newState, byteCodeBlock, (size_t)codeBuffer + code->m_catchPosition, registerFile);
if (newState->inExecutionStopState()) {
return Value();
Expand All @@ -3092,9 +3098,11 @@ NEVER_INLINE Value InterpreterSlowPath::tryOperation(ExecutionState*& state, siz
}
} else if (code->m_isCatchResumeProcess) {
try {
#if defined(ESCARGOT_ENABLE_TEST)
ExecutionStateVariableChanger<void (*)(ExecutionState&, bool)> changer(*state, [](ExecutionState& state, bool in) {
state.m_onCatch = in;
});
#endif
Interpreter::interpret(newState, byteCodeBlock, programCounter + sizeof(TryOperation), registerFile);
if (UNLIKELY(newState->inExecutionStopState() || newState->parent()->inExecutionStopState())) {
return Value();
Expand All @@ -3111,9 +3119,11 @@ NEVER_INLINE Value InterpreterSlowPath::tryOperation(ExecutionState*& state, siz
}

if (code->m_isFinallyResumeProcess) {
#if defined(ESCARGOT_ENABLE_TEST)
ExecutionStateVariableChanger<void (*)(ExecutionState&, bool)> changer(*state, [](ExecutionState& state, bool in) {
state.m_onFinally = in;
});
#endif
Interpreter::interpret(newState, byteCodeBlock, programCounter + sizeof(TryOperation), registerFile);
if (newState->inExecutionStopState() || newState->parent()->inExecutionStopState()) {
return Value();
Expand All @@ -3132,9 +3142,11 @@ NEVER_INLINE Value InterpreterSlowPath::tryOperation(ExecutionState*& state, siz
newState = new ExecutionState(state, state->lexicalEnvironment(), state->inStrictMode());
newState->ensureRareData()->m_controlFlowRecord = state->rareData()->m_controlFlowRecord;
}
#if defined(ESCARGOT_ENABLE_TEST)
ExecutionStateVariableChanger<void (*)(ExecutionState&, bool)> changer(*state, [](ExecutionState& state, bool in) {
state.m_onFinally = in;
});
#endif
Interpreter::interpret(newState, byteCodeBlock, (size_t)codeBuffer + code->m_tryCatchEndPosition, registerFile);
if (newState->inExecutionStopState()) {
return Value();
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/ExecutionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ ExecutionState::ExecutionState()
, m_inStrictMode(false)
, m_isNativeFunctionObjectExecutionContext(false)
, m_inExecutionStopState(false)
#if defined(ESCARGOT_ENABLE_TEST)
, m_onTry(false)
, m_onCatch(false)
, m_onFinally(false)
#endif
#if defined(ENABLE_TCO)
, m_initTCO(false)
#endif
Expand All @@ -67,9 +69,11 @@ ExecutionState::ExecutionState(Context* context)
, m_inStrictMode(false)
, m_isNativeFunctionObjectExecutionContext(false)
, m_inExecutionStopState(false)
#if defined(ESCARGOT_ENABLE_TEST)
, m_onTry(false)
, m_onCatch(false)
, m_onFinally(false)
#endif
#if defined(ENABLE_TCO)
, m_initTCO(false)
#endif
Expand Down
14 changes: 14 additions & 0 deletions src/runtime/ExecutionState.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ class ExecutionState : public gc {
, m_inStrictMode(inStrictMode)
, m_isNativeFunctionObjectExecutionContext(false)
, m_inExecutionStopState(false)
#if defined(ESCARGOT_ENABLE_TEST)
, m_onTry(false)
, m_onCatch(false)
, m_onFinally(false)
#endif
#if defined(ENABLE_TCO)
, m_initTCO(false)
#endif
Expand All @@ -99,9 +101,11 @@ class ExecutionState : public gc {
, m_inStrictMode(false)
, m_isNativeFunctionObjectExecutionContext(false)
, m_inExecutionStopState(false)
#if defined(ESCARGOT_ENABLE_TEST)
, m_onTry(false)
, m_onCatch(false)
, m_onFinally(false)
#endif
#if defined(ENABLE_TCO)
, m_initTCO(false)
#endif
Expand All @@ -120,9 +124,11 @@ class ExecutionState : public gc {
, m_inStrictMode(inStrictMode)
, m_isNativeFunctionObjectExecutionContext(false)
, m_inExecutionStopState(false)
#if defined(ESCARGOT_ENABLE_TEST)
, m_onTry(false)
, m_onCatch(false)
, m_onFinally(false)
#endif
#if defined(ENABLE_TCO)
, m_initTCO(false)
#endif
Expand All @@ -141,9 +147,11 @@ class ExecutionState : public gc {
, m_inStrictMode(inStrictMode)
, m_isNativeFunctionObjectExecutionContext(true)
, m_inExecutionStopState(false)
#if defined(ESCARGOT_ENABLE_TEST)
, m_onTry(false)
, m_onCatch(false)
, m_onFinally(false)
#endif
#if defined(ENABLE_TCO)
, m_initTCO(false)
#endif
Expand All @@ -165,9 +173,11 @@ class ExecutionState : public gc {
, m_inStrictMode(inStrictMode)
, m_isNativeFunctionObjectExecutionContext(false)
, m_inExecutionStopState(false)
#if defined(ESCARGOT_ENABLE_TEST)
, m_onTry(false)
, m_onCatch(false)
, m_onFinally(false)
#endif
#if defined(ENABLE_TCO)
, m_initTCO(false)
#endif
Expand Down Expand Up @@ -253,6 +263,7 @@ class ExecutionState : public gc {
return m_inExecutionStopState;
}

#if defined(ESCARGOT_ENABLE_TEST)
bool onTry() const
{
return m_onTry;
Expand All @@ -267,6 +278,7 @@ class ExecutionState : public gc {
{
return m_onFinally;
}
#endif

#if defined(ENABLE_TCO)
bool initTCO() const
Expand Down Expand Up @@ -358,9 +370,11 @@ class ExecutionState : public gc {
bool m_inStrictMode : 1;
bool m_isNativeFunctionObjectExecutionContext : 1;
bool m_inExecutionStopState : 1;
#if defined(ESCARGOT_ENABLE_TEST)
bool m_onTry : 1;
bool m_onCatch : 1;
bool m_onFinally : 1;
#endif
#if defined(ENABLE_TCO)
bool m_initTCO : 1;
#endif
Expand Down

0 comments on commit 49fd86e

Please sign in to comment.