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->d->numArguments) { 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->d->deletedArguments || !thisObject->d->deletedArguments[i]) && !JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot)) object->putDirect(exec->globalData(), propertyName, thisObject->argument(i).get(), 0); if (!Base::defineOwnProperty(object, exec, propertyName, descriptor, shouldThrow)) return false; if (!thisObject->d->deletedArguments) { thisObject->d->deletedArguments = adoptArrayPtr(new bool[thisObject->d->numArguments]); memset(thisObject->d->deletedArguments.get(), 0, sizeof(bool) * thisObject->d->numArguments); } // From ES 5.1, 10.6 Arguments Object // 5. If the value of isMapped is not undefined, then if (!thisObject->d->deletedArguments[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->d->deletedArguments[i] = true; } 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->argument(i).set(exec->globalData(), thisObject, 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->d->deletedArguments[i] = true; } } return true; } if (propertyName == exec->propertyNames().length && !thisObject->d->overrodeLength) { thisObject->putDirect(exec->globalData(), propertyName, jsNumber(thisObject->d->numArguments), DontEnum); thisObject->d->overrodeLength = true; } else if (propertyName == exec->propertyNames().callee && !thisObject->d->overrodeCallee) { thisObject->putDirect(exec->globalData(), propertyName, thisObject->d->callee.get(), DontEnum); thisObject->d->overrodeCallee = true; } else if (propertyName == exec->propertyNames().caller && thisObject->d->isStrictMode) thisObject->createStrictModeCallerIfNecessary(exec); return Base::defineOwnProperty(object, exec, propertyName, descriptor, shouldThrow); }
void Arguments::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot) { Arguments* thisObject = jsCast<Arguments*>(cell); unsigned i = propertyName.asIndex(); if (i < thisObject->d->numArguments && (!thisObject->d->deletedArguments || !thisObject->d->deletedArguments[i])) { ASSERT(i < PropertyName::NotAnIndex); thisObject->argument(i).set(exec->globalData(), thisObject, value); return; } if (propertyName == exec->propertyNames().length && !thisObject->d->overrodeLength) { thisObject->d->overrodeLength = true; thisObject->putDirect(exec->globalData(), propertyName, value, DontEnum); return; } if (propertyName == exec->propertyNames().callee && !thisObject->d->overrodeCallee) { if (!thisObject->d->isStrictMode) { thisObject->d->overrodeCallee = true; thisObject->putDirect(exec->globalData(), propertyName, value, DontEnum); return; } thisObject->createStrictModeCalleeIfNecessary(exec); } if (propertyName == exec->propertyNames().caller && thisObject->d->isStrictMode) thisObject->createStrictModeCallerIfNecessary(exec); JSObject::put(thisObject, exec, propertyName, value, slot); }
bool Arguments::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor) { Arguments* thisObject = jsCast<Arguments*>(object); unsigned i = propertyName.asIndex(); if (i < thisObject->d->numArguments && (!thisObject->d->deletedArguments || !thisObject->d->deletedArguments[i])) { ASSERT(i < PropertyName::NotAnIndex); descriptor.setDescriptor(thisObject->argument(i).get(), None); return true; } if (propertyName == exec->propertyNames().length && LIKELY(!thisObject->d->overrodeLength)) { descriptor.setDescriptor(jsNumber(thisObject->d->numArguments), DontEnum); return true; } if (propertyName == exec->propertyNames().callee && LIKELY(!thisObject->d->overrodeCallee)) { if (!thisObject->d->isStrictMode) { descriptor.setDescriptor(thisObject->d->callee.get(), DontEnum); return true; } thisObject->createStrictModeCalleeIfNecessary(exec); } if (propertyName == exec->propertyNames().caller && thisObject->d->isStrictMode) thisObject->createStrictModeCallerIfNecessary(exec); return JSObject::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor); }
bool Arguments::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot) { Arguments* thisObject = jsCast<Arguments*>(cell); unsigned i = propertyName.asIndex(); if (i < thisObject->d->numArguments && (!thisObject->d->deletedArguments || !thisObject->d->deletedArguments[i])) { ASSERT(i < PropertyName::NotAnIndex); slot.setValue(thisObject->argument(i).get()); return true; } if (propertyName == exec->propertyNames().length && LIKELY(!thisObject->d->overrodeLength)) { slot.setValue(jsNumber(thisObject->d->numArguments)); return true; } if (propertyName == exec->propertyNames().callee && LIKELY(!thisObject->d->overrodeCallee)) { if (!thisObject->d->isStrictMode) { slot.setValue(thisObject->d->callee.get()); return true; } thisObject->createStrictModeCalleeIfNecessary(exec); } if (propertyName == exec->propertyNames().caller && thisObject->d->isStrictMode) thisObject->createStrictModeCallerIfNecessary(exec); return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot); }
bool Arguments::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned i, PropertySlot& slot) { Arguments* thisObject = jsCast<Arguments*>(cell); if (i < thisObject->d->numArguments && (!thisObject->d->deletedArguments || !thisObject->d->deletedArguments[i])) { slot.setValue(thisObject->argument(i).get()); return true; } return JSObject::getOwnPropertySlot(thisObject, exec, Identifier(exec, UString::number(i)), slot); }
void Arguments::putByIndex(JSCell* cell, ExecState* exec, unsigned i, JSValue value, bool shouldThrow) { Arguments* thisObject = jsCast<Arguments*>(cell); if (i < static_cast<unsigned>(thisObject->d->numArguments) && (!thisObject->d->deletedArguments || !thisObject->d->deletedArguments[i])) { thisObject->argument(i).set(exec->globalData(), thisObject, value); return; } PutPropertySlot slot(shouldThrow); JSObject::put(thisObject, exec, Identifier(exec, UString::number(i)), value, slot); }