From 29146da9f7b8158b076b5669a3a369fc50a7dbaa Mon Sep 17 00:00:00 2001 From: HyukWoo Park Date: Thu, 10 Aug 2023 09:41:07 +0900 Subject: [PATCH 1/2] Replace redundant sandbox runs with try-catch statement Signed-off-by: HyukWoo Park --- src/builtins/BuiltinPromise.cpp | 19 +++++----- src/runtime/FinalizationRegistryObject.cpp | 19 ++++------ src/runtime/Job.cpp | 43 +++++++++++----------- src/runtime/PromiseObject.cpp | 13 +++---- src/runtime/SandBox.cpp | 10 ++--- src/runtime/SandBox.h | 2 +- src/wasm/BuiltinWASM.cpp | 30 +++++++-------- 7 files changed, 62 insertions(+), 74 deletions(-) diff --git a/src/builtins/BuiltinPromise.cpp b/src/builtins/BuiltinPromise.cpp index a1109e552..7fd752083 100644 --- a/src/builtins/BuiltinPromise.cpp +++ b/src/builtins/BuiltinPromise.cpp @@ -37,6 +37,7 @@ static Value builtinPromiseConstructor(ExecutionState& state, Value thisValue, s auto strings = &state.context()->staticStrings(); if (!newTarget.hasValue()) { ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Promise.string(), false, String::emptyString, "%s: Promise constructor should be called with new Promise()"); + return Value(); } Value executor = argv[0]; @@ -59,15 +60,12 @@ static Value builtinPromiseConstructor(ExecutionState& state, Value thisValue, s state.context()->vmInstance()->triggerPromiseHook(state, VMInstance::PromiseHookType::Init, promise, (argc > 1) ? argv[1] : Value()); } - SandBox sb(state.context()); - auto res = sb.run([&]() -> Value { + try { Value arguments[] = { capability.m_resolveFunction, capability.m_rejectFunction }; Object::call(state, executor, Value(), 2, arguments); - return Value(); - }); - if (!res.error.isEmpty()) { - Value arguments[] = { res.error }; - Object::call(state, capability.m_rejectFunction, Value(), 1, arguments); + } catch (const Value& v) { + Value thrownValue = v; + Object::call(state, capability.m_rejectFunction, Value(), 1, &thrownValue); } return promise; @@ -567,6 +565,7 @@ static Value builtinPromiseAllSettled(ExecutionState& state, Value thisValue, si try { result = IteratorObject::iteratorClose(state, iteratorRecord, exceptionValue, true); } catch (const Value& v) { + exceptionValue = v; // IfAbruptRejectPromise(result, promiseCapability). // If value is an abrupt completion, // Perform ? Call(capability.[[Reject]], undefined, « value.[[Value]] »). @@ -609,7 +608,7 @@ static Value performPromiseAny(ExecutionState& state, IteratorRecord* iteratorRe next = IteratorObject::iteratorStep(state, iteratorRecord); } catch (const Value& v) { iteratorRecord->m_done = true; - throw v; + state.throwException(v); } // If next is false, then @@ -627,7 +626,7 @@ static Value performPromiseAny(ExecutionState& state, IteratorRecord* iteratorRe ObjectPropertyDescriptor(Object::createArrayFromList(state, *errors), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent | ObjectPropertyDescriptor::WritablePresent))); // Return ThrowCompletion(error). - throw Value(error); + state.throwException(error); } // Return resultCapability.[[Promise]]. return resultCapability.m_promise; @@ -641,7 +640,7 @@ static Value performPromiseAny(ExecutionState& state, IteratorRecord* iteratorRe // If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true. iteratorRecord->m_done = true; // ReturnIfAbrupt(nextValue). - throw v; + state.throwException(v); } // Append undefined to errors. errors->pushBack(Value()); diff --git a/src/runtime/FinalizationRegistryObject.cpp b/src/runtime/FinalizationRegistryObject.cpp index 974171be6..f6740fd13 100644 --- a/src/runtime/FinalizationRegistryObject.cpp +++ b/src/runtime/FinalizationRegistryObject.cpp @@ -178,18 +178,13 @@ void FinalizationRegistryObject::finalizer(Object* self, void* data) } if (!wasCallbackDeleted) { - SandBox sb(item->source->m_realm); - struct ExecutionData { - FinalizationRegistryObjectItem* item; - } ed; - ed.item = item; - sb.run([](ExecutionState& state, void* data) -> Value { - ExecutionData* ed = (ExecutionData*)data; - Value argv = ed->item->heldValue; - Object::call(state, ed->item->source->m_cleanupCallback.value(), Value(), 1, &argv); - return Value(); - }, - &ed); + try { + ExecutionState tempState(item->source->m_realm); + Value argv = item->heldValue; + Object::call(tempState, item->source->m_cleanupCallback.value(), Value(), 1, &argv); + } catch (const Value& v) { + // do nothing + } } } diff --git a/src/runtime/Job.cpp b/src/runtime/Job.cpp index 23d97c7de..42401eecf 100644 --- a/src/runtime/Job.cpp +++ b/src/runtime/Job.cpp @@ -64,26 +64,25 @@ SandBox::SandBoxResult PromiseReactionJob::run() return Object::call(state, m_reaction.m_capability.m_rejectFunction, Value(), 1, value); } - SandBox sb(state.context()); - auto res = sb.run([&]() -> Value { - Value arguments[] = { m_argument }; - Value res = Object::call(state, m_reaction.m_handler, Value(), 1, arguments); + Value res; + try { + Value argument = m_argument; + res = Object::call(state, m_reaction.m_handler, Value(), 1, &argument); // m_reaction.m_capability can be null when there was no result capability when promise.then() - if (m_reaction.m_capability.m_promise == nullptr) { - return Value(); + if (m_reaction.m_capability.m_promise != nullptr) { + Value value[] = { res }; + Object::call(state, m_reaction.m_capability.m_resolveFunction, Value(), 1, value); } - Value value[] = { res }; - return Object::call(state, m_reaction.m_capability.m_resolveFunction, Value(), 1, value); - }); - if (!res.error.isEmpty()) { + } catch (const Value& v) { + Value reason = v; if (m_reaction.m_capability.m_rejectFunction) { - Value reason[] = { res.error }; - return Object::call(state, m_reaction.m_capability.m_rejectFunction, Value(), 1, reason); + return Object::call(state, m_reaction.m_capability.m_rejectFunction, Value(), 1, &reason); } else { - state.throwException(res.error); + state.throwException(reason); } } - return res.result; + + return res; }); #ifdef ESCARGOT_DEBUGGER @@ -110,16 +109,16 @@ SandBox::SandBoxResult PromiseResolveThenableJob::run() auto strings = &state.context()->staticStrings(); PromiseReaction::Capability capability = m_promise->createResolvingFunctions(state); - SandBox sb(state.context()); - auto res = sb.run([&]() -> Value { + Value result; + try { Value arguments[] = { capability.m_resolveFunction, capability.m_rejectFunction }; - return Object::call(state, m_then, m_thenable, 2, arguments); - }); - if (!res.error.isEmpty()) { - Value reason[] = { res.error }; - return Object::call(state, capability.m_rejectFunction, Value(), 1, reason); + result = Object::call(state, m_then, m_thenable, 2, arguments); + } catch (const Value& v) { + Value reason = v; + return Object::call(state, capability.m_rejectFunction, Value(), 1, &reason); } - return res.result; + + return result; }); } diff --git a/src/runtime/PromiseObject.cpp b/src/runtime/PromiseObject.cpp index 714adb401..286a9576b 100644 --- a/src/runtime/PromiseObject.cpp +++ b/src/runtime/PromiseObject.cpp @@ -319,15 +319,14 @@ static Value promiseResolveFunctions(ExecutionState& state, Value thisValue, siz } Object* resolution = resolutionValue.asObject(); - SandBox sb(state.context()); - auto res = sb.run([&]() -> Value { - return resolution->get(state, strings->then).value(state, resolution); - }); - if (!res.error.isEmpty()) { - promise->reject(state, res.error); + Value then; + try { + then = resolution->get(state, strings->then).value(state, resolution); + } catch (const Value& v) { + Value reason = v; + promise->reject(state, reason); return Value(); } - Value then = res.result; if (then.isCallable()) { state.context()->vmInstance()->enqueueJob(new PromiseResolveThenableJob(state.context(), promise, resolution, then.asObject())); diff --git a/src/runtime/SandBox.cpp b/src/runtime/SandBox.cpp index 20df75899..c85c2481b 100644 --- a/src/runtime/SandBox.cpp +++ b/src/runtime/SandBox.cpp @@ -300,7 +300,7 @@ void SandBox::throwException(ExecutionState& state, const Value& exception) throw exception; } -void SandBox::rethrowPreviouslyCaughtException(ExecutionState& state, Value exception, const StackTraceDataVector& stackTraceDataVector) +void SandBox::rethrowPreviouslyCaughtException(ExecutionState& state, Value exception, StackTraceDataVector&& stackTraceDataVector) { m_stackTraceDataVector = stackTraceDataVector; // update stack trace data if needs @@ -353,8 +353,7 @@ void ErrorObject::StackTraceData::buildStackTrace(Context* context, StringBuilde { if (exception.isObject()) { ExecutionState state(context); - SandBox sb(context); - sb.run([&]() -> Value { + try { auto getResult = exception.asObject()->get(state, state.context()->staticStrings().name); if (getResult.hasValue()) { builder.appendString(getResult.value(state, exception.asObject()).toString(state)); @@ -365,8 +364,9 @@ void ErrorObject::StackTraceData::buildStackTrace(Context* context, StringBuilde builder.appendString(getResult.value(state, exception.asObject()).toString(state)); builder.appendChar('\n'); } - return Value(); - }); + } catch (const Value& v) { + // ignore exception + } } ByteCodeLOCDataMap locMap; diff --git a/src/runtime/SandBox.h b/src/runtime/SandBox.h index 392abffb3..49fe6a663 100644 --- a/src/runtime/SandBox.h +++ b/src/runtime/SandBox.h @@ -86,7 +86,7 @@ class SandBox : public gc { static bool createStackTrace(StackTraceDataVector& stackTraceDataVector, ExecutionState& state, bool stopAtPause = false); void throwException(ExecutionState& state, const Value& exception); - void rethrowPreviouslyCaughtException(ExecutionState& state, Value exception, const StackTraceDataVector& stackTraceDataVector); + void rethrowPreviouslyCaughtException(ExecutionState& state, Value exception, StackTraceDataVector&& stackTraceDataVector); StackTraceDataVector& stackTraceDataVector() { diff --git a/src/wasm/BuiltinWASM.cpp b/src/wasm/BuiltinWASM.cpp index 7bdb1cf77..d78b39c31 100644 --- a/src/wasm/BuiltinWASM.cpp +++ b/src/wasm/BuiltinWASM.cpp @@ -161,8 +161,7 @@ static Value builtinWASMInstantiate(ExecutionState& state, Value thisValue, size // Read the imports of module with imports importObject, and let imports be the result. If this operation throws an exception, catch it, reject promise with the exception, and return promise. own wasm_extern_vec_t imports; - SandBox sb(state.context()); - auto readImportsResult = sb.run([&]() -> Value { + try { Value moduleValue = firstArg; if (!moduleValue.isObject() || !moduleValue.asObject()->isWASMModuleObject()) { ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::WASM_InstantiateModuleError); @@ -175,24 +174,21 @@ static Value builtinWASMInstantiate(ExecutionState& state, Value thisValue, size // Read the imports of module with imports importObject, and let imports be the result. wasm_extern_vec_new_empty(&imports); WASMOperations::readImportsOfModule(state, module, importObj, &imports); - - return Value(); - }); - - if (!readImportsResult.error.isEmpty()) { + } catch (const Value& v) { // If this operation throws an exception, catch it, reject promise with the exception. - Value reason[] = { readImportsResult.error }; - Object::call(state, capability.m_rejectFunction, Value(), 1, reason); - } else { - // Note) pass imports data and its size into ExtendedNativeFunctionObjectImpl and delete imports vector inside ExtendedNativeFunctionObjectImpl call - auto moduleInstantiator = new ExtendedNativeFunctionObjectImpl<2>(state, NativeFunctionInfo(AtomicString(), WASMOperations::instantiateCoreModule, 1, NativeFunctionInfo::Strict)); - moduleInstantiator->setInternalSlot(0, Value(imports.size)); - moduleInstantiator->setInternalSlotAsPointer(1, imports.data); - - Job* job = new PromiseReactionJob(state.context(), PromiseReaction(moduleInstantiator, capability), firstArg); - state.context()->vmInstance()->enqueueJob(job); + Value reason = v; + Object::call(state, capability.m_rejectFunction, Value(), 1, &reason); + return capability.m_promise; } + // Note) pass imports data and its size into ExtendedNativeFunctionObjectImpl and delete imports vector inside ExtendedNativeFunctionObjectImpl call + auto moduleInstantiator = new ExtendedNativeFunctionObjectImpl<2>(state, NativeFunctionInfo(AtomicString(), WASMOperations::instantiateCoreModule, 1, NativeFunctionInfo::Strict)); + moduleInstantiator->setInternalSlot(0, Value(imports.size)); + moduleInstantiator->setInternalSlotAsPointer(1, imports.data); + + Job* job = new PromiseReactionJob(state.context(), PromiseReaction(moduleInstantiator, capability), firstArg); + state.context()->vmInstance()->enqueueJob(job); + return capability.m_promise; } From 8f9ee3d94edce1478962b71f84eb3d377281d999 Mon Sep 17 00:00:00 2001 From: HyukWoo Park Date: Thu, 10 Aug 2023 09:41:36 +0900 Subject: [PATCH 2/2] Fix minor code defects Signed-off-by: HyukWoo Park --- src/builtins/BuiltinArrayBuffer.cpp | 2 ++ src/builtins/BuiltinDataView.cpp | 1 + src/builtins/BuiltinFinalizationRegistry.cpp | 1 + src/builtins/BuiltinIntl.cpp | 5 +++++ src/builtins/BuiltinMap.cpp | 1 + src/builtins/BuiltinSet.cpp | 1 + src/builtins/BuiltinTypedArray.cpp | 1 + src/builtins/BuiltinWeakMap.cpp | 1 + src/builtins/BuiltinWeakRef.cpp | 1 + src/builtins/BuiltinWeakSet.cpp | 1 + src/interpreter/ByteCode.h | 2 +- src/interpreter/ByteCodeInterpreter.cpp | 4 ++-- src/parser/Script.cpp | 1 + src/runtime/ExecutionState.cpp | 1 + src/runtime/ScriptClassConstructorFunctionObject.cpp | 3 +-- 15 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/builtins/BuiltinArrayBuffer.cpp b/src/builtins/BuiltinArrayBuffer.cpp index 915c9e608..1655b1096 100644 --- a/src/builtins/BuiltinArrayBuffer.cpp +++ b/src/builtins/BuiltinArrayBuffer.cpp @@ -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 maxByteLength; diff --git a/src/builtins/BuiltinDataView.cpp b/src/builtins/BuiltinDataView.cpp index 8f620756e..19e60fca9 100644 --- a/src/builtins/BuiltinDataView.cpp +++ b/src/builtins/BuiltinDataView.cpp @@ -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); diff --git a/src/builtins/BuiltinFinalizationRegistry.cpp b/src/builtins/BuiltinFinalizationRegistry.cpp index 66a81a6d7..64845d0a2 100644 --- a/src/builtins/BuiltinFinalizationRegistry.cpp +++ b/src/builtins/BuiltinFinalizationRegistry.cpp @@ -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"); diff --git a/src/builtins/BuiltinIntl.cpp b/src/builtins/BuiltinIntl.cpp index 1d7243871..2048b79ea 100644 --- a/src/builtins/BuiltinIntl.cpp +++ b/src/builtins/BuiltinIntl.cpp @@ -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) @@ -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]; @@ -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) @@ -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* { @@ -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* { diff --git a/src/builtins/BuiltinMap.cpp b/src/builtins/BuiltinMap.cpp index 5077e4d75..56894d4f9 100644 --- a/src/builtins/BuiltinMap.cpp +++ b/src/builtins/BuiltinMap.cpp @@ -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]] »). diff --git a/src/builtins/BuiltinSet.cpp b/src/builtins/BuiltinSet.cpp index bb1d42c2d..efec19e3d 100644 --- a/src/builtins/BuiltinSet.cpp +++ b/src/builtins/BuiltinSet.cpp @@ -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]] »). diff --git a/src/builtins/BuiltinTypedArray.cpp b/src/builtins/BuiltinTypedArray.cpp index 719e547ae..1142c5cba 100644 --- a/src/builtins/BuiltinTypedArray.cpp +++ b/src/builtins/BuiltinTypedArray.cpp @@ -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); } diff --git a/src/builtins/BuiltinWeakMap.cpp b/src/builtins/BuiltinWeakMap.cpp index ae8c1e960..6f9d565bc 100644 --- a/src/builtins/BuiltinWeakMap.cpp +++ b/src/builtins/BuiltinWeakMap.cpp @@ -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* { diff --git a/src/builtins/BuiltinWeakRef.cpp b/src/builtins/BuiltinWeakRef.cpp index 64a0b8915..72107ccee 100644 --- a/src/builtins/BuiltinWeakRef.cpp +++ b/src/builtins/BuiltinWeakRef.cpp @@ -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"); diff --git a/src/builtins/BuiltinWeakSet.cpp b/src/builtins/BuiltinWeakSet.cpp index 0fdffb6aa..6b981e3e8 100644 --- a/src/builtins/BuiltinWeakSet.cpp +++ b/src/builtins/BuiltinWeakSet.cpp @@ -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* { diff --git a/src/interpreter/ByteCode.h b/src/interpreter/ByteCode.h index 8f8bb854f..2179e686f 100644 --- a/src/interpreter/ByteCode.h +++ b/src/interpreter/ByteCode.h @@ -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 }; diff --git a/src/interpreter/ByteCodeInterpreter.cpp b/src/interpreter/ByteCodeInterpreter.cpp index c15d28e87..1b136ce85 100644 --- a/src/interpreter/ByteCodeInterpreter.cpp +++ b/src/interpreter/ByteCodeInterpreter.cpp @@ -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); } } @@ -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); diff --git a/src/parser/Script.cpp b/src/parser/Script.cpp index 76b74c139..3f50cb240 100644 --- a/src/parser/Script.cpp +++ b/src/parser/Script.cpp @@ -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()); diff --git a/src/runtime/ExecutionState.cpp b/src/runtime/ExecutionState.cpp index f91b068b9..c530056ce 100644 --- a/src/runtime/ExecutionState.cpp +++ b/src/runtime/ExecutionState.cpp @@ -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()); } diff --git a/src/runtime/ScriptClassConstructorFunctionObject.cpp b/src/runtime/ScriptClassConstructorFunctionObject.cpp index aa478e065..e32efdb2f 100644 --- a/src/runtime/ScriptClassConstructorFunctionObject.cpp +++ b/src/runtime/ScriptClassConstructorFunctionObject.cpp @@ -146,8 +146,7 @@ Value ScriptClassConstructorFunctionObject::construct(ExecutionState& state, con // Return envRec.GetThisBinding(). // -> perform at ScriptClassConstructorFunctionObjectReturnValueBinderWithConstruct return FunctionObjectProcessCallGenerator::processCall(state, this, thisArgument, argc, argv, newTarget) - .asObject(); + ScriptClassConstructorFunctionObjectNewTargetBinderWithConstruct, ScriptClassConstructorFunctionObjectReturnValueBinderWithConstruct>(state, this, thisArgument, argc, argv, newTarget); } void ScriptClassConstructorFunctionObject::initInstanceFieldMembers(ExecutionState& state, Object* instance)