mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-22 10:01:50 +00:00
Fix errors (#467)
* Fix BDWGC compile option * Fix build error on ndk * Global declared function declaration should always create binding Signed-off-by: seonghyun kim <sh8281.kim@samsung.com>
This commit is contained in:
parent
ba4631ae02
commit
355c7eff53
11 changed files with 41 additions and 25 deletions
|
|
@ -74,6 +74,8 @@ SET (ESCARGOT_BDWGC_CFLAGS ${ESCARGOT_BDWGC_CFLAGS} -DGC_GCJ_SUPPORT=1 -DGC_NO_T
|
|||
SET (ESCARGOT_BDWGC_CFLAGS ${ESCARGOT_BDWGC_CFLAGS} -DHAVE_DLADDR=1 -DHAVE_DLFCN_H=1 -DHAVE_DL_ITERATE_PHDR=1 -DHAVE_INTTYPES_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STDINT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRINGS_H=1)
|
||||
SET (ESCARGOT_BDWGC_CFLAGS ${ESCARGOT_BDWGC_CFLAGS} -DHAVE_STRING_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1)
|
||||
SET (ESCARGOT_BDWGC_CFLAGS ${ESCARGOT_BDWGC_CFLAGS} -DIGNORE_DYNAMIC_LOADING=1 -DJAVA_FINALIZATION=1 -DLARGE_CONFIG=1 -DMUNMAP_THRESHOLD=1 -DNO_EXECUTE_PERMISSION=1 -DSTDC_HEADERS=1 -DUSE_MMAP=1 -DUSE_MUNMAP=1)
|
||||
SET (ESCARGOT_BDWGC_CFLAGS ${ESCARGOT_BDWGC_CFLAGS} -DHAVE_PTHREAD_GETATTR_NP=1 -DUSE_GET_STACKBASE_FOR_MAIN=1)
|
||||
|
||||
IF (${ESCARGOT_MODE} STREQUAL "debug")
|
||||
SET (ESCARGOT_BDWGC_CFLAGS ${ESCARGOT_BDWGC_CFLAGS} -DKEEP_BACK_PTRS=1 -DSAVE_CALL_COUNT=8 -DDBG_HDRS_ALL=1 -DGC_DEBUG -O0)
|
||||
ELSEIF (${ESCARGOT_MODE} STREQUAL "release")
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ void Memory::setEventEventListener(OnGCEventListener l)
|
|||
}
|
||||
|
||||
// I store ref count as SmallValue. this can prevent what bdwgc can see ref count as address (SmallValue store integer value as odd)
|
||||
using PersistentValueRefMapImpl = std::unordered_map<ValueRef*, SmallValue, std::hash<void*>, std::equal_to<void*>, GCUtil::gc_malloc_allocator<std::pair<ValueRef*, SmallValue>>>;
|
||||
using PersistentValueRefMapImpl = std::unordered_map<ValueRef*, SmallValue, std::hash<void*>, std::equal_to<void*>, GCUtil::gc_malloc_allocator<std::pair<ValueRef* const, SmallValue>>>;
|
||||
|
||||
PersistentRefHolder<PersistentValueRefMap> PersistentValueRefMap::create()
|
||||
{
|
||||
|
|
@ -545,15 +545,22 @@ Evaluator::StackTraceData::StackTraceData()
|
|||
Evaluator::EvaluatorResult::EvaluatorResult()
|
||||
: result()
|
||||
, error()
|
||||
, resultOrErrorAsString(toRef(String::emptyString))
|
||||
{
|
||||
}
|
||||
|
||||
StringRef* Evaluator::EvaluatorResult::resultOrErrorToString(ContextRef* ctx) const
|
||||
{
|
||||
if (isSuccessful()) {
|
||||
return result->toStringWithoutException(ctx);
|
||||
} else {
|
||||
return ((ValueRef*)error.value())->toStringWithoutException(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
static Evaluator::EvaluatorResult toEvaluatorResultRef(SandBox::SandBoxResult& result)
|
||||
{
|
||||
Evaluator::EvaluatorResult r;
|
||||
r.error = toOptionalValue(result.error);
|
||||
r.resultOrErrorAsString = toRef(result.resultOrErrorAsString);
|
||||
r.result = toRef(result.result);
|
||||
|
||||
if (!result.error.isEmpty()) {
|
||||
|
|
@ -1664,10 +1671,10 @@ StringRef* ValueRef::toString(ExecutionStateRef* es)
|
|||
return toRef(toImpl(this).toString(*esi));
|
||||
}
|
||||
|
||||
StringRef* ValueRef::toStringWithoutException(ExecutionStateRef* es)
|
||||
StringRef* ValueRef::toStringWithoutException(ContextRef* ctx)
|
||||
{
|
||||
ExecutionState* esi = toImpl(es);
|
||||
return toRef(toImpl(this).toStringWithoutException(*esi));
|
||||
ExecutionState state(toImpl(ctx));
|
||||
return toRef(toImpl(this).toStringWithoutException(state));
|
||||
}
|
||||
|
||||
ObjectRef* ValueRef::toObject(ExecutionStateRef* es)
|
||||
|
|
|
|||
|
|
@ -473,14 +473,15 @@ public:
|
|||
|
||||
struct EvaluatorResult {
|
||||
EvaluatorResult();
|
||||
bool isSuccessful()
|
||||
bool isSuccessful() const
|
||||
{
|
||||
return !error.hasValue();
|
||||
}
|
||||
|
||||
StringRef* resultOrErrorToString(ContextRef* ctx) const;
|
||||
|
||||
ValueRef* result;
|
||||
OptionalRef<ValueRef> error;
|
||||
StringRef* resultOrErrorAsString;
|
||||
GCManagedVector<StackTraceData> stackTraceData;
|
||||
};
|
||||
|
||||
|
|
@ -665,7 +666,7 @@ public:
|
|||
uint32_t toUint32(ExecutionStateRef* state);
|
||||
StringRef* toString(ExecutionStateRef* state);
|
||||
// we never throw exception in this function but returns "Error while converting to string, but do not throw an exception" string
|
||||
StringRef* toStringWithoutException(ExecutionStateRef* state);
|
||||
StringRef* toStringWithoutException(ContextRef* ctx);
|
||||
ObjectRef* toObject(ExecutionStateRef* state);
|
||||
|
||||
enum : uint32_t { InvalidIndexValue = std::numeric_limits<uint32_t>::max() };
|
||||
|
|
|
|||
|
|
@ -486,6 +486,17 @@ Value Script::execute(ExecutionState& state, bool isExecuteOnEvalFunction, bool
|
|||
}
|
||||
|
||||
if (!isExecuteOnEvalFunction) {
|
||||
InterpretedCodeBlock* child = m_topCodeBlock->firstChild();
|
||||
while (child) {
|
||||
if (child->isFunctionDeclaration()) {
|
||||
if (!state.context()->globalObject()->defineOwnProperty(state, child->functionName(),
|
||||
ObjectPropertyDescriptor(Value(), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectStructurePropertyDescriptor::EnumerablePresent)))) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorObject::Code::SyntaxError, "Identifier '%s' has already been declared", child->functionName());
|
||||
}
|
||||
}
|
||||
child = child->nextSibling();
|
||||
}
|
||||
|
||||
const auto& globalLexicalVector = m_topCodeBlock->blockInfo(0)->m_identifiers;
|
||||
size_t len = globalLexicalVector.size();
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ private:
|
|||
IdentifierRecordVector m_globalDeclarativeRecord;
|
||||
SmallValueVector m_globalDeclarativeStorage;
|
||||
std::unordered_map<AtomicString, GlobalVariableAccessCacheItem*, std::hash<AtomicString>, std::equal_to<AtomicString>,
|
||||
GCUtil::gc_malloc_allocator<std::pair<AtomicString, GlobalVariableAccessCacheItem*>>>
|
||||
GCUtil::gc_malloc_allocator<std::pair<AtomicString const, GlobalVariableAccessCacheItem*>>>
|
||||
m_globalVariableAccessCache;
|
||||
LoadedModuleVector m_loadedModules;
|
||||
Vector<CodeBlock*, GCUtil::gc_malloc_allocator<CodeBlock*>>& m_compiledCodeBlocks;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public:
|
|||
bool isLittleEndian = _isLittleEndian.toBoolean(state);
|
||||
|
||||
ArrayBufferObject* buffer = this->buffer();
|
||||
if (buffer->isDetachedBuffer())
|
||||
if (!buffer && buffer->isDetachedBuffer())
|
||||
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().DataView.string(), false, String::emptyString, errorMessage_GlobalObject_DetachedBuffer);
|
||||
|
||||
unsigned viewOffset = byteOffset();
|
||||
|
|
@ -109,7 +109,7 @@ public:
|
|||
bool isLittleEndian = _isLittleEndian.toBoolean(state);
|
||||
|
||||
ArrayBufferObject* buffer = this->buffer();
|
||||
if (buffer->isDetachedBuffer())
|
||||
if (!buffer && buffer->isDetachedBuffer())
|
||||
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().DataView.string(), false, String::emptyString, errorMessage_GlobalObject_DetachedBuffer);
|
||||
|
||||
unsigned viewOffset = byteOffset();
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ static ArrayBufferObject* validateTypedArray(ExecutionState& state, Object* this
|
|||
|
||||
auto wrapper = thisObject->asArrayBufferView();
|
||||
ArrayBufferObject* buffer = wrapper->buffer();
|
||||
if (buffer->isDetachedBuffer()) {
|
||||
if (!buffer && buffer->isDetachedBuffer()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().TypedArray.string(), true, func, errorMessage_GlobalObject_DetachedBuffer);
|
||||
}
|
||||
return buffer;
|
||||
|
|
@ -341,7 +341,9 @@ static Value builtinTypedArrayLengthGetter(ExecutionState& state, Value thisValu
|
|||
static Value builtinTypedArrayBufferGetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
|
||||
{
|
||||
if (LIKELY(thisValue.isPointerValue() && thisValue.asPointerValue()->isTypedArrayObject())) {
|
||||
return Value(thisValue.asObject()->asArrayBufferView()->buffer());
|
||||
if (thisValue.asObject()->asArrayBufferView()->buffer()) {
|
||||
return Value(thisValue.asObject()->asArrayBufferView()->buffer());
|
||||
}
|
||||
}
|
||||
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, "get TypedArray.prototype.buffer called on incompatible receiver");
|
||||
RELEASE_ASSERT_NOT_REACHED();
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ void SandBox::processCatch(const Value& error, SandBoxResult& result)
|
|||
// this is to avoid dereferencing of null pointer.
|
||||
result.result = Value();
|
||||
result.error = error;
|
||||
result.resultOrErrorAsString = result.error.toStringWithoutException(state);
|
||||
|
||||
fillStackDataIntoErrorObject(error);
|
||||
|
||||
|
|
@ -62,7 +61,6 @@ SandBox::SandBoxResult SandBox::run(Value (*scriptRunner)(ExecutionState&, void*
|
|||
try {
|
||||
ExecutionState state(m_context);
|
||||
result.result = scriptRunner(state, data);
|
||||
result.resultOrErrorAsString = result.result.toStringWithoutException(state);
|
||||
} catch (const Value& err) {
|
||||
processCatch(err, result);
|
||||
}
|
||||
|
|
@ -75,8 +73,6 @@ SandBox::SandBoxResult SandBox::run(const std::function<Value()>& scriptRunner)
|
|||
|
||||
try {
|
||||
result.result = scriptRunner();
|
||||
ExecutionState state(m_context);
|
||||
result.resultOrErrorAsString = result.result.toStringWithoutException(state);
|
||||
} catch (const Value& err) {
|
||||
processCatch(err, result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,12 +59,10 @@ public:
|
|||
struct SandBoxResult {
|
||||
Value result;
|
||||
Value error;
|
||||
String* resultOrErrorAsString;
|
||||
Vector<StackTraceData, GCUtil::gc_malloc_allocator<StackTraceData>> stackTraceData;
|
||||
SandBoxResult()
|
||||
: result(Value::EmptyValue)
|
||||
, error(Value::EmptyValue)
|
||||
, resultOrErrorAsString(String::emptyString)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -335,7 +335,6 @@ public:
|
|||
size_t len = arrayLength();
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
unsigned idxPosition = i * typedArrayElementSize + byteOffset();
|
||||
ArrayBufferObject* b = buffer();
|
||||
if (!callback(state, this, ObjectPropertyName(state, Value(i)), ObjectStructurePropertyDescriptor::createDataDescriptor((ObjectStructurePropertyDescriptor::PresentAttribute)(ObjectStructurePropertyDescriptor::WritablePresent | ObjectStructurePropertyDescriptor::EnumerablePresent)), data)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -484,7 +484,7 @@ static bool evalScript(ContextRef* context, StringRef* str, StringRef* fileName,
|
|||
scriptInitializeResult.script.get());
|
||||
|
||||
if (!evalResult.isSuccessful()) {
|
||||
printf("Uncaught %s:\n", evalResult.resultOrErrorAsString->toStdUTF8String().data());
|
||||
printf("Uncaught %s:\n", evalResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
for (size_t i = 0; i < evalResult.stackTraceData.size(); i++) {
|
||||
printf("%s (%d:%d)\n", evalResult.stackTraceData[i].src->toStdUTF8String().data(), (int)evalResult.stackTraceData[i].loc.line, (int)evalResult.stackTraceData[i].loc.column);
|
||||
}
|
||||
|
|
@ -492,16 +492,16 @@ static bool evalScript(ContextRef* context, StringRef* str, StringRef* fileName,
|
|||
}
|
||||
|
||||
if (shouldPrintScriptResult) {
|
||||
puts(evalResult.resultOrErrorAsString->toStdUTF8String().data());
|
||||
puts(evalResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
}
|
||||
|
||||
while (context->vmInstance()->hasPendingPromiseJob()) {
|
||||
auto jobResult = context->vmInstance()->executePendingPromiseJob();
|
||||
if (shouldPrintScriptResult) {
|
||||
if (jobResult.error) {
|
||||
printf("Uncaught %s:\n", jobResult.resultOrErrorAsString->toStdUTF8String().data());
|
||||
printf("Uncaught %s:\n", jobResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
} else {
|
||||
printf("%s\n", jobResult.resultOrErrorAsString->toStdUTF8String().data());
|
||||
printf("%s\n", jobResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue