Skip to content

Commit

Permalink
Fix minor code defects
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 Aug 11, 2023
1 parent b09fdcb commit f56ea25
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/builtins/BuiltinArrayBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ static Value builtinArrayBufferConstructor(ExecutionState& state, Value thisValu
{
if (!newTarget.hasValue()) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}

uint64_t byteLength = argv[0].toIndex(state);
if (UNLIKELY(byteLength == Value::InvalidIndexValue)) {
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().ArrayBuffer.string(), false, String::emptyString, ErrorObject::Messages::GlobalObject_FirstArgumentInvalidLength);
return Value();
}

Optional<uint64_t> maxByteLength;
Expand Down
1 change: 1 addition & 0 deletions src/builtins/BuiltinDataView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static Value builtinDataViewConstructor(ExecutionState& state, Value thisValue,
{
if (!newTarget.hasValue()) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}
if (!(argv[0].isObject() && argv[0].asPointerValue()->isArrayBuffer())) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().DataView.string(), false, String::emptyString, ErrorObject::Messages::GlobalObject_ThisNotArrayBufferObject);
Expand Down
1 change: 1 addition & 0 deletions src/builtins/BuiltinFinalizationRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static Value builtinFinalizationRegistryConstructor(ExecutionState& state, Value
{
if (!newTarget.hasValue()) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}
if (argc == 0 || !argv[0].isCallable()) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "cleanup Callback is not callable");
Expand Down
5 changes: 5 additions & 0 deletions src/builtins/BuiltinIntl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ static Value builtinIntlPluralRulesConstructor(ExecutionState& state, Value this
// If NewTarget is undefined, throw a TypeError exception.
if (!newTarget) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}

#if defined(ENABLE_RUNTIME_ICU_BINDER)
Expand Down Expand Up @@ -570,6 +571,7 @@ static Value builtinIntlLocaleConstructor(ExecutionState& state, Value thisValue
// If NewTarget is undefined, throw a TypeError exception.
if (!newTarget) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}

Value tagValue = argv[0];
Expand Down Expand Up @@ -908,6 +910,7 @@ static Value builtinIntlRelativeTimeFormatConstructor(ExecutionState& state, Val
// If NewTarget is undefined, throw a TypeError exception.
if (!newTarget) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}

#if defined(ENABLE_RUNTIME_ICU_BINDER)
Expand Down Expand Up @@ -1002,6 +1005,7 @@ static Value builtinIntlDisplayNamesConstructor(ExecutionState& state, Value thi
// If NewTarget is undefined, throw a TypeError exception.
if (!newTarget) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}

Object* proto = Object::getPrototypeFromConstructor(state, newTarget.value(), [](ExecutionState& state, Context* realm) -> Object* {
Expand Down Expand Up @@ -1046,6 +1050,7 @@ static Value builtinIntlListFormatConstructor(ExecutionState& state, Value thisV
// If NewTarget is undefined, throw a TypeError exception.
if (!newTarget) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}

Object* proto = Object::getPrototypeFromConstructor(state, newTarget.value(), [](ExecutionState& state, Context* realm) -> Object* {
Expand Down
1 change: 1 addition & 0 deletions src/builtins/BuiltinMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static Value builtinMapConstructor(ExecutionState& state, Value thisValue, size_
{
if (!newTarget.hasValue()) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}

// Let map be ? OrdinaryCreateFromConstructor(NewTarget, "%MapPrototype%", « [[MapData]] »).
Expand Down
1 change: 1 addition & 0 deletions src/builtins/BuiltinSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static Value builtinSetConstructor(ExecutionState& state, Value thisValue, size_
// If NewTarget is undefined, throw a TypeError exception.
if (!newTarget.hasValue()) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}

// Let set be ? OrdinaryCreateFromConstructor(NewTarget, "%SetPrototype%", « [[SetData]] »).
Expand Down
1 change: 1 addition & 0 deletions src/builtins/BuiltinTypedArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ static Value builtinTypedArrayConstructor(ExecutionState& state, Value thisValue
uint64_t elemlen = firstArg.toIndex(state);
if (elemlen == Value::InvalidIndexValue) {
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().TypedArray.string(), false, String::emptyString, ErrorObject::Messages::GlobalObject_FirstArgumentInvalidLength);
return Value();
}
return TA::allocateTypedArray(state, newTarget.value(), elemlen);
}
Expand Down
1 change: 1 addition & 0 deletions src/builtins/BuiltinWeakMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static Value builtinWeakMapConstructor(ExecutionState& state, Value thisValue, s
{
if (!newTarget.hasValue()) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}

Object* proto = Object::getPrototypeFromConstructor(state, newTarget.value(), [](ExecutionState& state, Context* constructorRealm) -> Object* {
Expand Down
1 change: 1 addition & 0 deletions src/builtins/BuiltinWeakRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static Value builtinWeakRefConstructor(ExecutionState& state, Value thisValue, s
{
if (!newTarget.hasValue()) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}
if (argc == 0 || !argv[0].isObject()) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "target is not object");
Expand Down
1 change: 1 addition & 0 deletions src/builtins/BuiltinWeakSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static Value builtinWeakSetConstructor(ExecutionState& state, Value thisValue, s
{
if (!newTarget.hasValue()) {
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
return Value();
}

Object* proto = Object::getPrototypeFromConstructor(state, newTarget.value(), [](ExecutionState& state, Context* constructorRealm) -> Object* {
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/ByteCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ class End : public ByteCode {
#ifndef NDEBUG
void dump()
{
printf("end(return with r[%u])", m_registerIndex);
printf("end(return with r%u)", m_registerIndex);
}
#endif
};
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/ByteCodeInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3083,7 +3083,7 @@ NEVER_INLINE Value InterpreterSlowPath::tryOperation(ExecutionState*& state, siz
return Value();
}
} catch (const Value& val) {
stackTraceDataVector = newState->context()->vmInstance()->currentSandBox()->stackTraceDataVector();
stackTraceDataVector = std::move(newState->context()->vmInstance()->currentSandBox()->stackTraceDataVector());
newState->rareData()->m_controlFlowRecord->back() = new ControlFlowRecord(ControlFlowRecord::NeedsThrow, val);
}
}
Expand Down Expand Up @@ -3156,7 +3156,7 @@ NEVER_INLINE Value InterpreterSlowPath::tryOperation(ExecutionState*& state, siz
return Value(Value::EmptyValue);
}
} else if (record->reason() == ControlFlowRecord::NeedsThrow) {
state->context()->vmInstance()->currentSandBox()->rethrowPreviouslyCaughtException(*state, record->value(), stackTraceDataVector);
state->context()->vmInstance()->currentSandBox()->rethrowPreviouslyCaughtException(*state, record->value(), std::move(stackTraceDataVector));
ASSERT_NOT_REACHED();
// never get here. but I add return statement for removing compile warning
return Value(Value::EmptyValue);
Expand Down
1 change: 1 addition & 0 deletions src/parser/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Script* Script::loadModuleFromScript(ExecutionState& state, ModuleRequest& reque
Platform::LoadModuleResult result = Global::platform()->onLoadModule(context(), this, request.m_specifier, request.m_type);
if (!result.script) {
ErrorObject::throwBuiltinError(state, (ErrorCode)result.errorCode, result.errorMessage->toNonGCUTF8StringData().data());
return nullptr;
}
if (!result.script->moduleData()->m_didCallLoadedCallback) {
Global::platform()->didLoadModule(context(), this, result.script.value());
Expand Down
1 change: 1 addition & 0 deletions src/runtime/ExecutionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Object* ExecutionState::findPrivateMemberContextObject()
auto o = mostNearestHomeObject();
if (!o) {
ErrorObject::throwBuiltinError(*this, ErrorCode::TypeError, "Cannot read/write private member here");
return nullptr;
}
return convertHomeObjectIntoPrivateMemberContextObject(o.value());
}
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/ScriptClassConstructorFunctionObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ Value ScriptClassConstructorFunctionObject::construct(ExecutionState& state, con
// Return envRec.GetThisBinding().
// -> perform at ScriptClassConstructorFunctionObjectReturnValueBinderWithConstruct
return FunctionObjectProcessCallGenerator::processCall<ScriptClassConstructorFunctionObject, true, true, true, ScriptClassConstructorFunctionObjectThisValueBinder,
ScriptClassConstructorFunctionObjectNewTargetBinderWithConstruct, ScriptClassConstructorFunctionObjectReturnValueBinderWithConstruct>(state, this, thisArgument, argc, argv, newTarget)
.asObject();
ScriptClassConstructorFunctionObjectNewTargetBinderWithConstruct, ScriptClassConstructorFunctionObjectReturnValueBinderWithConstruct>(state, this, thisArgument, argc, argv, newTarget);
}

void ScriptClassConstructorFunctionObject::initInstanceFieldMembers(ExecutionState& state, Object* instance)
Expand Down

0 comments on commit f56ea25

Please sign in to comment.