#include "JSActivation.h"
#include "JSFunction.h"
#include "JSGlobalObject.h"
+#include "Operations.h"
using namespace std;
namespace JSC {
-ASSERT_CLASS_FITS_IN_CELL(Arguments);
+const ClassInfo Arguments::s_info = { "Arguments", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(Arguments) };
-const ClassInfo Arguments::s_info = { "Arguments", &JSNonFinalObject::s_info, 0, 0 };
-
-Arguments::~Arguments()
-{
- if (d->extraArguments != d->extraArgumentsFixedBuffer)
- delete [] d->extraArguments;
-}
-
-void Arguments::visitChildren(SlotVisitor& visitor)
+void Arguments::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
- ASSERT_GC_OBJECT_INHERITS(this, &s_info);
+ Arguments* thisObject = jsCast<Arguments*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
- ASSERT(structure()->typeInfo().overridesVisitChildren());
- JSObject::visitChildren(visitor);
-
- if (d->registerArray)
- visitor.appendValues(d->registerArray.get(), d->numParameters);
+ ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
+ JSObject::visitChildren(thisObject, visitor);
- if (d->extraArguments) {
- unsigned numExtraArguments = d->numArguments - d->numParameters;
- visitor.appendValues(d->extraArguments, numExtraArguments);
- }
-
- visitor.append(&d->callee);
+ if (thisObject->m_registerArray)
+ visitor.appendValues(thisObject->m_registerArray.get(), thisObject->m_numArguments);
+ visitor.append(&thisObject->m_callee);
+ visitor.append(&thisObject->m_activation);
+}
- if (d->activation)
- visitor.append(&d->activation);
+void Arguments::destroy(JSCell* cell)
+{
+ static_cast<Arguments*>(cell)->Arguments::~Arguments();
}
-void Arguments::copyToRegisters(ExecState* exec, Register* buffer, uint32_t maxSize)
+void Arguments::copyToArguments(ExecState* exec, CallFrame* callFrame, uint32_t length)
{
- if (UNLIKELY(d->overrodeLength)) {
- unsigned length = min(get(exec, exec->propertyNames().length).toUInt32(exec), maxSize);
+ if (UNLIKELY(m_overrodeLength)) {
+ length = min(get(exec, exec->propertyNames().length).toUInt32(exec), length);
for (unsigned i = 0; i < length; i++)
- buffer[i] = get(exec, i);
+ callFrame->setArgument(i, get(exec, i));
return;
}
-
- if (LIKELY(!d->deletedArguments)) {
- unsigned parametersLength = min(min(d->numParameters, d->numArguments), maxSize);
- unsigned i = 0;
- for (; i < parametersLength; ++i)
- buffer[i] = d->registers[d->firstParameterIndex + i].get();
- for (; i < d->numArguments; ++i)
- buffer[i] = d->extraArguments[i - d->numParameters].get();
- return;
- }
-
- unsigned parametersLength = min(min(d->numParameters, d->numArguments), maxSize);
- unsigned i = 0;
- for (; i < parametersLength; ++i) {
- if (!d->deletedArguments[i])
- buffer[i] = d->registers[d->firstParameterIndex + i].get();
+ ASSERT(length == this->length(exec));
+ for (size_t i = 0; i < length; ++i) {
+ if (JSValue value = tryGetArgument(i))
+ callFrame->setArgument(i, value);
else
- buffer[i] = get(exec, i);
- }
- for (; i < d->numArguments; ++i) {
- if (!d->deletedArguments[i])
- buffer[i] = d->extraArguments[i - d->numParameters].get();
- else
- buffer[i] = get(exec, i);
+ callFrame->setArgument(i, get(exec, i));
}
}
void Arguments::fillArgList(ExecState* exec, MarkedArgumentBuffer& args)
{
- if (UNLIKELY(d->overrodeLength)) {
+ if (UNLIKELY(m_overrodeLength)) {
unsigned length = get(exec, exec->propertyNames().length).toUInt32(exec);
for (unsigned i = 0; i < length; i++)
args.append(get(exec, i));
return;
}
-
- if (LIKELY(!d->deletedArguments)) {
- if (LIKELY(!d->numParameters)) {
- args.initialize(d->extraArguments, d->numArguments);
- return;
- }
-
- if (d->numParameters == d->numArguments) {
- args.initialize(&d->registers[d->firstParameterIndex], d->numArguments);
- return;
- }
-
- unsigned parametersLength = min(d->numParameters, d->numArguments);
- unsigned i = 0;
- for (; i < parametersLength; ++i)
- args.append(d->registers[d->firstParameterIndex + i].get());
- for (; i < d->numArguments; ++i)
- args.append(d->extraArguments[i - d->numParameters].get());
- return;
- }
-
- unsigned parametersLength = min(d->numParameters, d->numArguments);
- unsigned i = 0;
- for (; i < parametersLength; ++i) {
- if (!d->deletedArguments[i])
- args.append(d->registers[d->firstParameterIndex + i].get());
- else
- args.append(get(exec, i));
- }
- for (; i < d->numArguments; ++i) {
- if (!d->deletedArguments[i])
- args.append(d->extraArguments[i - d->numParameters].get());
+ uint32_t length = this->length(exec);
+ for (size_t i = 0; i < length; ++i) {
+ if (JSValue value = tryGetArgument(i))
+ args.append(value);
else
args.append(get(exec, i));
}
}
-bool Arguments::getOwnPropertySlot(ExecState* exec, unsigned i, PropertySlot& slot)
+bool Arguments::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned i, PropertySlot& slot)
{
- if (i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) {
- if (i < d->numParameters) {
- slot.setValue(d->registers[d->firstParameterIndex + i].get());
- } else
- slot.setValue(d->extraArguments[i - d->numParameters].get());
+ Arguments* thisObject = jsCast<Arguments*>(cell);
+ if (JSValue value = thisObject->tryGetArgument(i)) {
+ slot.setValue(value);
return true;
}
- return JSObject::getOwnPropertySlot(exec, Identifier(exec, UString::number(i)), slot);
+ return JSObject::getOwnPropertySlot(thisObject, exec, Identifier(exec, String::number(i)), slot);
}
void Arguments::createStrictModeCallerIfNecessary(ExecState* exec)
{
- if (d->overrodeCaller)
+ if (m_overrodeCaller)
return;
- d->overrodeCaller = true;
+ m_overrodeCaller = true;
PropertyDescriptor descriptor;
- JSValue thrower = createTypeErrorFunction(exec, "Unable to access caller of strict mode function");
- descriptor.setAccessorDescriptor(thrower, thrower, DontEnum | DontDelete | Getter | Setter);
- defineOwnProperty(exec, exec->propertyNames().caller, descriptor, false);
+ descriptor.setAccessorDescriptor(globalObject()->throwTypeErrorGetterSetter(exec), DontEnum | DontDelete | Accessor);
+ methodTable()->defineOwnProperty(this, exec, exec->propertyNames().caller, descriptor, false);
}
void Arguments::createStrictModeCalleeIfNecessary(ExecState* exec)
{
- if (d->overrodeCallee)
+ if (m_overrodeCallee)
return;
- d->overrodeCallee = true;
+ m_overrodeCallee = true;
PropertyDescriptor descriptor;
- JSValue thrower = createTypeErrorFunction(exec, "Unable to access callee of strict mode function");
- descriptor.setAccessorDescriptor(thrower, thrower, DontEnum | DontDelete | Getter | Setter);
- defineOwnProperty(exec, exec->propertyNames().callee, descriptor, false);
+ descriptor.setAccessorDescriptor(globalObject()->throwTypeErrorGetterSetter(exec), DontEnum | DontDelete | Accessor);
+ methodTable()->defineOwnProperty(this, exec, exec->propertyNames().callee, descriptor, false);
}
-bool Arguments::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+bool Arguments::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
- bool isArrayIndex;
- unsigned i = propertyName.toArrayIndex(isArrayIndex);
- if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) {
- if (i < d->numParameters) {
- slot.setValue(d->registers[d->firstParameterIndex + i].get());
- } else
- slot.setValue(d->extraArguments[i - d->numParameters].get());
+ Arguments* thisObject = jsCast<Arguments*>(cell);
+ unsigned i = propertyName.asIndex();
+ if (JSValue value = thisObject->tryGetArgument(i)) {
+ RELEASE_ASSERT(i < PropertyName::NotAnIndex);
+ slot.setValue(value);
return true;
}
- if (propertyName == exec->propertyNames().length && LIKELY(!d->overrodeLength)) {
- slot.setValue(jsNumber(d->numArguments));
+ if (propertyName == exec->propertyNames().length && LIKELY(!thisObject->m_overrodeLength)) {
+ slot.setValue(jsNumber(thisObject->m_numArguments));
return true;
}
- if (propertyName == exec->propertyNames().callee && LIKELY(!d->overrodeCallee)) {
- if (!d->isStrictMode) {
- slot.setValue(d->callee.get());
+ if (propertyName == exec->propertyNames().callee && LIKELY(!thisObject->m_overrodeCallee)) {
+ if (!thisObject->m_isStrictMode) {
+ slot.setValue(thisObject->m_callee.get());
return true;
}
- createStrictModeCalleeIfNecessary(exec);
+ thisObject->createStrictModeCalleeIfNecessary(exec);
}
- if (propertyName == exec->propertyNames().caller && d->isStrictMode)
- createStrictModeCallerIfNecessary(exec);
+ if (propertyName == exec->propertyNames().caller && thisObject->m_isStrictMode)
+ thisObject->createStrictModeCallerIfNecessary(exec);
- return JSObject::getOwnPropertySlot(exec, propertyName, slot);
+ return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot);
}
-bool Arguments::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
+bool Arguments::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
{
- bool isArrayIndex;
- unsigned i = propertyName.toArrayIndex(isArrayIndex);
- if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) {
- if (i < d->numParameters) {
- descriptor.setDescriptor(d->registers[d->firstParameterIndex + i].get(), DontEnum);
- } else
- descriptor.setDescriptor(d->extraArguments[i - d->numParameters].get(), DontEnum);
+ Arguments* thisObject = jsCast<Arguments*>(object);
+ unsigned i = propertyName.asIndex();
+ if (JSValue value = thisObject->tryGetArgument(i)) {
+ RELEASE_ASSERT(i < PropertyName::NotAnIndex);
+ descriptor.setDescriptor(value, None);
return true;
}
- if (propertyName == exec->propertyNames().length && LIKELY(!d->overrodeLength)) {
- descriptor.setDescriptor(jsNumber(d->numArguments), DontEnum);
+ if (propertyName == exec->propertyNames().length && LIKELY(!thisObject->m_overrodeLength)) {
+ descriptor.setDescriptor(jsNumber(thisObject->m_numArguments), DontEnum);
return true;
}
- if (propertyName == exec->propertyNames().callee && LIKELY(!d->overrodeCallee)) {
- if (!d->isStrictMode) {
- descriptor.setDescriptor(d->callee.get(), DontEnum);
+ if (propertyName == exec->propertyNames().callee && LIKELY(!thisObject->m_overrodeCallee)) {
+ if (!thisObject->m_isStrictMode) {
+ descriptor.setDescriptor(thisObject->m_callee.get(), DontEnum);
return true;
}
- createStrictModeCalleeIfNecessary(exec);
+ thisObject->createStrictModeCalleeIfNecessary(exec);
}
- if (propertyName == exec->propertyNames().caller && d->isStrictMode)
- createStrictModeCallerIfNecessary(exec);
+ if (propertyName == exec->propertyNames().caller && thisObject->m_isStrictMode)
+ thisObject->createStrictModeCallerIfNecessary(exec);
- return JSObject::getOwnPropertyDescriptor(exec, propertyName, descriptor);
+ return JSObject::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
}
-void Arguments::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
+void Arguments::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
+ Arguments* thisObject = jsCast<Arguments*>(object);
+ for (unsigned i = 0; i < thisObject->m_numArguments; ++i) {
+ if (!thisObject->isArgument(i))
+ continue;
+ propertyNames.add(Identifier(exec, String::number(i)));
+ }
if (mode == IncludeDontEnumProperties) {
- for (unsigned i = 0; i < d->numArguments; ++i) {
- if (!d->deletedArguments || !d->deletedArguments[i])
- propertyNames.add(Identifier(exec, UString::number(i)));
- }
propertyNames.add(exec->propertyNames().callee);
propertyNames.add(exec->propertyNames().length);
}
- JSObject::getOwnPropertyNames(exec, propertyNames, mode);
+ JSObject::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}
-void Arguments::put(ExecState* exec, unsigned i, JSValue value)
+void Arguments::putByIndex(JSCell* cell, ExecState* exec, unsigned i, JSValue value, bool shouldThrow)
{
- if (i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) {
- if (i < d->numParameters)
- d->registers[d->firstParameterIndex + i].set(exec->globalData(), d->activation ? static_cast<JSCell*>(d->activation.get()) : static_cast<JSCell*>(this), value);
- else
- d->extraArguments[i - d->numParameters].set(exec->globalData(), this, value);
+ Arguments* thisObject = jsCast<Arguments*>(cell);
+ if (thisObject->trySetArgument(exec->vm(), i, value))
return;
- }
- PutPropertySlot slot;
- JSObject::put(exec, Identifier(exec, UString::number(i)), value, slot);
+ PutPropertySlot slot(shouldThrow);
+ JSObject::put(thisObject, exec, Identifier(exec, String::number(i)), value, slot);
}
-void Arguments::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
+void Arguments::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
{
- bool isArrayIndex;
- unsigned i = propertyName.toArrayIndex(isArrayIndex);
- if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) {
- if (i < d->numParameters)
- d->registers[d->firstParameterIndex + i].set(exec->globalData(), d->activation ? static_cast<JSCell*>(d->activation.get()) : static_cast<JSCell*>(this), value);
- else
- d->extraArguments[i - d->numParameters].set(exec->globalData(), this, value);
+ Arguments* thisObject = jsCast<Arguments*>(cell);
+ unsigned i = propertyName.asIndex();
+ if (thisObject->trySetArgument(exec->vm(), i, value))
return;
- }
- if (propertyName == exec->propertyNames().length && !d->overrodeLength) {
- d->overrodeLength = true;
- putDirect(exec->globalData(), propertyName, value, DontEnum);
+ if (propertyName == exec->propertyNames().length && !thisObject->m_overrodeLength) {
+ thisObject->m_overrodeLength = true;
+ thisObject->putDirect(exec->vm(), propertyName, value, DontEnum);
return;
}
- if (propertyName == exec->propertyNames().callee && !d->overrodeCallee) {
- if (!d->isStrictMode) {
- d->overrodeCallee = true;
- putDirect(exec->globalData(), propertyName, value, DontEnum);
+ if (propertyName == exec->propertyNames().callee && !thisObject->m_overrodeCallee) {
+ if (!thisObject->m_isStrictMode) {
+ thisObject->m_overrodeCallee = true;
+ thisObject->putDirect(exec->vm(), propertyName, value, DontEnum);
return;
}
- createStrictModeCalleeIfNecessary(exec);
+ thisObject->createStrictModeCalleeIfNecessary(exec);
}
- if (propertyName == exec->propertyNames().caller && d->isStrictMode)
- createStrictModeCallerIfNecessary(exec);
+ if (propertyName == exec->propertyNames().caller && thisObject->m_isStrictMode)
+ thisObject->createStrictModeCallerIfNecessary(exec);
- JSObject::put(exec, propertyName, value, slot);
+ JSObject::put(thisObject, exec, propertyName, value, slot);
}
-bool Arguments::deleteProperty(ExecState* exec, unsigned i)
+bool Arguments::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned i)
{
- if (i < d->numArguments) {
- if (!d->deletedArguments) {
- d->deletedArguments = adoptArrayPtr(new bool[d->numArguments]);
- memset(d->deletedArguments.get(), 0, sizeof(bool) * d->numArguments);
- }
- if (!d->deletedArguments[i]) {
- d->deletedArguments[i] = true;
+ Arguments* thisObject = jsCast<Arguments*>(cell);
+ if (i < thisObject->m_numArguments) {
+ if (!Base::deletePropertyByIndex(cell, exec, i))
+ return false;
+ if (thisObject->tryDeleteArgument(i))
return true;
- }
}
-
- return JSObject::deleteProperty(exec, Identifier(exec, UString::number(i)));
+ return JSObject::deletePropertyByIndex(thisObject, exec, i);
}
-bool Arguments::deleteProperty(ExecState* exec, const Identifier& propertyName)
+bool Arguments::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
- bool isArrayIndex;
- unsigned i = propertyName.toArrayIndex(isArrayIndex);
- if (isArrayIndex && i < d->numArguments) {
- if (!d->deletedArguments) {
- d->deletedArguments = adoptArrayPtr(new bool[d->numArguments]);
- memset(d->deletedArguments.get(), 0, sizeof(bool) * d->numArguments);
- }
- if (!d->deletedArguments[i]) {
- d->deletedArguments[i] = true;
+ if (exec->vm().isInDefineOwnProperty())
+ return Base::deleteProperty(cell, exec, propertyName);
+
+ Arguments* thisObject = jsCast<Arguments*>(cell);
+ unsigned i = propertyName.asIndex();
+ if (i < thisObject->m_numArguments) {
+ RELEASE_ASSERT(i < PropertyName::NotAnIndex);
+ if (!Base::deleteProperty(cell, exec, propertyName))
+ return false;
+ if (thisObject->tryDeleteArgument(i))
return true;
- }
}
- if (propertyName == exec->propertyNames().length && !d->overrodeLength) {
- d->overrodeLength = true;
+ if (propertyName == exec->propertyNames().length && !thisObject->m_overrodeLength) {
+ thisObject->m_overrodeLength = true;
return true;
}
- if (propertyName == exec->propertyNames().callee && !d->overrodeCallee) {
- if (!d->isStrictMode) {
- d->overrodeCallee = true;
+ if (propertyName == exec->propertyNames().callee && !thisObject->m_overrodeCallee) {
+ if (!thisObject->m_isStrictMode) {
+ thisObject->m_overrodeCallee = true;
return true;
}
- createStrictModeCalleeIfNecessary(exec);
+ thisObject->createStrictModeCalleeIfNecessary(exec);
+ }
+
+ if (propertyName == exec->propertyNames().caller && thisObject->m_isStrictMode)
+ thisObject->createStrictModeCallerIfNecessary(exec);
+
+ return JSObject::deleteProperty(thisObject, exec, propertyName);
+}
+
+bool Arguments::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor, bool shouldThrow)
+{
+ Arguments* thisObject = jsCast<Arguments*>(object);
+ unsigned i = propertyName.asIndex();
+ if (i < thisObject->m_numArguments) {
+ RELEASE_ASSERT(i < PropertyName::NotAnIndex);
+ // If the property is not yet present on the object, and is not yet marked as deleted, then add it now.
+ PropertySlot slot;
+ if (!thisObject->isDeletedArgument(i) && !JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot)) {
+ JSValue value = thisObject->tryGetArgument(i);
+ ASSERT(value);
+ object->putDirectMayBeIndex(exec, propertyName, value);
+ }
+ if (!Base::defineOwnProperty(object, exec, propertyName, descriptor, shouldThrow))
+ return false;
+
+ // From ES 5.1, 10.6 Arguments Object
+ // 5. If the value of isMapped is not undefined, then
+ if (thisObject->isArgument(i)) {
+ // a. If IsAccessorDescriptor(Desc) is true, then
+ if (descriptor.isAccessorDescriptor()) {
+ // i. Call the [[Delete]] internal method of map passing P, and false as the arguments.
+ thisObject->tryDeleteArgument(i);
+ } else { // b. Else
+ // i. If Desc.[[Value]] is present, then
+ // 1. Call the [[Put]] internal method of map passing P, Desc.[[Value]], and Throw as the arguments.
+ if (descriptor.value())
+ thisObject->trySetArgument(exec->vm(), i, descriptor.value());
+ // ii. If Desc.[[Writable]] is present and its value is false, then
+ // 1. Call the [[Delete]] internal method of map passing P and false as arguments.
+ if (descriptor.writablePresent() && !descriptor.writable())
+ thisObject->tryDeleteArgument(i);
+ }
+ }
+ return true;
}
+
+ if (propertyName == exec->propertyNames().length && !thisObject->m_overrodeLength) {
+ thisObject->putDirect(exec->vm(), propertyName, jsNumber(thisObject->m_numArguments), DontEnum);
+ thisObject->m_overrodeLength = true;
+ } else if (propertyName == exec->propertyNames().callee && !thisObject->m_overrodeCallee) {
+ thisObject->putDirect(exec->vm(), propertyName, thisObject->m_callee.get(), DontEnum);
+ thisObject->m_overrodeCallee = true;
+ } else if (propertyName == exec->propertyNames().caller && thisObject->m_isStrictMode)
+ thisObject->createStrictModeCallerIfNecessary(exec);
+
+ return Base::defineOwnProperty(object, exec, propertyName, descriptor, shouldThrow);
+}
+
+void Arguments::tearOff(CallFrame* callFrame)
+{
+ if (isTornOff())
+ return;
+
+ if (!m_numArguments)
+ return;
+
+ // Must be called for the same call frame from which it was created.
+ ASSERT(bitwise_cast<WriteBarrier<Unknown>*>(callFrame) == m_registers);
- if (propertyName == exec->propertyNames().caller && !d->isStrictMode)
- createStrictModeCallerIfNecessary(exec);
+ m_registerArray = adoptArrayPtr(new WriteBarrier<Unknown>[m_numArguments]);
+ m_registers = m_registerArray.get() + CallFrame::offsetFor(m_numArguments + 1);
+
+ // If we have a captured argument that logically aliases activation storage,
+ // but we optimize away the activation, the argument needs to tear off into
+ // our storage. The simplest way to do this is to revert it to Normal status.
+ if (m_slowArguments && !m_activation) {
+ for (size_t i = 0; i < m_numArguments; ++i) {
+ if (m_slowArguments[i].status != SlowArgument::Captured)
+ continue;
+ m_slowArguments[i].status = SlowArgument::Normal;
+ m_slowArguments[i].index = CallFrame::argumentOffset(i);
+ }
+ }
+
+ if (!callFrame->isInlineCallFrame()) {
+ for (size_t i = 0; i < m_numArguments; ++i)
+ trySetArgument(callFrame->vm(), i, callFrame->argumentAfterCapture(i));
+ return;
+ }
- return JSObject::deleteProperty(exec, propertyName);
+ tearOffForInlineCallFrame(
+ callFrame->vm(), callFrame->registers(), callFrame->inlineCallFrame());
+}
+
+void Arguments::didTearOffActivation(ExecState* exec, JSActivation* activation)
+{
+ RELEASE_ASSERT(activation);
+ if (isTornOff())
+ return;
+
+ if (!m_numArguments)
+ return;
+
+ m_activation.set(exec->vm(), this, activation);
+ tearOff(exec);
+}
+
+void Arguments::tearOff(CallFrame* callFrame, InlineCallFrame* inlineCallFrame)
+{
+ if (isTornOff())
+ return;
+
+ if (!m_numArguments)
+ return;
+
+ m_registerArray = adoptArrayPtr(new WriteBarrier<Unknown>[m_numArguments]);
+ m_registers = m_registerArray.get() + CallFrame::offsetFor(m_numArguments + 1);
+
+ tearOffForInlineCallFrame(
+ callFrame->vm(), callFrame->registers() + inlineCallFrame->stackOffset,
+ inlineCallFrame);
+}
+
+void Arguments::tearOffForInlineCallFrame(VM& vm, Register* registers, InlineCallFrame* inlineCallFrame)
+{
+ for (size_t i = 0; i < m_numArguments; ++i) {
+ ValueRecovery& recovery = inlineCallFrame->arguments[i + 1];
+ // In the future we'll support displaced recoveries (indicating that the
+ // argument was flushed to a different location), but for now we don't do
+ // that so this code will fail if that were to happen. On the other hand,
+ // it's much less likely that we'll support in-register recoveries since
+ // this code does not (easily) have access to registers.
+ JSValue value;
+ Register* location = ®isters[CallFrame::argumentOffset(i)];
+ switch (recovery.technique()) {
+ case AlreadyInJSStack:
+ value = location->jsValue();
+ break;
+ case AlreadyInJSStackAsUnboxedInt32:
+ value = jsNumber(location->unboxedInt32());
+ break;
+ case AlreadyInJSStackAsUnboxedCell:
+ value = location->unboxedCell();
+ break;
+ case AlreadyInJSStackAsUnboxedBoolean:
+ value = jsBoolean(location->unboxedBoolean());
+ break;
+ case AlreadyInJSStackAsUnboxedDouble:
+#if USE(JSVALUE64)
+ value = jsNumber(*bitwise_cast<double*>(location));
+#else
+ value = location->jsValue();
+#endif
+ break;
+ case Constant:
+ value = recovery.constant();
+ break;
+ default:
+ RELEASE_ASSERT_NOT_REACHED();
+ break;
+ }
+ trySetArgument(vm, i, value);
+ }
}
} // namespace JSC