Changeset 207411 in webkit


Ignore:
Timestamp:
Oct 17, 2016 9:59:06 AM (7 years ago)
Author:
mark.lam@apple.com
Message:

Use the reject() helper function for conditionally throwing TypeErrors.
https://bugs.webkit.org/show_bug.cgi?id=163491

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

In some places where we may conditionally throw a TypeError (e.g. when in strict
mode), we already use the reject() helper function to conditionally throw the
TypeError. Doing so makes the code mode compact. This patch applies this idiom
consistently in all places that throws TypeError where appropriate.

This patch also does the following:

  1. Make the reject() helper function take an ASCIILiteral instead of a const char* because we always pass it a literal string anyway.
  2. Change the reject helper() to take a ThrowScope&. This allows the thrown error to be attributed to its caller.
  3. When an error message string is instantiated repeatedly in more than 1 place, create a common copy of that literal string in JSObject.cpp (if one doesn't already exist) and use that common string in all those places.
  4. Since I was auditing call sites of throwTypeError() to check if they should be using the reject() helper instead, I also fixed those up to pass the error message as an ASCIILiteral where appropriate.
  5. In functions that I touched, change the code to not recompute the VM& when it is already available.
  • jit/JITOperations.cpp:
  • llint/LLIntSlowPaths.cpp:

(JSC::LLInt::LLINT_SLOW_PATH_DECL):

  • runtime/ArrayPrototype.cpp:

(JSC::shift):
(JSC::unshift):
(JSC::arrayProtoFuncPop):
(JSC::arrayProtoFuncReverse):

  • runtime/CommonSlowPaths.cpp:

(JSC::SLOW_PATH_DECL):

  • runtime/GetterSetter.cpp:

(JSC::callSetter):

  • runtime/JSArray.cpp:

(JSC::JSArray::defineOwnProperty):
(JSC::JSArray::setLengthWithArrayStorage):
(JSC::JSArray::pop):

  • runtime/JSArrayBuffer.cpp:

(JSC::JSArrayBuffer::put):
(JSC::JSArrayBuffer::defineOwnProperty):

  • runtime/JSCJSValue.cpp:

(JSC::JSValue::putToPrimitive):
(JSC::JSValue::putToPrimitiveByIndex):

  • runtime/JSDataView.cpp:

(JSC::JSDataView::put):
(JSC::JSDataView::defineOwnProperty):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::put):
(JSC::JSFunction::defineOwnProperty):

  • runtime/JSGenericTypedArrayView.h:

(JSC::JSGenericTypedArrayView::setIndex):

  • runtime/JSGenericTypedArrayViewInlines.h:

(JSC::JSGenericTypedArrayView<Adaptor>::defineOwnProperty):
(JSC::JSGenericTypedArrayView<Adaptor>::deleteProperty):

  • runtime/JSGenericTypedArrayViewPrototypeFunctions.h:

(JSC::speciesConstruct):
(JSC::genericTypedArrayViewPrivateFuncSubarrayCreate):

  • runtime/JSModuleNamespaceObject.cpp:

(JSC::JSModuleNamespaceObject::defineOwnProperty):

  • runtime/JSObject.cpp:

(JSC::ordinarySetSlow):
(JSC::JSObject::putInlineSlow):
(JSC::JSObject::setPrototypeWithCycleCheck):
(JSC::JSObject::defineOwnIndexedProperty):
(JSC::JSObject::putByIndexBeyondVectorLengthWithArrayStorage):
(JSC::JSObject::putDirectIndexBeyondVectorLengthWithArrayStorage):
(JSC::validateAndApplyPropertyDescriptor):

  • runtime/JSObject.h:
  • runtime/JSObjectInlines.h:

(JSC::JSObject::putInline):

  • runtime/JSProxy.cpp:

(JSC::JSProxy::setPrototype):

  • runtime/JSSymbolTableObject.h:

(JSC::symbolTablePut):

  • runtime/Lookup.h:

(JSC::putEntry):

  • runtime/RegExpObject.cpp:

(JSC::RegExpObject::defineOwnProperty):

  • runtime/RegExpObject.h:

(JSC::RegExpObject::setLastIndex):

  • runtime/Reject.h:

(JSC::reject):

  • runtime/SparseArrayValueMap.cpp:

(JSC::SparseArrayValueMap::putEntry):
(JSC::SparseArrayValueMap::putDirect):
(JSC::SparseArrayEntry::put):

  • runtime/StringObject.cpp:

(JSC::StringObject::put):
(JSC::StringObject::putByIndex):

  • runtime/SymbolConstructor.cpp:

(JSC::symbolConstructorKeyFor):

Source/WebCore:

No new tests because this patch does not introduce new behavior.

  • bindings/js/JSCryptoAlgorithmDictionary.cpp:

(WebCore::createRsaKeyGenParams):

  • bindings/js/JSIDBDatabaseCustom.cpp:

(WebCore::JSIDBDatabase::createObjectStore):

  • bridge/c/c_instance.cpp:

(JSC::Bindings::CInstance::invokeMethod):

Location:
trunk/Source
Files:
31 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r207408 r207411  
     12016-10-17  Mark Lam  <mark.lam@apple.com>
     2
     3        Use the reject() helper function for conditionally throwing TypeErrors.
     4        https://bugs.webkit.org/show_bug.cgi?id=163491
     5
     6        Reviewed by Filip Pizlo.
     7
     8        In some places where we may conditionally throw a TypeError (e.g. when in strict
     9        mode), we already use the reject() helper function to conditionally throw the
     10        TypeError.  Doing so makes the code mode compact.  This patch applies this idiom
     11        consistently in all places that throws TypeError where appropriate.
     12
     13        This patch also does the following:
     14        1. Make the reject() helper function take an ASCIILiteral instead of a const char*
     15           because we always pass it a literal string anyway.
     16        2. Change the reject helper() to take a ThrowScope&.  This allows the thrown
     17           error to be attributed to its caller.
     18        3. When an error message string is instantiated repeatedly in more than 1 place,
     19           create a common copy of that literal string in JSObject.cpp (if one doesn't
     20           already exist) and use that common string in all those places.
     21        4. Since I was auditing call sites of throwTypeError() to check if they should be
     22           using the reject() helper instead, I also fixed those up to pass the error
     23           message as an ASCIILiteral where appropriate.
     24        5. In functions that I touched, change the code to not recompute the VM& when it
     25           is already available.
     26
     27        * jit/JITOperations.cpp:
     28        * llint/LLIntSlowPaths.cpp:
     29        (JSC::LLInt::LLINT_SLOW_PATH_DECL):
     30        * runtime/ArrayPrototype.cpp:
     31        (JSC::shift):
     32        (JSC::unshift):
     33        (JSC::arrayProtoFuncPop):
     34        (JSC::arrayProtoFuncReverse):
     35        * runtime/CommonSlowPaths.cpp:
     36        (JSC::SLOW_PATH_DECL):
     37        * runtime/GetterSetter.cpp:
     38        (JSC::callSetter):
     39        * runtime/JSArray.cpp:
     40        (JSC::JSArray::defineOwnProperty):
     41        (JSC::JSArray::setLengthWithArrayStorage):
     42        (JSC::JSArray::pop):
     43        * runtime/JSArrayBuffer.cpp:
     44        (JSC::JSArrayBuffer::put):
     45        (JSC::JSArrayBuffer::defineOwnProperty):
     46        * runtime/JSCJSValue.cpp:
     47        (JSC::JSValue::putToPrimitive):
     48        (JSC::JSValue::putToPrimitiveByIndex):
     49        * runtime/JSDataView.cpp:
     50        (JSC::JSDataView::put):
     51        (JSC::JSDataView::defineOwnProperty):
     52        * runtime/JSFunction.cpp:
     53        (JSC::JSFunction::put):
     54        (JSC::JSFunction::defineOwnProperty):
     55        * runtime/JSGenericTypedArrayView.h:
     56        (JSC::JSGenericTypedArrayView::setIndex):
     57        * runtime/JSGenericTypedArrayViewInlines.h:
     58        (JSC::JSGenericTypedArrayView<Adaptor>::defineOwnProperty):
     59        (JSC::JSGenericTypedArrayView<Adaptor>::deleteProperty):
     60        * runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
     61        (JSC::speciesConstruct):
     62        (JSC::genericTypedArrayViewPrivateFuncSubarrayCreate):
     63        * runtime/JSModuleNamespaceObject.cpp:
     64        (JSC::JSModuleNamespaceObject::defineOwnProperty):
     65        * runtime/JSObject.cpp:
     66        (JSC::ordinarySetSlow):
     67        (JSC::JSObject::putInlineSlow):
     68        (JSC::JSObject::setPrototypeWithCycleCheck):
     69        (JSC::JSObject::defineOwnIndexedProperty):
     70        (JSC::JSObject::putByIndexBeyondVectorLengthWithArrayStorage):
     71        (JSC::JSObject::putDirectIndexBeyondVectorLengthWithArrayStorage):
     72        (JSC::validateAndApplyPropertyDescriptor):
     73        * runtime/JSObject.h:
     74        * runtime/JSObjectInlines.h:
     75        (JSC::JSObject::putInline):
     76        * runtime/JSProxy.cpp:
     77        (JSC::JSProxy::setPrototype):
     78        * runtime/JSSymbolTableObject.h:
     79        (JSC::symbolTablePut):
     80        * runtime/Lookup.h:
     81        (JSC::putEntry):
     82        * runtime/RegExpObject.cpp:
     83        (JSC::RegExpObject::defineOwnProperty):
     84        * runtime/RegExpObject.h:
     85        (JSC::RegExpObject::setLastIndex):
     86        * runtime/Reject.h:
     87        (JSC::reject):
     88        * runtime/SparseArrayValueMap.cpp:
     89        (JSC::SparseArrayValueMap::putEntry):
     90        (JSC::SparseArrayValueMap::putDirect):
     91        (JSC::SparseArrayEntry::put):
     92        * runtime/StringObject.cpp:
     93        (JSC::StringObject::put):
     94        (JSC::StringObject::putByIndex):
     95        * runtime/SymbolConstructor.cpp:
     96        (JSC::symbolConstructorKeyFor):
     97
    1982016-10-16  Filip Pizlo  <fpizlo@apple.com>
    299
  • trunk/Source/JavaScriptCore/jit/JITOperations.cpp

    r207369 r207411  
    18671867    bool couldDelete = baseObj->methodTable(vm)->deleteProperty(baseObj, exec, Identifier::fromUid(&vm, uid));
    18681868    if (!couldDelete && exec->codeBlock()->isStrictMode())
    1869         throwTypeError(exec, scope, ASCIILiteral("Unable to delete property."));
     1869        throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError));
    18701870    return couldDelete;
    18711871}
     
    18981898    }
    18991899    if (!couldDelete && exec->codeBlock()->isStrictMode())
    1900         throwTypeError(exec, scope, ASCIILiteral("Unable to delete property."));
     1900        throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError));
    19011901    return couldDelete;
    19021902}
  • trunk/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp

    r206853 r207411  
    785785    LLINT_CHECK_EXCEPTION();
    786786    if (!couldDelete && codeBlock->isStrictMode())
    787         LLINT_THROW(createTypeError(exec, "Unable to delete property."));
     787        LLINT_THROW(createTypeError(exec, UnableToDeletePropertyError));
    788788    LLINT_RETURN(jsBoolean(couldDelete));
    789789}
     
    916916   
    917917    if (!couldDelete && exec->codeBlock()->isStrictMode())
    918         LLINT_THROW(createTypeError(exec, "Unable to delete property."));
     918        LLINT_THROW(createTypeError(exec, UnableToDeletePropertyError));
    919919   
    920920    LLINT_RETURN(jsBoolean(couldDelete));
  • trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

    r207344 r207411  
    300300            RETURN_IF_EXCEPTION(scope, void());
    301301        } else if (!thisObj->methodTable(vm)->deletePropertyByIndex(thisObj, exec, to)) {
    302             throwTypeError(exec, scope, ASCIILiteral("Unable to delete property."));
     302            throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError));
    303303            return;
    304304        }
     
    306306    for (unsigned k = length; k > length - count; --k) {
    307307        if (!thisObj->methodTable(vm)->deletePropertyByIndex(thisObj, exec, k - 1)) {
    308             throwTypeError(exec, scope, ASCIILiteral("Unable to delete property."));
     308            throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError));
    309309            return;
    310310        }
     
    343343            thisObj->putByIndexInline(exec, to, value, true);
    344344        } else if (!thisObj->methodTable(vm)->deletePropertyByIndex(thisObj, exec, to)) {
    345             throwTypeError(exec, scope, ASCIILiteral("Unable to delete property."));
     345            throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError));
    346346            return;
    347347        }
     
    693693        RETURN_IF_EXCEPTION(scope, encodedJSValue());
    694694        if (!thisObj->methodTable(vm)->deletePropertyByIndex(thisObj, exec, length - 1)) {
    695             throwTypeError(exec, scope, ASCIILiteral("Unable to delete property."));
     695            throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError));
    696696            return JSValue::encode(jsUndefined());
    697697        }
     
    806806        } else if (!thisObject->methodTable(vm)->deletePropertyByIndex(thisObject, exec, lower)) {
    807807            if (!scope.exception())
    808                 throwTypeError(exec, scope, ASCIILiteral("Unable to delete property."));
     808                throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError));
    809809            return JSValue::encode(JSValue());
    810810        }
     
    815815        } else if (!thisObject->methodTable(vm)->deletePropertyByIndex(thisObject, exec, upper)) {
    816816            if (!scope.exception())
    817                 throwTypeError(exec, scope, ASCIILiteral("Unable to delete property."));
     817                throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError));
    818818            return JSValue::encode(JSValue());
    819819        }
  • trunk/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp

    r207023 r207411  
    632632    uint32_t i;
    633633    if (subscript.getUInt32(i))
    634         couldDelete = baseObject->methodTable()->deletePropertyByIndex(baseObject, exec, i);
     634        couldDelete = baseObject->methodTable(vm)->deletePropertyByIndex(baseObject, exec, i);
    635635    else {
    636636        CHECK_EXCEPTION();
    637637        auto property = subscript.toPropertyKey(exec);
    638638        CHECK_EXCEPTION();
    639         couldDelete = baseObject->methodTable()->deleteProperty(baseObject, exec, property);
     639        couldDelete = baseObject->methodTable(vm)->deleteProperty(baseObject, exec, property);
    640640    }
    641641   
    642642    if (!couldDelete && exec->codeBlock()->isStrictMode())
    643         THROW(createTypeError(exec, "Unable to delete property."));
     643        THROW(createTypeError(exec, UnableToDeletePropertyError));
    644644   
    645645    RETURN(jsBoolean(couldDelete));
  • trunk/Source/JavaScriptCore/runtime/GetterSetter.cpp

    r207023 r207411  
    9494    GetterSetter* getterSetterObj = jsCast<GetterSetter*>(getterSetter);
    9595
    96     if (getterSetterObj->isSetterNull()) {
    97         if (ecmaMode == StrictMode)
    98             throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    99         return false;
    100     }
     96    if (getterSetterObj->isSetterNull())
     97        return reject(exec, scope, ecmaMode == StrictMode, ASCIILiteral(ReadonlyPropertyWriteError));
    10198
    10299    JSObject* setter = getterSetterObj->setter();
  • trunk/Source/JavaScriptCore/runtime/JSArray.cpp

    r207023 r207411  
    130130
    131131    // 3. If P is "length", then
    132     if (propertyName == exec->propertyNames().length) {
     132    if (propertyName == vm.propertyNames->length) {
    133133        // All paths through length definition call the default [[DefineOwnProperty]], hence:
    134134        // from ES5.1 8.12.9 7.a.
    135135        if (descriptor.configurablePresent() && descriptor.configurable())
    136             return reject(exec, throwException, "Attempting to change configurable attribute of unconfigurable property.");
     136            return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeConfigurabilityError));
    137137        // from ES5.1 8.12.9 7.b.
    138138        if (descriptor.enumerablePresent() && descriptor.enumerable())
    139             return reject(exec, throwException, "Attempting to change enumerable attribute of unconfigurable property.");
     139            return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeEnumerabilityError));
    140140
    141141        // a. If the [[Value]] field of Desc is absent, then
    142142        // a.i. Return the result of calling the default [[DefineOwnProperty]] internal method (8.12.9) on A passing "length", Desc, and Throw as arguments.
    143143        if (descriptor.isAccessorDescriptor())
    144             return reject(exec, throwException, UnconfigurablePropertyChangeAccessMechanismError);
     144            return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError));
    145145        // from ES5.1 8.12.9 10.a.
    146146        if (!array->isLengthWritable() && descriptor.writablePresent() && descriptor.writable())
    147             return reject(exec, throwException, "Attempting to change writable attribute of unconfigurable property.");
     147            return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeWritabilityError));
    148148        // This descriptor is either just making length read-only, or changing nothing!
    149149        if (!descriptor.value()) {
     
    175175        // g. Reject if oldLenDesc.[[Writable]] is false.
    176176        if (!array->isLengthWritable())
    177             return reject(exec, throwException, "Attempting to change value of a readonly property.");
     177            return reject(exec, scope, throwException, ASCIILiteral(ReadonlyPropertyChangeError));
    178178       
    179179        // h. If newLenDesc.[[Writable]] is absent or has the value true, let newWritable be true.
     
    215215        // FIXME: Nothing prevents this from being called on a RuntimeArray, and the length function will always return 0 in that case.
    216216        if (index >= array->length() && !array->isLengthWritable())
    217             return reject(exec, throwException, "Attempting to define numeric property on array with non-writable length property.");
     217            return reject(exec, scope, throwException, ASCIILiteral("Attempting to define numeric property on array with non-writable length property."));
    218218        // c. Let succeeded be the result of calling the default [[DefineOwnProperty]] internal method (8.12.9) on A passing P, Desc, and false as arguments.
    219219        // d. Reject if succeeded is false.
     
    399399bool JSArray::setLengthWithArrayStorage(ExecState* exec, unsigned newLength, bool throwException, ArrayStorage* storage)
    400400{
     401    VM& vm = exec->vm();
     402    auto scope = DECLARE_THROW_SCOPE(vm);
     403
    401404    unsigned length = storage->length();
    402405   
     
    407410        // Fail if the length is not writable.
    408411        if (map->lengthIsReadOnly())
    409             return reject(exec, throwException, ReadonlyPropertyWriteError);
     412            return reject(exec, scope, throwException, ASCIILiteral(ReadonlyPropertyWriteError));
    410413
    411414        if (newLength < length) {
     
    432435                    if (it->value.attributes & DontDelete) {
    433436                        storage->setLength(index + 1);
    434                         return reject(exec, throwException, "Unable to delete property.");
     437                        return reject(exec, scope, throwException, ASCIILiteral(UnableToDeletePropertyError));
    435438                    }
    436439                    map->remove(it);
     
    626629        if (!length) {
    627630            if (!isLengthWritable())
    628                 throwTypeError(exec, scope, ReadonlyPropertyWriteError);
     631                throwTypeError(exec, scope, ASCIILiteral(ReadonlyPropertyWriteError));
    629632            return jsUndefined();
    630633        }
     
    657660    // Call the [[Delete]] internal method of O with arguments indx and true.
    658661    if (!deletePropertyByIndex(this, exec, index)) {
    659         throwTypeError(exec, scope, ASCIILiteral("Unable to delete property."));
     662        throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError));
    660663        return jsUndefined();
    661664    }
  • trunk/Source/JavaScriptCore/runtime/JSArrayBuffer.cpp

    r201226 r207411  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    9191    PutPropertySlot& slot)
    9292{
     93    VM& vm = exec->vm();
     94    auto scope = DECLARE_THROW_SCOPE(vm);
    9395    JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(cell);
    9496
     
    9698        return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode());
    9799   
    98     if (propertyName == exec->propertyNames().byteLength)
    99         return reject(exec, slot.isStrictMode(), "Attempting to write to a read-only array buffer property.");
     100    if (propertyName == vm.propertyNames->byteLength)
     101        return reject(exec, scope, slot.isStrictMode(), ASCIILiteral("Attempting to write to a read-only array buffer property."));
    100102   
    101103    return Base::put(thisObject, exec, propertyName, value, slot);
     
    106108    const PropertyDescriptor& descriptor, bool shouldThrow)
    107109{
     110    VM& vm = exec->vm();
     111    auto scope = DECLARE_THROW_SCOPE(vm);
    108112    JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(object);
    109113   
    110     if (propertyName == exec->propertyNames().byteLength)
    111         return reject(exec, shouldThrow, "Attempting to define read-only array buffer property.");
     114    if (propertyName == vm.propertyNames->byteLength)
     115        return reject(exec, scope, shouldThrow, ASCIILiteral("Attempting to define read-only array buffer property."));
    112116   
    113117    return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
  • trunk/Source/JavaScriptCore/runtime/JSCJSValue.cpp

    r207023 r207411  
    159159        return false;
    160160    JSValue prototype;
    161     if (propertyName != exec->propertyNames().underscoreProto) {
     161    if (propertyName != vm.propertyNames->underscoreProto) {
    162162        for (; !obj->structure()->hasReadOnlyOrGetterSetterPropertiesExcludingProto(); obj = asObject(prototype)) {
    163163            prototype = obj->getPrototypeDirect();
    164             if (prototype.isNull()) {
    165                 if (slot.isStrictMode())
    166                     throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    167                 return false;
    168             }
     164            if (prototype.isNull())
     165                return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    169166        }
    170167    }
     
    174171        PropertyOffset offset = obj->structure()->get(vm, propertyName, attributes);
    175172        if (offset != invalidOffset) {
    176             if (attributes & ReadOnly) {
    177                 if (slot.isStrictMode())
    178                     throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    179                 return false;
    180             }
     173            if (attributes & ReadOnly)
     174                return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    181175
    182176            JSValue gs = obj->getDirect(offset);
     
    198192    }
    199193   
    200     if (slot.isStrictMode())
    201         throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    202     return false;
     194    return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    203195}
    204196
     
    222214        return putResult;
    223215   
    224     if (shouldThrow)
    225         throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    226     return false;
     216    return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    227217}
    228218
  • trunk/Source/JavaScriptCore/runtime/JSDataView.cpp

    r205198 r207411  
    118118    PutPropertySlot& slot)
    119119{
     120    VM& vm = exec->vm();
     121    auto scope = DECLARE_THROW_SCOPE(vm);
    120122    JSDataView* thisObject = jsCast<JSDataView*>(cell);
    121123
     
    123125        return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode());
    124126
    125     if (propertyName == exec->propertyNames().byteLength
    126         || propertyName == exec->propertyNames().byteOffset)
    127         return reject(exec, slot.isStrictMode(), "Attempting to write to read-only typed array property.");
     127    if (propertyName == vm.propertyNames->byteLength
     128        || propertyName == vm.propertyNames->byteOffset)
     129        return reject(exec, scope, slot.isStrictMode(), ASCIILiteral("Attempting to write to read-only typed array property."));
    128130
    129131    return Base::put(thisObject, exec, propertyName, value, slot);
     
    134136    const PropertyDescriptor& descriptor, bool shouldThrow)
    135137{
     138    VM& vm = exec->vm();
     139    auto scope = DECLARE_THROW_SCOPE(vm);
    136140    JSDataView* thisObject = jsCast<JSDataView*>(object);
    137     if (propertyName == exec->propertyNames().byteLength
    138         || propertyName == exec->propertyNames().byteOffset)
    139         return reject(exec, shouldThrow, "Attempting to define read-only typed array property.");
     141    if (propertyName == vm.propertyNames->byteLength
     142        || propertyName == vm.propertyNames->byteOffset)
     143        return reject(exec, scope, shouldThrow, ASCIILiteral("Attempting to define read-only typed array property."));
    140144
    141145    return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
  • trunk/Source/JavaScriptCore/runtime/JSFunction.cpp

    r207347 r207411  
    447447    }
    448448
    449     if ((thisObject->jsExecutable()->isStrictMode() || thisObject->jsExecutable()->isES6Function()) && (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().caller)) {
     449    if ((thisObject->jsExecutable()->isStrictMode() || thisObject->jsExecutable()->isES6Function()) && (propertyName == vm.propertyNames->arguments || propertyName == vm.propertyNames->caller)) {
    450450        // This will trigger the property to be reified, if this is not already the case!
    451451        bool okay = thisObject->hasProperty(exec, propertyName);
     
    454454        return Base::put(thisObject, exec, propertyName, value, slot);
    455455    }
    456     if (propertyName == vm.propertyNames->arguments || propertyName == vm.propertyNames->caller) {
    457         if (slot.isStrictMode())
    458             throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    459         return false;
    460     }
     456    if (propertyName == vm.propertyNames->arguments || propertyName == vm.propertyNames->caller)
     457        return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    461458    thisObject->reifyLazyPropertyIfNeeded(vm, exec, propertyName);
    462459    scope.release();
     
    511508
    512509    bool valueCheck;
    513     if (propertyName == exec->propertyNames().arguments) {
     510    if (propertyName == vm.propertyNames->arguments) {
    514511        if (thisObject->jsExecutable()->isClass()) {
    515512            thisObject->reifyLazyPropertyIfNeeded(vm, exec, propertyName);
     
    523520        }
    524521        valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), retrieveArguments(exec, thisObject));
    525     } else if (propertyName == exec->propertyNames().caller) {
     522    } else if (propertyName == vm.propertyNames->caller) {
    526523        if (thisObject->jsExecutable()->isClass()) {
    527524            thisObject->reifyLazyPropertyIfNeeded(vm, exec, propertyName);
     
    540537    }
    541538     
    542     if (descriptor.configurablePresent() && descriptor.configurable()) {
    543         if (throwException)
    544             throwTypeError(exec, scope, ASCIILiteral("Attempting to change configurable attribute of unconfigurable property."));
    545         return false;
    546     }
    547     if (descriptor.enumerablePresent() && descriptor.enumerable()) {
    548         if (throwException)
    549             throwTypeError(exec, scope, ASCIILiteral("Attempting to change enumerable attribute of unconfigurable property."));
    550         return false;
    551     }
    552     if (descriptor.isAccessorDescriptor()) {
    553         if (throwException)
    554             throwTypeError(exec, scope, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError));
    555         return false;
    556     }
    557     if (descriptor.writablePresent() && descriptor.writable()) {
    558         if (throwException)
    559             throwTypeError(exec, scope, ASCIILiteral("Attempting to change writable attribute of unconfigurable property."));
    560         return false;
    561     }
    562     if (!valueCheck) {
    563         if (throwException)
    564             throwTypeError(exec, scope, ASCIILiteral("Attempting to change value of a readonly property."));
    565         return false;
    566     }
     539    if (descriptor.configurablePresent() && descriptor.configurable())
     540        return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeConfigurabilityError));
     541    if (descriptor.enumerablePresent() && descriptor.enumerable())
     542        return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeEnumerabilityError));
     543    if (descriptor.isAccessorDescriptor())
     544        return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError));
     545    if (descriptor.writablePresent() && descriptor.writable())
     546        return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeWritabilityError));
     547    if (!valueCheck)
     548        return reject(exec, scope, throwException, ASCIILiteral(ReadonlyPropertyChangeError));
    567549    return true;
    568550}
  • trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h

    r206525 r207411  
    8989};
    9090
    91 static const char* typedArrayBufferHasBeenDetachedErrorMessage = "Underlying ArrayBuffer has been detached from the view";
     91static const char* const typedArrayBufferHasBeenDetachedErrorMessage = "Underlying ArrayBuffer has been detached from the view";
    9292
    9393template<typename Adaptor>
     
    177177
    178178        if (isNeutered()) {
    179             throwTypeError(exec, scope, typedArrayBufferHasBeenDetachedErrorMessage);
     179            throwTypeError(exec, scope, ASCIILiteral(typedArrayBufferHasBeenDetachedErrorMessage));
    180180            return false;
    181181        }
  • trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h

    r206525 r207411  
    361361    const PropertyDescriptor& descriptor, bool shouldThrow)
    362362{
     363    VM& vm = exec->vm();
     364    auto scope = DECLARE_THROW_SCOPE(vm);
    363365    JSGenericTypedArrayView* thisObject = jsCast<JSGenericTypedArrayView*>(object);
    364366
    365367    if (parseIndex(propertyName)) {
    366368        if (descriptor.isAccessorDescriptor())
    367             return reject(exec, shouldThrow, "Attempting to store accessor indexed property on a typed array.");
     369            return reject(exec, scope, shouldThrow, ASCIILiteral("Attempting to store accessor indexed property on a typed array."));
    368370
    369371        if (descriptor.configurable())
    370             return reject(exec, shouldThrow, "Attempting to configure non-configurable property.");
     372            return reject(exec, scope, shouldThrow, ASCIILiteral("Attempting to configure non-configurable property."));
    371373
    372374        if (!descriptor.enumerable() || !descriptor.writable())
    373             return reject(exec, shouldThrow, "Attempting to store non-enumerable or non-writable indexed property on a typed array.");
     375            return reject(exec, scope, shouldThrow, ASCIILiteral("Attempting to store non-enumerable or non-writable indexed property on a typed array."));
    374376
    375377        if (descriptor.value()) {
     
    387389    JSCell* cell, ExecState* exec, PropertyName propertyName)
    388390{
     391    VM& vm = exec->vm();
     392    auto scope = DECLARE_THROW_SCOPE(vm);
    389393    JSGenericTypedArrayView* thisObject = jsCast<JSGenericTypedArrayView*>(cell);
    390394
    391395    if (thisObject->isNeutered())
    392         return reject(exec, true, typedArrayBufferHasBeenDetachedErrorMessage);
     396        return reject(exec, scope, true, ASCIILiteral(typedArrayBufferHasBeenDetachedErrorMessage));
    393397
    394398    if (parseIndex(propertyName))
  • trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h

    r206525 r207411  
    5050    auto scope = DECLARE_THROW_SCOPE(vm);
    5151
    52     JSValue constructor = exemplar->get(exec, exec->propertyNames().constructor);
     52    JSValue constructor = exemplar->get(exec, vm.propertyNames->constructor);
    5353    RETURN_IF_EXCEPTION(scope, nullptr);
    5454
     
    6060    }
    6161
    62     JSValue species = constructor.get(exec, exec->propertyNames().speciesSymbol);
     62    JSValue species = constructor.get(exec, vm.propertyNames->speciesSymbol);
    6363    RETURN_IF_EXCEPTION(scope, nullptr);
    6464
     
    7373            return view;
    7474
    75         throwTypeError(exec, scope, typedArrayBufferHasBeenDetachedErrorMessage);
     75        throwTypeError(exec, scope, ASCIILiteral(typedArrayBufferHasBeenDetachedErrorMessage));
    7676        return nullptr;
    7777    }
     
    553553        return JSValue::encode(result);
    554554
    555     throwTypeError(exec, scope, "species constructor did not return a TypedArray View");
     555    throwTypeError(exec, scope, ASCIILiteral("species constructor did not return a TypedArray View"));
    556556    return JSValue::encode(JSValue());
    557557}
  • trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp

    r207023 r207411  
    205205    // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-defineownproperty-p-desc
    206206    if (shouldThrow)
    207         throwTypeError(exec, scope, ASCIILiteral("Attempting to define property on object that is not extensible."));
     207        throwTypeError(exec, scope, ASCIILiteral(NonExtensibleObjectPropertyDefineError));
    208208    return false;
    209209}
  • trunk/Source/JavaScriptCore/runtime/JSObject.cpp

    r207023 r207411  
    6262STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSFinalObject);
    6363
    64 const char* ReadonlyPropertyWriteError = "Attempted to assign to readonly property.";
    65 const char* UnconfigurablePropertyChangeAccessMechanismError = "Attempting to change access mechanism for an unconfigurable property.";
     64const char* const NonExtensibleObjectPropertyDefineError = "Attempting to define property on object that is not extensible.";
     65const char* const ReadonlyPropertyWriteError = "Attempted to assign to readonly property.";
     66const char* const ReadonlyPropertyChangeError = "Attempting to change value of a readonly property.";
     67const char* const UnableToDeletePropertyError = "Unable to delete property.";
     68const char* const UnconfigurablePropertyChangeAccessMechanismError = "Attempting to change access mechanism for an unconfigurable property.";
     69const char* const UnconfigurablePropertyChangeConfigurabilityError = "Attempting to change configurable attribute of unconfigurable property.";
     70const char* const UnconfigurablePropertyChangeEnumerabilityError = "Attempting to change enumerable attribute of unconfigurable property.";
     71const char* const UnconfigurablePropertyChangeWritabilityError = "Attempting to change writable attribute of unconfigurable property.";
    6672
    6773const ClassInfo JSObject::s_info = { "Object", 0, 0, CREATE_METHOD_TABLE(JSObject) };
     
    390396        // 9.1.9.1-4-a If ownDesc.[[Writable]] is false, return false.
    391397        if (!ownDescriptor.writable())
    392             return reject(exec, shouldThrow, ReadonlyPropertyWriteError);
     398            return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    393399
    394400        // 9.1.9.1-4-b If Type(Receiver) is not Object, return false.
    395401        if (!receiver.isObject())
    396             return reject(exec, shouldThrow, ReadonlyPropertyWriteError);
     402            return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    397403
    398404        // In OrdinarySet, the receiver may not be the same to the object.
     
    409415            // 9.1.9.1-4-d-i If IsAccessorDescriptor(existingDescriptor) is true, return false.
    410416            if (existingDescriptor.isAccessorDescriptor())
    411                 return reject(exec, shouldThrow, ReadonlyPropertyWriteError);
     417                return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    412418
    413419            // 9.1.9.1-4-d-ii If existingDescriptor.[[Writable]] is false, return false.
    414420            if (!existingDescriptor.writable())
    415                 return reject(exec, shouldThrow, ReadonlyPropertyWriteError);
     421                return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    416422
    417423            // 9.1.9.1-4-d-iii Let valueDesc be the PropertyDescriptor{[[Value]]: V}.
     
    435441    JSValue setter = ownDescriptor.setter();
    436442    if (!setter.isObject())
    437         return reject(exec, shouldThrow, ReadonlyPropertyWriteError);
     443        return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    438444
    439445    // 9.1.9.1-8 Perform ? Call(setter, Receiver, << V >>).
     
    443449
    444450    CallData callData;
    445     CallType callType = setterObject->methodTable(exec->vm())->getCallData(setterObject, callData);
     451    CallType callType = setterObject->methodTable(vm)->getCallData(setterObject, callData);
    446452    call(exec, setterObject, callType, callData, receiver, args);
    447453
     
    461467
    462468    VM& vm = exec->vm();
     469    auto scope = DECLARE_THROW_SCOPE(vm);
    463470
    464471    JSObject* obj = this;
     
    468475        if (isValidOffset(offset)) {
    469476            if (attributes & ReadOnly) {
    470                 ASSERT(structure(vm)->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName) || obj == this);
    471                 return reject(exec, slot.isStrictMode(), ReadonlyPropertyWriteError);
     477                ASSERT(structure(vm)->prototypeChainMayInterceptStoreTo(vm, propertyName) || obj == this);
     478                return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    472479            }
    473480
     
    512519    }
    513520
    514     ASSERT(!structure(vm)->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName) || obj == this);
     521    ASSERT(!structure(vm)->prototypeChainMayInterceptStoreTo(vm, propertyName) || obj == this);
    515522    if (!putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot))
    516         return reject(exec, slot.isStrictMode(), ReadonlyPropertyWriteError);
     523        return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    517524    return true;
    518525}
     
    12961303    RETURN_IF_EXCEPTION(scope, false);
    12971304
    1298     if (!isExtensible) {
    1299         if (shouldThrowIfCantSet)
    1300             throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    1301         return false;
    1302     }
     1305    if (!isExtensible)
     1306        return reject(exec, scope, shouldThrowIfCantSet, ASCIILiteral(ReadonlyPropertyWriteError));
    13031307
    13041308    JSValue nextPrototype = prototype;
    13051309    while (nextPrototype && nextPrototype.isObject()) {
    1306         if (nextPrototype == this) {
    1307             if (shouldThrowIfCantSet)
    1308                 throwTypeError(exec, scope, ASCIILiteral("cyclic __proto__ value"));
    1309             return false;
    1310         }
     1310        if (nextPrototype == this)
     1311            return reject(exec, scope, shouldThrowIfCantSet, ASCIILiteral("cyclic __proto__ value"));
    13111312        // FIXME: The specification currently says we should check if the [[GetPrototypeOf]] internal method of nextPrototype
    13121313        // is not the ordinary object internal method. However, we currently restrict this to Proxy objects as it would allow
     
    19881989bool JSObject::defineOwnIndexedProperty(ExecState* exec, unsigned index, const PropertyDescriptor& descriptor, bool throwException)
    19891990{
     1991    VM& vm = exec->vm();
     1992    auto scope = DECLARE_THROW_SCOPE(vm);
     1993
    19901994    ASSERT(index <= MAX_ARRAY_INDEX);
    19911995
     
    20002004        }
    20012005       
    2002         ensureArrayStorageExistsAndEnterDictionaryIndexingMode(exec->vm());
     2006        ensureArrayStorageExistsAndEnterDictionaryIndexingMode(vm);
    20032007    }
    20042008
    20052009    if (descriptor.attributes() & (ReadOnly | Accessor))
    2006         notifyPresenceOfIndexedAccessors(exec->vm());
     2010        notifyPresenceOfIndexedAccessors(vm);
    20072011
    20082012    SparseArrayValueMap* map = m_butterfly.get()->arrayStorage()->m_sparseMap.get();
     
    20192023        if (!isStructureExtensible()) {
    20202024            map->remove(result.iterator);
    2021             return reject(exec, throwException, "Attempting to define property on object that is not extensible.");
     2025            return reject(exec, scope, throwException, ASCIILiteral(NonExtensibleObjectPropertyDefineError));
    20222026        }
    20232027
     
    20552059        // 7.a. Reject, if the [[Configurable]] field of Desc is true.
    20562060        if (descriptor.configurablePresent() && descriptor.configurable())
    2057             return reject(exec, throwException, "Attempting to change configurable attribute of unconfigurable property.");
     2061            return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeConfigurabilityError));
    20582062        // 7.b. Reject, if the [[Enumerable]] field of Desc is present and the [[Enumerable]] fields of current and Desc are the Boolean negation of each other.
    20592063        if (descriptor.enumerablePresent() && current.enumerable() != descriptor.enumerable())
    2060             return reject(exec, throwException, "Attempting to change enumerable attribute of unconfigurable property.");
     2064            return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeEnumerabilityError));
    20612065    }
    20622066
     
    20672071            // 9.a. Reject, if the [[Configurable]] field of current is false.
    20682072            if (!current.configurable())
    2069                 return reject(exec, throwException, UnconfigurablePropertyChangeAccessMechanismError);
     2073                return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError));
    20702074            // 9.b. If IsDataDescriptor(current) is true, then convert the property named P of object O from a
    20712075            // data property to an accessor property. Preserve the existing values of the converted property's
     
    20812085                // 10.a.i. Reject, if the [[Writable]] field of current is false and the [[Writable]] field of Desc is true.
    20822086                if (descriptor.writable())
    2083                     return reject(exec, throwException, "Attempting to change writable attribute of unconfigurable property.");
     2087                    return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeWritabilityError));
    20842088                // 10.a.ii. If the [[Writable]] field of current is false, then
    20852089                // 10.a.ii.1. Reject, if the [[Value]] field of Desc is present and SameValue(Desc.[[Value]], current.[[Value]]) is false.
    20862090                if (descriptor.value() && !sameValue(exec, descriptor.value(), current.value()))
    2087                     return reject(exec, throwException, "Attempting to change value of a readonly property.");
     2091                    return reject(exec, scope, throwException, ASCIILiteral(ReadonlyPropertyChangeError));
    20882092            }
    20892093            // 10.b. else, the [[Configurable]] field of current is true, so any change is acceptable.
     
    20942098                // 11.i. Reject, if the [[Set]] field of Desc is present and SameValue(Desc.[[Set]], current.[[Set]]) is false.
    20952099                if (descriptor.setterPresent() && descriptor.setter() != current.setter())
    2096                     return reject(exec, throwException, "Attempting to change the setter of an unconfigurable property.");
     2100                    return reject(exec, scope, throwException, ASCIILiteral("Attempting to change the setter of an unconfigurable property."));
    20972101                // 11.ii. Reject, if the [[Get]] field of Desc is present and SameValue(Desc.[[Get]], current.[[Get]]) is false.
    20982102                if (descriptor.getterPresent() && descriptor.getter() != current.getter())
    2099                     return reject(exec, throwException, "Attempting to change the getter of an unconfigurable property.");
     2103                    return reject(exec, scope, throwException, ASCIILiteral("Attempting to change the getter of an unconfigurable property."));
    21002104            }
    21012105        }
     
    22632267    if (i >= length) {
    22642268        // Prohibit growing the array if length is not writable.
    2265         if (map->lengthIsReadOnly() || !isStructureExtensible()) {
    2266             if (shouldThrow)
    2267                 throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    2268             return false;
    2269         }
     2269        if (map->lengthIsReadOnly() || !isStructureExtensible())
     2270            return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    22702271        length = i + 1;
    22712272        storage->setLength(length);
     
    23622363{
    23632364    VM& vm = exec->vm();
     2365    auto scope = DECLARE_THROW_SCOPE(vm);
    23642366   
    23652367    // i should be a valid array index that is outside of the current vector.
     
    23932395        }
    23942396        // We don't want to, or can't use a vector to hold this property - allocate a sparse map & add the value.
    2395         map = allocateSparseIndexMap(exec->vm());
     2397        map = allocateSparseIndexMap(vm);
    23962398        return map->putDirect(exec, this, i, value, attributes, mode);
    23972399    }
     
    24032405            // Prohibit growing the array if length is not writable.
    24042406            if (map->lengthIsReadOnly())
    2405                 return reject(exec, mode == PutDirectIndexShouldThrow, ReadonlyPropertyWriteError);
     2407                return reject(exec, scope, mode == PutDirectIndexShouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    24062408            if (!isStructureExtensible())
    2407                 return reject(exec, mode == PutDirectIndexShouldThrow, "Attempting to define property on object that is not extensible.");
     2409                return reject(exec, scope, mode == PutDirectIndexShouldThrow, ASCIILiteral(NonExtensibleObjectPropertyDefineError));
    24082410        }
    24092411        length = i + 1;
     
    24142416    // We will continue  to use a sparse map if SparseMode is set, a vector would be too sparse, or if allocation fails.
    24152417    unsigned numValuesInArray = storage->m_numValuesInVector + map->size();
    2416     if (map->sparseMode() || attributes || !isDenseEnoughForVector(length, numValuesInArray) || !increaseVectorLength(exec->vm(), length))
     2418    if (map->sparseMode() || attributes || !isDenseEnoughForVector(length, numValuesInArray) || !increaseVectorLength(vm, length))
    24172419        return map->putDirect(exec, this, i, value, attributes, mode);
    24182420
     
    29172919        // unless extensions are prevented!
    29182920        // Step 2.a
    2919         if (!isExtensible) {
    2920             if (throwException)
    2921                 throwTypeError(exec, scope, ASCIILiteral("Attempting to define property on object that is not extensible."));
    2922             return false;
    2923         }
     2921        if (!isExtensible)
     2922            return reject(exec, scope, throwException, ASCIILiteral(NonExtensibleObjectPropertyDefineError));
    29242923        if (!object)
    29252924            return true;
     
    29402939    // Filter out invalid changes
    29412940    if (!current.configurable()) {
    2942         if (descriptor.configurable()) {
    2943             if (throwException)
    2944                 throwTypeError(exec, scope, ASCIILiteral("Attempting to change configurable attribute of unconfigurable property."));
    2945             return false;
    2946         }
    2947         if (descriptor.enumerablePresent() && descriptor.enumerable() != current.enumerable()) {
    2948             if (throwException)
    2949                 throwTypeError(exec, scope, ASCIILiteral("Attempting to change enumerable attribute of unconfigurable property."));
    2950             return false;
    2951         }
     2941        if (descriptor.configurable())
     2942            return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeConfigurabilityError));
     2943        if (descriptor.enumerablePresent() && descriptor.enumerable() != current.enumerable())
     2944            return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeEnumerabilityError));
    29522945    }
    29532946   
     
    29652958    // Changing between a normal property or an accessor property
    29662959    if (descriptor.isDataDescriptor() != current.isDataDescriptor()) {
    2967         if (!current.configurable()) {
    2968             if (throwException)
    2969                 throwTypeError(exec, scope, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError));
    2970             return false;
    2971         }
     2960        if (!current.configurable())
     2961            return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError));
    29722962
    29732963        if (!object)
     
    29822972    if (descriptor.isDataDescriptor()) {
    29832973        if (!current.configurable()) {
    2984             if (!current.writable() && descriptor.writable()) {
    2985                 if (throwException)
    2986                     throwTypeError(exec, scope, ASCIILiteral("Attempting to change writable attribute of unconfigurable property."));
    2987                 return false;
    2988             }
     2974            if (!current.writable() && descriptor.writable())
     2975                return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeWritabilityError));
    29892976            if (!current.writable()) {
    2990                 if (descriptor.value() && !sameValue(exec, current.value(), descriptor.value())) {
    2991                     if (throwException)
    2992                         throwTypeError(exec, scope, ASCIILiteral("Attempting to change value of a readonly property."));
    2993                     return false;
    2994                 }
     2977                if (descriptor.value() && !sameValue(exec, current.value(), descriptor.value()))
     2978                    return reject(exec, scope, throwException, ASCIILiteral(ReadonlyPropertyChangeError));
    29952979            }
    29962980        }
     
    30072991    ASSERT(descriptor.isAccessorDescriptor());
    30082992    if (!current.configurable()) {
    3009         if (descriptor.setterPresent() && !(current.setterPresent() && JSValue::strictEqual(exec, current.setter(), descriptor.setter()))) {
    3010             if (throwException)
    3011                 throwTypeError(exec, scope, ASCIILiteral("Attempting to change the setter of an unconfigurable property."));
    3012             return false;
    3013         }
    3014         if (descriptor.getterPresent() && !(current.getterPresent() && JSValue::strictEqual(exec, current.getter(), descriptor.getter()))) {
    3015             if (throwException)
    3016                 throwTypeError(exec, scope, ASCIILiteral("Attempting to change the getter of an unconfigurable property."));
    3017             return false;
    3018         }
    3019         if (current.attributes() & CustomAccessor) {
    3020             if (throwException)
    3021                 throwTypeError(exec, scope, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError));
    3022             return false;
    3023         }
     2993        if (descriptor.setterPresent() && !(current.setterPresent() && JSValue::strictEqual(exec, current.setter(), descriptor.setter())))
     2994            return reject(exec, scope, throwException, ASCIILiteral("Attempting to change the setter of an unconfigurable property."));
     2995        if (descriptor.getterPresent() && !(current.getterPresent() && JSValue::strictEqual(exec, current.getter(), descriptor.getter())))
     2996            return reject(exec, scope, throwException, ASCIILiteral("Attempting to change the getter of an unconfigurable property."));
     2997        if (current.attributes() & CustomAccessor)
     2998            return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError));
    30242999    }
    30253000
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r207023 r207411  
    6969
    7070JS_EXPORT_PRIVATE JSObject* throwTypeError(ExecState*, ThrowScope&, const String&);
    71 extern JS_EXPORTDATA const char* ReadonlyPropertyWriteError;
    72 extern JS_EXPORTDATA const char* UnconfigurablePropertyChangeAccessMechanismError;
     71extern JS_EXPORTDATA const char* const NonExtensibleObjectPropertyDefineError;
     72extern JS_EXPORTDATA const char* const ReadonlyPropertyWriteError;
     73extern JS_EXPORTDATA const char* const ReadonlyPropertyChangeError;
     74extern JS_EXPORTDATA const char* const UnableToDeletePropertyError;
     75extern JS_EXPORTDATA const char* const UnconfigurablePropertyChangeAccessMechanismError;
     76extern JS_EXPORTDATA const char* const UnconfigurablePropertyChangeConfigurabilityError;
     77extern JS_EXPORTDATA const char* const UnconfigurablePropertyChangeEnumerabilityError;
     78extern JS_EXPORTDATA const char* const UnconfigurablePropertyChangeWritabilityError;
    7379
    7480COMPILE_ASSERT(None < FirstInternalAttribute, None_is_below_FirstInternalAttribute);
  • trunk/Source/JavaScriptCore/runtime/JSObjectInlines.h

    r207023 r207411  
    178178    if (thisObject->canPerformFastPutInline(exec, vm, propertyName)) {
    179179        ASSERT(!thisObject->structure(vm)->prototypeChainMayInterceptStoreTo(vm, propertyName));
    180         if (!thisObject->putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot)) {
    181             if (slot.isStrictMode())
    182                 throwTypeError(exec, scope, ASCIILiteral(ReadonlyPropertyWriteError));
    183             return false;
    184         }
     180        if (!thisObject->putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot))
     181            return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    185182        return true;
    186183    }
  • trunk/Source/JavaScriptCore/runtime/JSProxy.cpp

    r206154 r207411  
    11/*
    2  * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011-2012, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    151151    auto scope = DECLARE_THROW_SCOPE(exec->vm());
    152152
    153     if (shouldThrowIfCantSet)
    154         throwTypeError(exec, scope, ASCIILiteral("Cannot set prototype of this object"));
    155 
    156     return false;
     153    return reject(exec, scope, shouldThrowIfCantSet, ASCIILiteral("Cannot set prototype of this object"));
    157154}
    158155
  • trunk/Source/JavaScriptCore/runtime/JSSymbolTableObject.h

    r207023 r207411  
    184184        if (fastEntry.isReadOnly() && !ignoreReadOnlyErrors) {
    185185            if (shouldThrowReadOnlyError)
    186                 throwTypeError(exec, scope, ReadonlyPropertyWriteError);
     186                throwTypeError(exec, scope, ASCIILiteral(ReadonlyPropertyWriteError));
    187187            putResult = false;
    188188            return true;
  • trunk/Source/JavaScriptCore/runtime/Lookup.h

    r207023 r207411  
    255255inline bool putEntry(ExecState* exec, const HashTableValue* entry, JSObject* base, JSObject* thisValue, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
    256256{
     257    VM& vm = exec->vm();
     258    auto scope = DECLARE_THROW_SCOPE(vm);
     259
    257260    if (entry->attributes() & BuiltinOrFunctionOrLazyProperty) {
    258261        if (!(entry->attributes() & ReadOnly)) {
     
    260263            // logically the object already had the property, so this is just a replace.
    261264            if (JSObject* thisObject = jsDynamicCast<JSObject*>(thisValue))
    262                 thisObject->putDirect(exec->vm(), propertyName, value);
     265                thisObject->putDirect(vm, propertyName, value);
    263266            return true;
    264267        }
    265         return reject(exec, slot.isStrictMode(), ReadonlyPropertyWriteError);
     268        return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    266269    }
    267270
    268271    if (entry->attributes() & Accessor)
    269         return reject(exec, slot.isStrictMode(), ReadonlyPropertyWriteError);
     272        return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    270273
    271274    if (!(entry->attributes() & ReadOnly)) {
     
    281284    }
    282285
    283     return reject(exec, slot.isStrictMode(), ReadonlyPropertyWriteError);
     286    return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    284287}
    285288
  • trunk/Source/JavaScriptCore/runtime/RegExpObject.cpp

    r206386 r207411  
    102102bool RegExpObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
    103103{
    104     if (propertyName == exec->propertyNames().lastIndex) {
     104    VM& vm = exec->vm();
     105    auto scope = DECLARE_THROW_SCOPE(vm);
     106
     107    if (propertyName == vm.propertyNames->lastIndex) {
    105108        RegExpObject* regExp = asRegExpObject(object);
    106109        if (descriptor.configurablePresent() && descriptor.configurable())
    107             return reject(exec, shouldThrow, "Attempting to change configurable attribute of unconfigurable property.");
     110            return reject(exec, scope, shouldThrow, ASCIILiteral(UnconfigurablePropertyChangeConfigurabilityError));
    108111        if (descriptor.enumerablePresent() && descriptor.enumerable())
    109             return reject(exec, shouldThrow, "Attempting to change enumerable attribute of unconfigurable property.");
     112            return reject(exec, scope, shouldThrow, ASCIILiteral(UnconfigurablePropertyChangeEnumerabilityError));
    110113        if (descriptor.isAccessorDescriptor())
    111             return reject(exec, shouldThrow, UnconfigurablePropertyChangeAccessMechanismError);
     114            return reject(exec, scope, shouldThrow, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError));
    112115        if (!regExp->m_lastIndexIsWritable) {
    113116            if (descriptor.writablePresent() && descriptor.writable())
    114                 return reject(exec, shouldThrow, "Attempting to change writable attribute of unconfigurable property.");
     117                return reject(exec, scope, shouldThrow, ASCIILiteral(UnconfigurablePropertyChangeWritabilityError));
    115118            if (!sameValue(exec, regExp->getLastIndex(), descriptor.value()))
    116                 return reject(exec, shouldThrow, "Attempting to change value of a readonly property.");
     119                return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyChangeError));
    117120            return true;
    118121        }
  • trunk/Source/JavaScriptCore/runtime/RegExpObject.h

    r207023 r207411  
    2323#include "JSObject.h"
    2424#include "RegExp.h"
     25#include "Reject.h"
    2526#include "ThrowScope.h"
    2627
     
    5152            return true;
    5253        }
    53         throwTypeError(exec, scope, ReadonlyPropertyWriteError);
     54        throwTypeError(exec, scope, ASCIILiteral(ReadonlyPropertyWriteError));
    5455        return false;
    5556    }
     
    6061
    6162        if (LIKELY(m_lastIndexIsWritable)) {
    62             m_lastIndex.set(exec->vm(), this, lastIndex);
     63            m_lastIndex.set(vm, this, lastIndex);
    6364            return true;
    6465        }
    6566
    66         if (shouldThrow)
    67             throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    68         return false;
     67        return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    6968    }
    7069    JSValue getLastIndex() const
  • trunk/Source/JavaScriptCore/runtime/Reject.h

    r206525 r207411  
    3131namespace JSC {
    3232
    33 inline bool reject(ExecState* exec, bool throwException, const char* message)
     33inline bool reject(ExecState* exec, ThrowScope& scope, bool throwException, ASCIILiteral message)
    3434{
    35     VM& vm = exec->vm();
    36     auto scope = DECLARE_THROW_SCOPE(vm);
    3735    if (throwException)
    3836        throwTypeError(exec, scope, message);
  • trunk/Source/JavaScriptCore/runtime/SparseArrayValueMap.cpp

    r207178 r207411  
    103103    if (result.isNewEntry && !array->isStructureExtensible()) {
    104104        remove(result.iterator);
    105         if (shouldThrow)
    106             throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    107         return false;
     105        return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    108106    }
    109107   
     
    113111bool SparseArrayValueMap::putDirect(ExecState* exec, JSObject* array, unsigned i, JSValue value, unsigned attributes, PutDirectIndexMode mode)
    114112{
     113    VM& vm = exec->vm();
     114    auto scope = DECLARE_THROW_SCOPE(vm);
    115115    ASSERT(value);
    116116   
     117    bool shouldThrow = (mode == PutDirectIndexShouldThrow);
     118
    117119    AddResult result = add(array, i);
    118120    SparseArrayEntry& entry = result.iterator->value;
     
    124126        if (result.isNewEntry) {
    125127            remove(result.iterator);
    126             return reject(exec, mode == PutDirectIndexShouldThrow, "Attempting to define property on object that is not extensible.");
     128            return reject(exec, scope, shouldThrow, ASCIILiteral(NonExtensibleObjectPropertyDefineError));
    127129        }
    128130        if (entry.attributes & ReadOnly)
    129             return reject(exec, mode == PutDirectIndexShouldThrow, ReadonlyPropertyWriteError);
     131            return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    130132    }
    131133    entry.attributes = attributes;
    132     entry.set(exec->vm(), this, value);
     134    entry.set(vm, this, value);
    133135    return true;
    134136}
     
    158160
    159161    if (!(attributes & Accessor)) {
    160         if (attributes & ReadOnly) {
    161             if (shouldThrow)
    162                 throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    163             return false;
    164         }
     162        if (attributes & ReadOnly)
     163            return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    165164
    166165        set(vm, map, value);
  • trunk/Source/JavaScriptCore/runtime/StringObject.cpp

    r207023 r207411  
    7171        return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode());
    7272
    73     if (propertyName == exec->propertyNames().length) {
    74         if (slot.isStrictMode())
    75             throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    76         return false;
    77     }
     73    if (propertyName == vm.propertyNames->length)
     74        return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    7875    if (Optional<uint32_t> index = parseIndex(propertyName))
    7976        return putByIndex(cell, exec, index.value(), value, slot.isStrictMode());
     
    8784
    8885    StringObject* thisObject = jsCast<StringObject*>(cell);
    89     if (thisObject->internalValue()->canGetIndex(propertyName)) {
    90         if (shouldThrow)
    91             throwTypeError(exec, scope, ReadonlyPropertyWriteError);
    92         return false;
    93     }
     86    if (thisObject->internalValue()->canGetIndex(propertyName))
     87        return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
    9488    return JSObject::putByIndex(cell, exec, propertyName, value, shouldThrow);
    9589}
  • trunk/Source/JavaScriptCore/runtime/SymbolConstructor.cpp

    r206386 r207411  
    108108}
    109109
    110 const char* SymbolKeyForTypeError = "Symbol.keyFor requires that the first argument be a symbol";
     110const char* const SymbolKeyForTypeError = "Symbol.keyFor requires that the first argument be a symbol";
    111111
    112112EncodedJSValue JSC_HOST_CALL symbolConstructorKeyFor(ExecState* exec)
     
    117117    JSValue symbolValue = exec->argument(0);
    118118    if (!symbolValue.isSymbol())
    119         return JSValue::encode(throwTypeError(exec, scope, SymbolKeyForTypeError));
     119        return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral(SymbolKeyForTypeError)));
    120120
    121121    SymbolImpl& uid = asSymbol(symbolValue)->privateName().uid();
  • trunk/Source/WebCore/ChangeLog

    r207409 r207411  
     12016-10-17  Mark Lam  <mark.lam@apple.com>
     2
     3        Use the reject() helper function for conditionally throwing TypeErrors.
     4        https://bugs.webkit.org/show_bug.cgi?id=163491
     5
     6        Reviewed by Filip Pizlo.
     7
     8        No new tests because this patch does not introduce new behavior.
     9
     10        * bindings/js/JSCryptoAlgorithmDictionary.cpp:
     11        (WebCore::createRsaKeyGenParams):
     12        * bindings/js/JSIDBDatabaseCustom.cpp:
     13        (WebCore::JSIDBDatabase::createObjectStore):
     14        * bridge/c/c_instance.cpp:
     15        (JSC::Bindings::CInstance::invokeMethod):
     16
    1172016-10-17  Miguel Gomez  <magomez@igalia.com>
    218
  • trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp

    r207150 r207411  
    245245    RefPtr<Uint8Array> publicExponentArray = toUint8Array(publicExponentValue);
    246246    if (!publicExponentArray) {
    247         throwTypeError(&state, scope, "Expected a Uint8Array in publicExponent");
     247        throwTypeError(&state, scope, ASCIILiteral("Expected a Uint8Array in publicExponent"));
    248248        return nullptr;
    249249    }
  • trunk/Source/WebCore/bindings/js/JSIDBDatabaseCustom.cpp

    r206976 r207411  
    6060    JSValue optionsValue = state.argument(1);
    6161    if (!optionsValue.isUndefinedOrNull() && !optionsValue.isObject())
    62         return throwTypeError(&state, scope, "Not an object.");
     62        return throwTypeError(&state, scope, ASCIILiteral("Not an object."));
    6363
    6464    IDBKeyPath keyPath;
  • trunk/Source/WebCore/bridge/c/c_instance.cpp

    r205569 r207411  
    161161
    162162    if (!asObject(runtimeMethod)->inherits(CRuntimeMethod::info()))
    163         return throwTypeError(exec, scope, "Attempt to invoke non-plug-in method on plug-in object.");
     163        return throwTypeError(exec, scope, ASCIILiteral("Attempt to invoke non-plug-in method on plug-in object."));
    164164
    165165    CMethod* method = static_cast<CMethod*>(runtimeMethod->method());
Note: See TracChangeset for help on using the changeset viewer.