Exemplo n.º 1
0
bool JSStorage::putDelegate(ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot&, bool& putResult)
{
    // Only perform the custom put if the object doesn't have a native property by this name.
    // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
    // the native property slots manually.
    PropertySlot slot(this, PropertySlot::InternalMethodType::GetOwnProperty);
    static_assert(!hasStaticPropertyTable, "This function does not handle static instance properties");

    JSValue prototype = this->getPrototypeDirect();
    if (prototype.isObject() && asObject(prototype)->getPropertySlot(exec, propertyName, slot))
        return false;

    if (propertyName.isSymbol())
        return false;

    String stringValue = value.toString(exec)->value(exec);
    if (exec->hadException()) {
        // The return value indicates whether putDelegate() should handle the put operation (which
        // if true, tells the caller not to execute the generic put). It does not indicate whether
        // putDelegate() did successfully complete the operation or not (which it didn't in this
        // case due to the exception).
        putResult = false;
        return true;
    }

    ExceptionCode ec = 0;
    wrapped().setItem(propertyNameToString(propertyName), stringValue, ec);
    setDOMException(exec, ec);
    putResult = !ec;
    return true;
}
Exemplo n.º 2
0
bool JSStorage::putDelegate(ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot&, bool& putResult)
{
    VM& vm = state->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    // Only perform the custom put if the object doesn't have a native property by this name.
    // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
    // the native property slots manually.
    PropertySlot slot { this, PropertySlot::InternalMethodType::GetOwnProperty };

    JSValue prototype = this->getPrototypeDirect();
    if (prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))
        return false;

    if (propertyName.isSymbol())
        return false;

    String stringValue = value.toWTFString(state);
    RETURN_IF_EXCEPTION(scope, true);

    auto setItemResult = wrapped().setItem(propertyNameToString(propertyName), stringValue);
    if (setItemResult.hasException()) {
        propagateException(*state, scope, setItemResult.releaseException());
        return true;
    }

    putResult = true;
    return true;
}
Exemplo n.º 3
0
bool JSStorage::putDelegate(ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot&)
{
    // Only perform the custom put if the object doesn't have a native property by this name.
    // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
    // the native property slots manually.
    PropertySlot slot(this);
    if (getStaticValueSlot<JSStorage, Base>(exec, *s_info.staticPropHashTable, this, propertyName, slot))
        return false;

    JSValue prototype = this->prototype();
    if (prototype.isObject() && asObject(prototype)->getPropertySlot(exec, propertyName, slot))
        return false;

    if (propertyName.isSymbol())
        return false;

    String stringValue = value.toString(exec)->value(exec);
    if (exec->hadException())
        return true;

    ExceptionCode ec = 0;
    wrapped().setItem(propertyNameToString(propertyName), stringValue, ec);
    setDOMException(exec, ec);

    return true;
}
Exemplo n.º 4
0
bool JSModuleNamespaceObject::getOwnPropertySlot(JSObject* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-getownproperty-p

    JSModuleNamespaceObject* thisObject = jsCast<JSModuleNamespaceObject*>(cell);

    // step 1.
    // If the property name is a symbol, we don't look into the imported bindings.
    // It may return the descriptor with writable: true, but namespace objects does not allow it in [[Set]] / [[DefineOwnProperty]] side.
    if (propertyName.isSymbol())
        return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot);

    if (!thisObject->m_exports.contains(propertyName.uid()))
        return false;

    // https://esdiscuss.org/topic/march-24-meeting-notes
    // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-getownproperty-p
    // section 9.4.6.5, step 6.
    // This property will be seen as writable: true, enumerable:true, configurable: false.
    // But this does not mean that this property is writable by users.
    //
    // In JSC, getOwnPropertySlot is not designed to throw any errors. But looking up the value from the module
    // environment may throw error if the loaded variable is the TDZ value. To workaround, we set the custom
    // getter function. When it is called, it looks up the variable and throws an error if the variable is not
    // initialized.
    slot.setCustom(thisObject, DontDelete, callbackGetter);
    return true;
}
Exemplo n.º 5
0
bool JSStorage::nameGetter(ExecState* exec, PropertyName propertyName, JSValue& value)
{
    if (propertyName.isSymbol())
        return false;

    ExceptionCode ec = 0;
    String item = wrapped().getItem(propertyNameToString(propertyName), ec);
    setDOMException(exec, ec);

    if (item.isNull())
        return false;

    value = jsStringWithCache(exec, item);
    return true;
}
Exemplo n.º 6
0
bool JSStorage::nameGetter(ExecState* state, PropertyName propertyName, JSValue& value)
{
    if (propertyName.isSymbol())
        return false;

    auto item = wrapped().getItem(propertyNameToString(propertyName));
    if (item.hasException()) {
        auto& vm = state->vm();
        auto scope = DECLARE_THROW_SCOPE(vm);
        propagateException(*state, scope, item.releaseException());
        return false;
    }

    auto string = item.releaseReturnValue();
    if (string.isNull())
        return false;

    value = jsStringWithCache(state, string);
    return true;
}
Exemplo n.º 7
0
bool JSStorage::deleteProperty(JSCell* cell, ExecState* state, PropertyName propertyName)
{
    auto& thisObject = *jsCast<JSStorage*>(cell);

    // Only perform the custom delete if the object doesn't have a native property by this name.
    // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
    // the native property slots manually.
    PropertySlot slot(&thisObject, PropertySlot::InternalMethodType::GetOwnProperty);

    JSValue prototype = thisObject.getPrototypeDirect();
    if (prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))
        return Base::deleteProperty(&thisObject, state, propertyName);

    if (propertyName.isSymbol())
        return Base::deleteProperty(&thisObject, state, propertyName);

    VM& vm = state->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);
    propagateException(*state, scope, thisObject.wrapped().removeItem(propertyNameToString(propertyName)));
    return true;
}
Exemplo n.º 8
0
bool JSStorage::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
    JSStorage* thisObject = jsCast<JSStorage*>(cell);
    // Only perform the custom delete if the object doesn't have a native property by this name.
    // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
    // the native property slots manually.
    PropertySlot slot(thisObject, PropertySlot::InternalMethodType::GetOwnProperty);

    static_assert(!hasStaticPropertyTable, "This function does not handle static instance properties");

    JSValue prototype = thisObject->getPrototypeDirect();
    if (prototype.isObject() && asObject(prototype)->getPropertySlot(exec, propertyName, slot))
        return Base::deleteProperty(thisObject, exec, propertyName);

    if (propertyName.isSymbol())
        return Base::deleteProperty(thisObject, exec, propertyName);

    ExceptionCode ec = 0;
    thisObject->wrapped().removeItem(propertyNameToString(propertyName), ec);
    setDOMException(exec, ec);
    return true;
}
Exemplo n.º 9
0
bool JSStorage::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
    JSStorage* thisObject = jsCast<JSStorage*>(cell);
    // Only perform the custom delete if the object doesn't have a native property by this name.
    // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
    // the native property slots manually.
    PropertySlot slot(thisObject);
    if (getStaticValueSlot<JSStorage, Base>(exec, *s_info.staticPropHashTable, thisObject, propertyName, slot))
        return Base::deleteProperty(thisObject, exec, propertyName);

    JSValue prototype = thisObject->prototype();
    if (prototype.isObject() && asObject(prototype)->getPropertySlot(exec, propertyName, slot))
        return Base::deleteProperty(thisObject, exec, propertyName);

    if (propertyName.isSymbol())
        return Base::deleteProperty(thisObject, exec, propertyName);

    ExceptionCode ec = 0;
    thisObject->wrapped().removeItem(propertyNameToString(propertyName), ec);
    setDOMException(exec, ec);
    return true;
}
Exemplo n.º 10
0
bool JSStyleSheetList::canGetItemsForName(ExecState*, StyleSheetList* styleSheetList, PropertyName propertyName)
{
    if (propertyName.isSymbol())
        return false;
    return styleSheetList->getNamedItem(propertyNameToString(propertyName));
}