From b980f684889a5dcf822b8968b44f59bc737b54c0 Mon Sep 17 00:00:00 2001 From: HyukWoo Park Date: Mon, 24 Jul 2023 20:18:32 +0900 Subject: [PATCH] Fix minor code defects Signed-off-by: HyukWoo Park --- src/interpreter/ByteCodeInterpreter.cpp | 12 ++++-------- src/runtime/EnvironmentRecord.cpp | 10 ---------- src/runtime/EnvironmentRecord.h | 6 ------ src/runtime/ExecutionState.h | 14 +++++++------- src/runtime/GlobalObject.cpp | 2 +- src/runtime/SandBox.cpp | 2 +- src/runtime/SandBox.h | 2 +- 7 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/interpreter/ByteCodeInterpreter.cpp b/src/interpreter/ByteCodeInterpreter.cpp index a2cf71f70..c15d28e87 100644 --- a/src/interpreter/ByteCodeInterpreter.cpp +++ b/src/interpreter/ByteCodeInterpreter.cpp @@ -103,7 +103,7 @@ OpcodeTable::OpcodeTable() class InterpreterSlowPath { public: static Value loadByName(ExecutionState& state, LexicalEnvironment* env, const AtomicString& name, bool throwException = true); - static EnvironmentRecord* getBindedEnvironmentRecordByName(ExecutionState& state, LexicalEnvironment* env, const AtomicString& name, Value& bindedValue, bool throwException = true); + static EnvironmentRecord* getBindedEnvironmentRecordByName(ExecutionState& state, LexicalEnvironment* env, const AtomicString& name, Value& bindedValue); static void storeByName(ExecutionState& state, LexicalEnvironment* env, const AtomicString& name, const Value& value); static void initializeByName(ExecutionState& state, LexicalEnvironment* env, const AtomicString& name, bool isLexicallyDeclaredName, const Value& value); static void resolveNameAddress(ExecutionState& state, ResolveNameAddress* code, Value* registerFile); @@ -1682,7 +1682,7 @@ Value Interpreter::interpret(ExecutionState* state, ByteCodeBlock* byteCodeBlock return Value(); } -NEVER_INLINE EnvironmentRecord* InterpreterSlowPath::getBindedEnvironmentRecordByName(ExecutionState& state, LexicalEnvironment* env, const AtomicString& name, Value& bindedValue, bool throwException) +NEVER_INLINE EnvironmentRecord* InterpreterSlowPath::getBindedEnvironmentRecordByName(ExecutionState& state, LexicalEnvironment* env, const AtomicString& name, Value& bindedValue) { while (env) { EnvironmentRecord::GetBindingValueResult result = env->record()->getBindingValue(state, name); @@ -1693,9 +1693,7 @@ NEVER_INLINE EnvironmentRecord* InterpreterSlowPath::getBindedEnvironmentRecordB env = env->outerEnvironment(); } - if (throwException) - ErrorObject::throwBuiltinError(state, ErrorCode::ReferenceError, name.string(), false, String::emptyString, ErrorObject::Messages::IsNotDefined); - + ErrorObject::throwBuiltinError(state, ErrorCode::ReferenceError, name.string(), false, String::emptyString, ErrorObject::Messages::IsNotDefined); return NULL; } @@ -3675,9 +3673,7 @@ NEVER_INLINE void InterpreterSlowPath::callFunctionComplexCase(ExecutionState& s Object* receiverObj = NULL; Value callee; EnvironmentRecord* bindedRecord = getBindedEnvironmentRecordByName(state, state.lexicalEnvironment(), calleeName, callee); - if (!bindedRecord) { - callee = Value(); - } + ASSERT(!!bindedRecord); if (bindedRecord && bindedRecord->isObjectEnvironmentRecord()) { receiverObj = bindedRecord->asObjectEnvironmentRecord()->bindingObject(); diff --git a/src/runtime/EnvironmentRecord.cpp b/src/runtime/EnvironmentRecord.cpp index 453c427e6..e1c014ba2 100644 --- a/src/runtime/EnvironmentRecord.cpp +++ b/src/runtime/EnvironmentRecord.cpp @@ -536,16 +536,6 @@ EnvironmentRecord::GetBindingValueResult ModuleEnvironmentRecord::getBindingValu return GetBindingValueResult(); } -Value ModuleEnvironmentRecord::getBindingValue(ExecutionState& state, const size_t i) -{ - if (m_moduleBindings[i].m_targetRecord) { - return m_moduleBindings[i].m_targetRecord->getBindingValue(state, m_moduleBindings[i].m_targetBindingName).m_value; - } else { - readCheck(state, i); - return m_moduleBindings[i].m_value; - } -} - void ModuleEnvironmentRecord::setHeapValueByIndex(ExecutionState& state, const size_t idx, const Value& v) { writeCheck(state, idx); diff --git a/src/runtime/EnvironmentRecord.h b/src/runtime/EnvironmentRecord.h index 582763dad..312c0c212 100644 --- a/src/runtime/EnvironmentRecord.h +++ b/src/runtime/EnvironmentRecord.h @@ -125,11 +125,6 @@ class EnvironmentRecord : public gc { return GetBindingValueResult(); } - virtual Value getBindingValue(ExecutionState& state, const size_t idx) - { - RELEASE_ASSERT_NOT_REACHED(); - } - virtual bool deleteBinding(ExecutionState& state, const AtomicString& name) { RELEASE_ASSERT_NOT_REACHED(); @@ -1230,7 +1225,6 @@ class ModuleEnvironmentRecord : public DeclarativeEnvironmentRecord { virtual void setMutableBindingByIndex(ExecutionState& state, const size_t i, const Value& v) override; virtual void initializeBindingByIndex(ExecutionState& state, const size_t idx, const Value& v) override; virtual GetBindingValueResult getBindingValue(ExecutionState& state, const AtomicString& name) override; - virtual Value getBindingValue(ExecutionState& state, const size_t i) override; virtual void setHeapValueByIndex(ExecutionState& state, const size_t idx, const Value& v) override; virtual Value getHeapValueByIndex(ExecutionState& state, const size_t idx) override; Script* script() diff --git a/src/runtime/ExecutionState.h b/src/runtime/ExecutionState.h index 431ba0236..c821c9bd9 100644 --- a/src/runtime/ExecutionState.h +++ b/src/runtime/ExecutionState.h @@ -40,19 +40,19 @@ class NativeFunctionObject; typedef Vector> ControlFlowRecordVector; struct ExecutionStateRareData : public gc { - ControlFlowRecordVector* m_controlFlowRecord; - ExecutionState* m_parent; CodeBlock* m_codeBlock; + ControlFlowRecordVector* m_controlFlowRecord; ExecutionPauser* m_pauseSource; + ExecutionState* m_parent; size_t m_programCounterWhenItStoppedByYield; ExecutionStateRareData() + : m_codeBlock(nullptr) + , m_controlFlowRecord(nullptr) + , m_pauseSource(nullptr) + , m_parent(nullptr) + , m_programCounterWhenItStoppedByYield(SIZE_MAX) { - m_codeBlock = nullptr; - m_controlFlowRecord = nullptr; - m_pauseSource = nullptr; - m_parent = nullptr; - m_programCounterWhenItStoppedByYield = SIZE_MAX; } }; diff --git a/src/runtime/GlobalObject.cpp b/src/runtime/GlobalObject.cpp index b42ca90e1..55c7775e0 100644 --- a/src/runtime/GlobalObject.cpp +++ b/src/runtime/GlobalObject.cpp @@ -847,7 +847,7 @@ static Value builtinArrayToString(ExecutionState& state, Value thisValue, size_t return Object::call(state, toString, thisObject, 0, nullptr); } -Value builtinGenericIteratorNext(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional newTarget) +static Value builtinGenericIteratorNext(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional newTarget) { if (!thisValue.isObject() || !thisValue.asObject()->isGenericIteratorObject()) { ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, String::fromASCII("Iterator"), true, state.context()->staticStrings().next.string(), ErrorObject::Messages::GlobalObject_CalledOnIncompatibleReceiver); diff --git a/src/runtime/SandBox.cpp b/src/runtime/SandBox.cpp index b926972c3..20df75899 100644 --- a/src/runtime/SandBox.cpp +++ b/src/runtime/SandBox.cpp @@ -289,7 +289,7 @@ bool SandBox::createStackTrace(StackTraceDataVector& stackTraceDataVector, Execu return false; } -void SandBox::throwException(ExecutionState& state, Value exception) +void SandBox::throwException(ExecutionState& state, const Value& exception) { m_stackTraceDataVector.clear(); createStackTrace(m_stackTraceDataVector, state); diff --git a/src/runtime/SandBox.h b/src/runtime/SandBox.h index 5eb1bdcf6..392abffb3 100644 --- a/src/runtime/SandBox.h +++ b/src/runtime/SandBox.h @@ -85,7 +85,7 @@ class SandBox : public gc { static bool createStackTrace(StackTraceDataVector& stackTraceDataVector, ExecutionState& state, bool stopAtPause = false); - void throwException(ExecutionState& state, Value exception); + void throwException(ExecutionState& state, const Value& exception); void rethrowPreviouslyCaughtException(ExecutionState& state, Value exception, const StackTraceDataVector& stackTraceDataVector); StackTraceDataVector& stackTraceDataVector()