summaryrefslogtreecommitdiff
path: root/Source/WebCore/bridge/runtime_array.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/bridge/runtime_array.cpp')
-rw-r--r--Source/WebCore/bridge/runtime_array.cpp70
1 files changed, 36 insertions, 34 deletions
diff --git a/Source/WebCore/bridge/runtime_array.cpp b/Source/WebCore/bridge/runtime_array.cpp
index 11ca04145..66203ea78 100644
--- a/Source/WebCore/bridge/runtime_array.cpp
+++ b/Source/WebCore/bridge/runtime_array.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2008, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -35,7 +35,7 @@ using namespace WebCore;
namespace JSC {
-const ClassInfo RuntimeArray::s_info = { "RuntimeArray", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(RuntimeArray) };
+const ClassInfo RuntimeArray::s_info = { "RuntimeArray", &Base::s_info, 0, CREATE_METHOD_TABLE(RuntimeArray) };
RuntimeArray::RuntimeArray(ExecState* exec, Structure* structure)
: JSArray(exec->vm(), structure, 0)
@@ -46,7 +46,7 @@ RuntimeArray::RuntimeArray(ExecState* exec, Structure* structure)
void RuntimeArray::finishCreation(VM& vm, Bindings::Array* array)
{
Base::finishCreation(vm);
- ASSERT(inherits(info()));
+ ASSERT(inherits(vm, info()));
m_array = array;
}
@@ -60,20 +60,17 @@ void RuntimeArray::destroy(JSCell* cell)
static_cast<RuntimeArray*>(cell)->RuntimeArray::~RuntimeArray();
}
-EncodedJSValue RuntimeArray::lengthGetter(ExecState* exec, EncodedJSValue, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue RuntimeArray::lengthGetter(ExecState* exec, EncodedJSValue thisValue, PropertyName)
{
- RuntimeArray* thisObject = jsDynamicCast<RuntimeArray*>(JSValue::decode(thisValue));
+ VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ RuntimeArray* thisObject = jsDynamicDowncast<RuntimeArray*>(vm, JSValue::decode(thisValue));
if (!thisObject)
- return throwVMTypeError(exec);
+ return throwVMTypeError(exec, scope);
return JSValue::encode(jsNumber(thisObject->getLength()));
}
-EncodedJSValue RuntimeArray::indexGetter(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, unsigned index)
-{
- RuntimeArray* thisObj = jsCast<RuntimeArray*>(JSValue::decode(slotBase));
- return JSValue::encode(thisObj->getConcreteArray()->valueAt(exec, index));
-}
-
void RuntimeArray::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
RuntimeArray* thisObject = jsCast<RuntimeArray*>(object);
@@ -81,7 +78,7 @@ void RuntimeArray::getOwnPropertyNames(JSObject* object, ExecState* exec, Proper
for (unsigned i = 0; i < length; ++i)
propertyNames.add(Identifier::from(exec, i));
- if (mode == IncludeDontEnumProperties)
+ if (mode.includeDontEnumProperties())
propertyNames.add(exec->propertyNames().length);
JSObject::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
@@ -95,10 +92,10 @@ bool RuntimeArray::getOwnPropertySlot(JSObject* object, ExecState* exec, Propert
return true;
}
- unsigned index = propertyName.asIndex();
- if (index < thisObject->getLength()) {
- ASSERT(index != PropertyName::NotAnIndex);
- slot.setCustomIndex(thisObject, DontDelete | DontEnum, index, thisObject->indexGetter);
+ std::optional<uint32_t> index = parseIndex(propertyName);
+ if (index && index.value() < thisObject->getLength()) {
+ slot.setValue(thisObject, DontDelete | DontEnum,
+ thisObject->getConcreteArray()->valueAt(exec, index.value()));
return true;
}
@@ -109,39 +106,44 @@ bool RuntimeArray::getOwnPropertySlotByIndex(JSObject* object, ExecState *exec,
{
RuntimeArray* thisObject = jsCast<RuntimeArray*>(object);
if (index < thisObject->getLength()) {
- slot.setCustomIndex(thisObject, DontDelete | DontEnum, index, thisObject->indexGetter);
+ slot.setValue(thisObject, DontDelete | DontEnum,
+ thisObject->getConcreteArray()->valueAt(exec, index));
return true;
}
return JSObject::getOwnPropertySlotByIndex(thisObject, exec, index, slot);
}
-void RuntimeArray::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
+bool RuntimeArray::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
{
+ VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
RuntimeArray* thisObject = jsCast<RuntimeArray*>(cell);
if (propertyName == exec->propertyNames().length) {
- exec->vm().throwException(exec, createRangeError(exec, "Range error"));
- return;
- }
-
- unsigned index = propertyName.asIndex();
- if (index != PropertyName::NotAnIndex) {
- thisObject->getConcreteArray()->setValueAt(exec, index, value);
- return;
+ throwException(exec, scope, createRangeError(exec, "Range error"));
+ return false;
}
- JSObject::put(thisObject, exec, propertyName, value, slot);
+ if (std::optional<uint32_t> index = parseIndex(propertyName))
+ return thisObject->getConcreteArray()->setValueAt(exec, index.value(), value);
+
+ scope.release();
+ return JSObject::put(thisObject, exec, propertyName, value, slot);
}
-void RuntimeArray::putByIndex(JSCell* cell, ExecState* exec, unsigned index, JSValue value, bool)
+bool RuntimeArray::putByIndex(JSCell* cell, ExecState* exec, unsigned index, JSValue value, bool)
{
+ VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
RuntimeArray* thisObject = jsCast<RuntimeArray*>(cell);
if (index >= thisObject->getLength()) {
- exec->vm().throwException(exec, createRangeError(exec, "Range error"));
- return;
+ throwException(exec, scope, createRangeError(exec, "Range error"));
+ return false;
}
- thisObject->getConcreteArray()->setValueAt(exec, index, value);
+ return thisObject->getConcreteArray()->setValueAt(exec, index, value);
}
bool RuntimeArray::deleteProperty(JSCell*, ExecState*, PropertyName)