Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor code updates #1263

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 15 additions & 2 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 Expand Up @@ -3403,7 +3415,8 @@ ValueRef* ValueRef::createUndefined()

bool ValueRef::toBoolean(ExecutionStateRef* es)
{
return toImpl(this).toBoolean(*toImpl(es));
UNUSED_PARAMETER(es);
return toImpl(this).toBoolean();
}

double ValueRef::toNumber(ExecutionStateRef* es)
Expand Down Expand Up @@ -3699,7 +3712,7 @@ BooleanObjectRef* BooleanObjectRef::create(ExecutionStateRef* state)

void BooleanObjectRef::setPrimitiveValue(ExecutionStateRef* state, ValueRef* str)
{
toImpl(this)->setPrimitiveValue(*toImpl(state), toImpl(str).toBoolean(*toImpl(state)));
toImpl(this)->setPrimitiveValue(*toImpl(state), toImpl(str).toBoolean());
}

bool BooleanObjectRef::primitiveValue()
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
14 changes: 7 additions & 7 deletions src/builtins/BuiltinArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ static Value builtinArrayEvery(ExecutionState& state, Value thisValue, size_t ar
Value args[] = { kValue, Value(k), O };
Value testResult = Object::call(state, callbackfn, T, 3, args);

if (!testResult.toBoolean(state)) {
if (!testResult.toBoolean()) {
return Value(false);
}

Expand Down Expand Up @@ -1079,7 +1079,7 @@ static Value builtinArrayFilter(ExecutionState& state, Value thisValue, size_t a
Value selected = Object::call(state, callbackfn, T, 3, v);

// If ToBoolean(selected) is true, then
if (selected.toBoolean(state)) {
if (selected.toBoolean()) {
// Let status be CreateDataPropertyOrThrow (A, ToString(to), kValue).
ASSERT(A != nullptr);
A->defineOwnPropertyThrowsException(state, ObjectPropertyName(state, Value(to)), ObjectPropertyDescriptor(kValue, ObjectPropertyDescriptor::AllPresent));
Expand Down Expand Up @@ -1188,7 +1188,7 @@ static Value builtinArraySome(ExecutionState& state, Value thisValue, size_t arg
Value argv[] = { kValue, Value(k), O };
Value testResult = Object::call(state, callbackfn, T, 3, argv);
// If ToBoolean(testResult) is true, return true.
if (testResult.toBoolean(state)) {
if (testResult.toBoolean()) {
return Value(true);
}
} else {
Expand Down Expand Up @@ -1699,7 +1699,7 @@ static Value builtinArrayFind(ExecutionState& state, Value thisValue, size_t arg
Value kValue = O->get(state, ObjectPropertyName(state, Value(k))).value(state, O);
// Let testResult be ToBoolean(? Call(predicate, thisArg, « kValue, k, O »)).
Value v[] = { kValue, Value(k), O };
bool testResult = Object::call(state, argv[0], thisArg, 3, v).toBoolean(state);
bool testResult = Object::call(state, argv[0], thisArg, 3, v).toBoolean();
// If testResult is true, return kValue.
if (testResult) {
return kValue;
Expand Down Expand Up @@ -1734,7 +1734,7 @@ static Value builtinArrayFindIndex(ExecutionState& state, Value thisValue, size_
Value kValue = O->get(state, ObjectPropertyName(state, Value(k))).value(state, O);
// Let testResult be ToBoolean(? Call(predicate, thisArg, « kValue, k, O »)).
Value v[] = { kValue, Value(k), O };
bool testResult = Object::call(state, argv[0], thisArg, 3, v).toBoolean(state);
bool testResult = Object::call(state, argv[0], thisArg, 3, v).toBoolean();
// If testResult is true, return k.
if (testResult) {
return Value(k);
Expand Down Expand Up @@ -1874,7 +1874,7 @@ static Value builtinArrayFindLast(ExecutionState& state, Value thisValue, size_t
Value predicateArgv[] = {
kValue, Value(k), Value(O)
};
bool testResult = Object::call(state, predicate, thisArg, 3, predicateArgv).toBoolean(state);
bool testResult = Object::call(state, predicate, thisArg, 3, predicateArgv).toBoolean();
// d. If testResult is true, return kValue.
if (testResult) {
return kValue;
Expand Down Expand Up @@ -1910,7 +1910,7 @@ static Value builtinArrayFindLastIndex(ExecutionState& state, Value thisValue, s
Value predicateArgv[] = {
kValue, Value(k), Value(O)
};
bool testResult = Object::call(state, predicate, thisArg, 3, predicateArgv).toBoolean(state);
bool testResult = Object::call(state, predicate, thisArg, 3, predicateArgv).toBoolean();
// d. If testResult is true, return kValue.
if (testResult) {
return Value(k);
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/BuiltinBoolean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Escargot {

static Value builtinBooleanConstructor(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
{
bool primitiveVal = argv[0].toBoolean(state);
bool primitiveVal = argv[0].toBoolean();
if (!newTarget.hasValue()) {
return Value(primitiveVal);
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/builtins/BuiltinRegExp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ static Value builtinRegExpReplace(ExecutionState& state, Value thisValue, size_t
if (!functionalReplace) {
replaceValue = replaceValue.toString(state);
}
bool global = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().global)).value(state, rx).toBoolean(state);
bool global = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().global)).value(state, rx).toBoolean();
if (global) {
fullUnicode = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().unicode)).value(state, rx).toBoolean(state);
fullUnicode = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().unicode)).value(state, rx).toBoolean();
rx.asObject()->setThrowsException(state, ObjectPropertyName(state, state.context()->staticStrings().lastIndex), Value(0), rx);
}
ValueVectorWithInlineStorage results;
Expand Down Expand Up @@ -509,13 +509,13 @@ static Value builtinRegExpMatch(ExecutionState& state, Value thisValue, size_t a
ASSERT(str != nullptr);

//21.2.5.6.8
bool global = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().global)).value(state, rx).toBoolean(state);
bool global = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().global)).value(state, rx).toBoolean();

if (!global) {
return regExpExec(state, rx.asObject(), str);
}

bool fullUnicode = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().unicode)).value(state, rx).toBoolean(state);
bool fullUnicode = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().unicode)).value(state, rx).toBoolean();
rx.asObject()->setThrowsException(state, ObjectPropertyName(state, state.context()->staticStrings().lastIndex), Value(0), rx);
ArrayObject* A = new ArrayObject(state);
size_t n = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/builtins/BuiltinTypedArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ static Value builtinTypedArraySome(ExecutionState& state, Value thisValue, size_
Value testResult = Object::call(state, callbackfn, T, 3, args);

// If ToBoolean(testResult) is true, return true.
if (testResult.toBoolean(state)) {
if (testResult.toBoolean()) {
return Value(true);
}

Expand Down Expand Up @@ -1002,7 +1002,7 @@ static Value builtinTypedArrayEvery(ExecutionState& state, Value thisValue, size
Value args[] = { kValue, Value(k), O };
Value testResult = Object::call(state, callbackfn, T, 3, args);

if (!testResult.toBoolean(state)) {
if (!testResult.toBoolean()) {
return Value(false);
}

Expand Down Expand Up @@ -1091,7 +1091,7 @@ static Value builtinTypedArrayFilter(ExecutionState& state, Value thisValue, siz
while (k < len) {
Value kValue = O->getIndexedProperty(state, Value(k)).value(state, O);
Value args[] = { kValue, Value(k), O };
bool selected = Object::call(state, callbackfn, T, 3, args).toBoolean(state);
bool selected = Object::call(state, callbackfn, T, 3, args).toBoolean();
if (selected) {
kept.push_back(kValue);
captured++;
Expand Down Expand Up @@ -1140,7 +1140,7 @@ static Value builtinTypedArrayFind(ExecutionState& state, Value thisValue, size_
Value kValue = O->getIndexedProperty(state, Value(k)).value(state, O);
// Let testResult be ToBoolean(Call(predicate, thisArg, «kValue, k, O»)).
Value args[] = { kValue, Value(k), O };
bool testResult = Object::call(state, predicate, thisArg, 3, args).toBoolean(state);
bool testResult = Object::call(state, predicate, thisArg, 3, args).toBoolean();
// If testResult is true, return kValue.
if (testResult) {
return kValue;
Expand Down Expand Up @@ -1179,7 +1179,7 @@ static Value builtinTypedArrayFindIndex(ExecutionState& state, Value thisValue,
Value kValue = O->getIndexedProperty(state, Value(k)).value(state, O);
// Let testResult be ToBoolean(? Call(predicate, thisArg, « kValue, k, O »)).
Value args[] = { kValue, Value(k), O };
bool testResult = Object::call(state, predicate, thisArg, 3, args).toBoolean(state);
bool testResult = Object::call(state, predicate, thisArg, 3, args).toBoolean();
// If testResult is true, return k.
if (testResult) {
return Value(k);
Expand Down Expand Up @@ -1217,7 +1217,7 @@ static Value builtinTypedArrayFindLast(ExecutionState& state, Value thisValue, s
kValue = O->getIndexedProperty(state, Value(k)).value(state, O);
// Let testResult be ToBoolean(Call(predicate, thisArg, «kValue, k, O»)).
Value args[] = { kValue, Value(k), O };
bool testResult = Object::call(state, predicate, thisArg, 3, args).toBoolean(state);
bool testResult = Object::call(state, predicate, thisArg, 3, args).toBoolean();
// If testResult is true, return kValue.
if (testResult) {
return kValue;
Expand Down Expand Up @@ -1255,7 +1255,7 @@ static Value builtinTypedArrayFindLastIndex(ExecutionState& state, Value thisVal
Value kValue = O->getIndexedProperty(state, Value(k)).value(state, O);
// Let testResult be ToBoolean(? Call(predicate, thisArg, « kValue, k, O »)).
Value args[] = { kValue, Value(k), O };
bool testResult = Object::call(state, predicate, thisArg, 3, args).toBoolean(state);
bool testResult = Object::call(state, predicate, thisArg, 3, args).toBoolean();
// If testResult is true, return k.
if (testResult) {
return Value(k);
Expand Down
22 changes: 17 additions & 5 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 @@ -544,7 +546,7 @@ Value Interpreter::interpret(ExecutionState* state, ByteCodeBlock* byteCodeBlock
{
UnaryNot* code = (UnaryNot*)programCounter;
const Value& val = registerFile[code->m_srcIndex];
registerFile[code->m_dstIndex] = Value(!val.toBoolean(*state));
registerFile[code->m_dstIndex] = Value(!val.toBoolean());
ADD_PROGRAM_COUNTER(UnaryNot);
NEXT_INSTRUCTION();
}
Expand Down Expand Up @@ -692,7 +694,7 @@ Value Interpreter::interpret(ExecutionState* state, ByteCodeBlock* byteCodeBlock
{
JumpIfTrue* code = (JumpIfTrue*)programCounter;
ASSERT(code->m_jumpPosition != SIZE_MAX);
if (registerFile[code->m_registerIndex].toBoolean(*state)) {
if (registerFile[code->m_registerIndex].toBoolean()) {
programCounter = code->m_jumpPosition;
} else {
ADD_PROGRAM_COUNTER(JumpIfTrue);
Expand Down Expand Up @@ -720,7 +722,7 @@ Value Interpreter::interpret(ExecutionState* state, ByteCodeBlock* byteCodeBlock
{
JumpIfFalse* code = (JumpIfFalse*)programCounter;
ASSERT(code->m_jumpPosition != SIZE_MAX);
if (!registerFile[code->m_registerIndex].toBoolean(*state)) {
if (!registerFile[code->m_registerIndex].toBoolean()) {
programCounter = code->m_jumpPosition;
} else {
ADD_PROGRAM_COUNTER(JumpIfFalse);
Expand Down Expand Up @@ -1771,7 +1773,7 @@ NEVER_INLINE void InterpreterSlowPath::resolveNameAddress(ExecutionState& state,
ObjectPropertyName propertyName(code->m_name);
auto obj = env->record()->asObjectEnvironmentRecord()->bindingObject();
Value unscopables = obj->get(state, ObjectPropertyName(state.context()->vmInstance()->globalSymbols().unscopables)).value(state, obj);
if (UNLIKELY(unscopables.isObject() && unscopables.asObject()->get(state, propertyName).value(state, unscopables).toBoolean(state))) {
if (UNLIKELY(unscopables.isObject() && unscopables.asObject()->get(state, propertyName).value(state, unscopables).toBoolean())) {
foundUnscopables = true;
}
}
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 Expand Up @@ -4516,7 +4528,7 @@ NEVER_INLINE void InterpreterSlowPath::iteratorOperation(ExecutionState& state,
registerFile[code->m_iteratorTestDoneData.m_iteratorRecordOrObjectRegisterIndex].asPointerValue()->asIteratorRecord()->m_done);
} else {
registerFile[code->m_iteratorTestDoneData.m_dstRegisterIndex] = Value(
registerFile[code->m_iteratorTestDoneData.m_iteratorRecordOrObjectRegisterIndex].asObject()->get(state, state.context()->staticStrings().done).value(state, registerFile[code->m_iteratorTestDoneData.m_iteratorRecordOrObjectRegisterIndex]).toBoolean(state));
registerFile[code->m_iteratorTestDoneData.m_iteratorRecordOrObjectRegisterIndex].asObject()->get(state, state.context()->staticStrings().done).value(state, registerFile[code->m_iteratorTestDoneData.m_iteratorRecordOrObjectRegisterIndex]).toBoolean());
}
ADD_PROGRAM_COUNTER(IteratorOperation);
} else if (code->m_operation == IteratorOperation::Operation::IteratorNext) {
Expand Down
2 changes: 1 addition & 1 deletion src/intl/Intl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,7 @@ Value Intl::getOption(ExecutionState& state, Object* options, Value property, In
// Assert: type is "boolean" or "string".
// If type is "boolean", then let value be ToBoolean(value).
if (type == Intl::OptionValueType::BooleanValue) {
value = Value(value.toBoolean(state));
value = Value(value.toBoolean());
}
// If type is "string", then let value be ToString(value).
if (type == Intl::OptionValueType::StringValue) {
Expand Down
Loading