From 49fd86eae80897425577e262277b0b7ef8d2b91a Mon Sep 17 00:00:00 2001 From: HyukWoo Park Date: Tue, 24 Oct 2023 22:56:37 +0900 Subject: [PATCH] Enable try operation APIs only for test mode Signed-off-by: HyukWoo Park --- .github/workflows/es-actions.yml | 4 ++-- src/api/EscargotPublic.cpp | 12 ++++++++++++ src/api/EscargotPublic.h | 4 ++-- src/interpreter/ByteCodeInterpreter.cpp | 12 ++++++++++++ src/runtime/ExecutionState.cpp | 4 ++++ src/runtime/ExecutionState.h | 14 ++++++++++++++ 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/.github/workflows/es-actions.yml b/.github/workflows/es-actions.yml index 1cd2a8817..b16e69b0b 100644 --- a/.github/workflows/es-actions.yml +++ b/.github/workflows/es-actions.yml @@ -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 diff --git a/src/api/EscargotPublic.cpp b/src/api/EscargotPublic.cpp index 31eed997a..5669a7e35 100644 --- a/src/api/EscargotPublic.cpp +++ b/src/api/EscargotPublic.cpp @@ -2310,6 +2310,11 @@ void ObjectRef::setIsHTMLDDA() { toImpl(this)->setIsHTMLDDA(); } +#else +void ObjectRef::setIsHTMLDDA() +{ + // do nothing +} #endif void ObjectRef::removeFromHiddenClassChain() @@ -3067,6 +3072,7 @@ GlobalObjectRef* ExecutionStateRef::resolveCallerLexicalGlobalObject() return toRef(ctx->globalObject()); } +#if defined(ESCARGOT_ENABLE_TEST) bool ExecutionStateRef::onTry() { return toImpl(this)->onTry(); @@ -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) { diff --git a/src/api/EscargotPublic.h b/src/api/EscargotPublic.h index ade4fa45c..30a88dfa8 100644 --- a/src/api/EscargotPublic.h +++ b/src/api/EscargotPublic.h @@ -628,6 +628,7 @@ class ESCARGOT_EXPORT ExecutionStateRef { GCManagedVector 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(); @@ -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(); diff --git a/src/interpreter/ByteCodeInterpreter.cpp b/src/interpreter/ByteCodeInterpreter.cpp index 8ed6a44e5..567423ef5 100644 --- a/src/interpreter/ByteCodeInterpreter.cpp +++ b/src/interpreter/ByteCodeInterpreter.cpp @@ -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 class ExecutionStateVariableChanger { public: @@ -83,6 +84,7 @@ class ExecutionStateVariableChanger { ExecutionState& m_state; T m_changer; }; +#endif OpcodeTable::OpcodeTable() @@ -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 changer(*state, [](ExecutionState& state, bool in) { state.m_onTry = in; }); +#endif size_t newPc = programCounter + sizeof(TryOperation); Interpreter::interpret(newState, byteCodeBlock, newPc, registerFile); @@ -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 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(); @@ -3092,9 +3098,11 @@ NEVER_INLINE Value InterpreterSlowPath::tryOperation(ExecutionState*& state, siz } } else if (code->m_isCatchResumeProcess) { try { +#if defined(ESCARGOT_ENABLE_TEST) ExecutionStateVariableChanger 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(); @@ -3111,9 +3119,11 @@ NEVER_INLINE Value InterpreterSlowPath::tryOperation(ExecutionState*& state, siz } if (code->m_isFinallyResumeProcess) { +#if defined(ESCARGOT_ENABLE_TEST) ExecutionStateVariableChanger 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(); @@ -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 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(); diff --git a/src/runtime/ExecutionState.cpp b/src/runtime/ExecutionState.cpp index c9382e236..9a3128870 100644 --- a/src/runtime/ExecutionState.cpp +++ b/src/runtime/ExecutionState.cpp @@ -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 @@ -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 diff --git a/src/runtime/ExecutionState.h b/src/runtime/ExecutionState.h index c7b99a7a2..c2658a2e0 100644 --- a/src/runtime/ExecutionState.h +++ b/src/runtime/ExecutionState.h @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -253,6 +263,7 @@ class ExecutionState : public gc { return m_inExecutionStopState; } +#if defined(ESCARGOT_ENABLE_TEST) bool onTry() const { return m_onTry; @@ -267,6 +278,7 @@ class ExecutionState : public gc { { return m_onFinally; } +#endif #if defined(ENABLE_TCO) bool initTCO() const @@ -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