mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-22 10:01:50 +00:00
1. implement ArrayObject
2. implement UnaryNot, Math.sqrt, break statement 3. add make tidy this patch pass bitops-nsieve-bits.js, access-fannkuch.js, access-nbody.js Signed-off-by: seonghyun kim <sh8281.kim@samsung.com>
This commit is contained in:
parent
3cfbdeb762
commit
efb82ad9b5
27 changed files with 572 additions and 42 deletions
97
src/runtime/ArrayObject.cpp
Normal file
97
src/runtime/ArrayObject.cpp
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#include "Escargot.h"
|
||||
#include "ArrayObject.h"
|
||||
#include "Context.h"
|
||||
|
||||
namespace Escargot {
|
||||
|
||||
ArrayObject::ArrayObject(ExecutionState& state)
|
||||
: Object(state, 2, true)
|
||||
{
|
||||
m_structure = state.context()->defaultStructureForArrayObject();
|
||||
m_values[1] = Value(0);
|
||||
setPrototype(state, state.context()->globalObject()->arrayPrototype());
|
||||
}
|
||||
|
||||
Value ArrayObject::getLengthSlowCase(ExecutionState& state)
|
||||
{
|
||||
return getOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().length)).value();
|
||||
}
|
||||
|
||||
bool ArrayObject::setLengthSlowCase(ExecutionState& state, const Value& value)
|
||||
{
|
||||
return defineOwnProperty(state, ObjectPropertyName(state, state.context()->staticStrings().length), ObjectPropertyDescriptorForDefineOwnProperty(value));
|
||||
}
|
||||
|
||||
Object::ObjectGetResult ArrayObject::getOwnProperty(ExecutionState& state, const ObjectPropertyName& P) ESCARGOT_OBJECT_SUBCLASS_MUST_REDEFINE
|
||||
{
|
||||
if (LIKELY(isFastModeArray())) {
|
||||
uint32_t idx;
|
||||
if (LIKELY(P.isUIntType())) {
|
||||
idx = P.uintValue();
|
||||
} else {
|
||||
uint32_t idx = P.string(state)->tryToUseAsIndex();
|
||||
}
|
||||
if (LIKELY(idx != Value::InvalidArrayIndexValue)) {
|
||||
ASSERT(m_fastModeData.size() == getLength(state));
|
||||
if (LIKELY(idx < m_fastModeData.size())) {
|
||||
Value v = m_fastModeData[idx];
|
||||
if (LIKELY(!v.isEmpty())) {
|
||||
return Object::ObjectGetResult(v, true, true, true);
|
||||
}
|
||||
return Object::ObjectGetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Object::getOwnProperty(state, P);
|
||||
}
|
||||
|
||||
bool ArrayObject::defineOwnProperty(ExecutionState& state, const ObjectPropertyName& P, const ObjectPropertyDescriptorForDefineOwnProperty& desc) ESCARGOT_OBJECT_SUBCLASS_MUST_REDEFINE
|
||||
{
|
||||
if (LIKELY(isFastModeArray())) {
|
||||
uint32_t idx;
|
||||
if (LIKELY(P.isUIntType())) {
|
||||
idx = P.uintValue();
|
||||
} else {
|
||||
idx = P.string(state)->tryToUseAsIndex();
|
||||
}
|
||||
if (LIKELY(idx != Value::InvalidArrayIndexValue)) {
|
||||
if (UNLIKELY(!desc.descriptor().isPlainDataWritableEnumerableConfigurable())) {
|
||||
convertIntoNonFastMode();
|
||||
goto NonFastMode;
|
||||
}
|
||||
uint32_t len = m_fastModeData.size();
|
||||
if (UNLIKELY(len <= idx)) {
|
||||
if (UNLIKELY(!setArrayLength(state, idx + 1))) {
|
||||
goto NonFastMode;
|
||||
}
|
||||
}
|
||||
ASSERT(m_fastModeData.size() == getLength(state));
|
||||
m_fastModeData[idx] = desc.value();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
NonFastMode:
|
||||
return Object::defineOwnProperty(state, P, desc);
|
||||
}
|
||||
|
||||
void ArrayObject::deleteOwnProperty(ExecutionState& state, const ObjectPropertyName& P) ESCARGOT_OBJECT_SUBCLASS_MUST_REDEFINE
|
||||
{
|
||||
if (LIKELY(isFastModeArray())) {
|
||||
uint32_t idx;
|
||||
if (LIKELY(P.isUIntType())) {
|
||||
idx = P.uintValue();
|
||||
} else {
|
||||
idx = P.string(state)->tryToUseAsIndex();
|
||||
}
|
||||
if (LIKELY(idx != Value::InvalidArrayIndexValue)) {
|
||||
uint32_t len = m_fastModeData.size();
|
||||
ASSERT(len == getLength(state));
|
||||
if (idx < len) {
|
||||
m_fastModeData[len] = Value(Value::EmptyValue);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Object::deleteOwnProperty(state, P);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue