Changeset 207411 in webkit
- Timestamp:
- Oct 17, 2016 9:59:06 AM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r207408 r207411 1 2016-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 1 98 2016-10-16 Filip Pizlo <fpizlo@apple.com> 2 99 -
trunk/Source/JavaScriptCore/jit/JITOperations.cpp
r207369 r207411 1867 1867 bool couldDelete = baseObj->methodTable(vm)->deleteProperty(baseObj, exec, Identifier::fromUid(&vm, uid)); 1868 1868 if (!couldDelete && exec->codeBlock()->isStrictMode()) 1869 throwTypeError(exec, scope, ASCIILiteral( "Unable to delete property."));1869 throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError)); 1870 1870 return couldDelete; 1871 1871 } … … 1898 1898 } 1899 1899 if (!couldDelete && exec->codeBlock()->isStrictMode()) 1900 throwTypeError(exec, scope, ASCIILiteral( "Unable to delete property."));1900 throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError)); 1901 1901 return couldDelete; 1902 1902 } -
trunk/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp
r206853 r207411 785 785 LLINT_CHECK_EXCEPTION(); 786 786 if (!couldDelete && codeBlock->isStrictMode()) 787 LLINT_THROW(createTypeError(exec, "Unable to delete property."));787 LLINT_THROW(createTypeError(exec, UnableToDeletePropertyError)); 788 788 LLINT_RETURN(jsBoolean(couldDelete)); 789 789 } … … 916 916 917 917 if (!couldDelete && exec->codeBlock()->isStrictMode()) 918 LLINT_THROW(createTypeError(exec, "Unable to delete property."));918 LLINT_THROW(createTypeError(exec, UnableToDeletePropertyError)); 919 919 920 920 LLINT_RETURN(jsBoolean(couldDelete)); -
trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp
r207344 r207411 300 300 RETURN_IF_EXCEPTION(scope, void()); 301 301 } else if (!thisObj->methodTable(vm)->deletePropertyByIndex(thisObj, exec, to)) { 302 throwTypeError(exec, scope, ASCIILiteral( "Unable to delete property."));302 throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError)); 303 303 return; 304 304 } … … 306 306 for (unsigned k = length; k > length - count; --k) { 307 307 if (!thisObj->methodTable(vm)->deletePropertyByIndex(thisObj, exec, k - 1)) { 308 throwTypeError(exec, scope, ASCIILiteral( "Unable to delete property."));308 throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError)); 309 309 return; 310 310 } … … 343 343 thisObj->putByIndexInline(exec, to, value, true); 344 344 } else if (!thisObj->methodTable(vm)->deletePropertyByIndex(thisObj, exec, to)) { 345 throwTypeError(exec, scope, ASCIILiteral( "Unable to delete property."));345 throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError)); 346 346 return; 347 347 } … … 693 693 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 694 694 if (!thisObj->methodTable(vm)->deletePropertyByIndex(thisObj, exec, length - 1)) { 695 throwTypeError(exec, scope, ASCIILiteral( "Unable to delete property."));695 throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError)); 696 696 return JSValue::encode(jsUndefined()); 697 697 } … … 806 806 } else if (!thisObject->methodTable(vm)->deletePropertyByIndex(thisObject, exec, lower)) { 807 807 if (!scope.exception()) 808 throwTypeError(exec, scope, ASCIILiteral( "Unable to delete property."));808 throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError)); 809 809 return JSValue::encode(JSValue()); 810 810 } … … 815 815 } else if (!thisObject->methodTable(vm)->deletePropertyByIndex(thisObject, exec, upper)) { 816 816 if (!scope.exception()) 817 throwTypeError(exec, scope, ASCIILiteral( "Unable to delete property."));817 throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError)); 818 818 return JSValue::encode(JSValue()); 819 819 } -
trunk/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp
r207023 r207411 632 632 uint32_t i; 633 633 if (subscript.getUInt32(i)) 634 couldDelete = baseObject->methodTable( )->deletePropertyByIndex(baseObject, exec, i);634 couldDelete = baseObject->methodTable(vm)->deletePropertyByIndex(baseObject, exec, i); 635 635 else { 636 636 CHECK_EXCEPTION(); 637 637 auto property = subscript.toPropertyKey(exec); 638 638 CHECK_EXCEPTION(); 639 couldDelete = baseObject->methodTable( )->deleteProperty(baseObject, exec, property);639 couldDelete = baseObject->methodTable(vm)->deleteProperty(baseObject, exec, property); 640 640 } 641 641 642 642 if (!couldDelete && exec->codeBlock()->isStrictMode()) 643 THROW(createTypeError(exec, "Unable to delete property."));643 THROW(createTypeError(exec, UnableToDeletePropertyError)); 644 644 645 645 RETURN(jsBoolean(couldDelete)); -
trunk/Source/JavaScriptCore/runtime/GetterSetter.cpp
r207023 r207411 94 94 GetterSetter* getterSetterObj = jsCast<GetterSetter*>(getterSetter); 95 95 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)); 101 98 102 99 JSObject* setter = getterSetterObj->setter(); -
trunk/Source/JavaScriptCore/runtime/JSArray.cpp
r207023 r207411 130 130 131 131 // 3. If P is "length", then 132 if (propertyName == exec->propertyNames().length) {132 if (propertyName == vm.propertyNames->length) { 133 133 // All paths through length definition call the default [[DefineOwnProperty]], hence: 134 134 // from ES5.1 8.12.9 7.a. 135 135 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)); 137 137 // from ES5.1 8.12.9 7.b. 138 138 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)); 140 140 141 141 // a. If the [[Value]] field of Desc is absent, then 142 142 // a.i. Return the result of calling the default [[DefineOwnProperty]] internal method (8.12.9) on A passing "length", Desc, and Throw as arguments. 143 143 if (descriptor.isAccessorDescriptor()) 144 return reject(exec, throwException, UnconfigurablePropertyChangeAccessMechanismError);144 return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError)); 145 145 // from ES5.1 8.12.9 10.a. 146 146 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)); 148 148 // This descriptor is either just making length read-only, or changing nothing! 149 149 if (!descriptor.value()) { … … 175 175 // g. Reject if oldLenDesc.[[Writable]] is false. 176 176 if (!array->isLengthWritable()) 177 return reject(exec, throwException, "Attempting to change value of a readonly property.");177 return reject(exec, scope, throwException, ASCIILiteral(ReadonlyPropertyChangeError)); 178 178 179 179 // h. If newLenDesc.[[Writable]] is absent or has the value true, let newWritable be true. … … 215 215 // FIXME: Nothing prevents this from being called on a RuntimeArray, and the length function will always return 0 in that case. 216 216 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.")); 218 218 // 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. 219 219 // d. Reject if succeeded is false. … … 399 399 bool JSArray::setLengthWithArrayStorage(ExecState* exec, unsigned newLength, bool throwException, ArrayStorage* storage) 400 400 { 401 VM& vm = exec->vm(); 402 auto scope = DECLARE_THROW_SCOPE(vm); 403 401 404 unsigned length = storage->length(); 402 405 … … 407 410 // Fail if the length is not writable. 408 411 if (map->lengthIsReadOnly()) 409 return reject(exec, throwException, ReadonlyPropertyWriteError);412 return reject(exec, scope, throwException, ASCIILiteral(ReadonlyPropertyWriteError)); 410 413 411 414 if (newLength < length) { … … 432 435 if (it->value.attributes & DontDelete) { 433 436 storage->setLength(index + 1); 434 return reject(exec, throwException, "Unable to delete property.");437 return reject(exec, scope, throwException, ASCIILiteral(UnableToDeletePropertyError)); 435 438 } 436 439 map->remove(it); … … 626 629 if (!length) { 627 630 if (!isLengthWritable()) 628 throwTypeError(exec, scope, ReadonlyPropertyWriteError);631 throwTypeError(exec, scope, ASCIILiteral(ReadonlyPropertyWriteError)); 629 632 return jsUndefined(); 630 633 } … … 657 660 // Call the [[Delete]] internal method of O with arguments indx and true. 658 661 if (!deletePropertyByIndex(this, exec, index)) { 659 throwTypeError(exec, scope, ASCIILiteral( "Unable to delete property."));662 throwTypeError(exec, scope, ASCIILiteral(UnableToDeletePropertyError)); 660 663 return jsUndefined(); 661 664 } -
trunk/Source/JavaScriptCore/runtime/JSArrayBuffer.cpp
r201226 r207411 1 1 /* 2 * Copyright (C) 2013 Apple Inc. All rights reserved.2 * Copyright (C) 2013, 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 91 91 PutPropertySlot& slot) 92 92 { 93 VM& vm = exec->vm(); 94 auto scope = DECLARE_THROW_SCOPE(vm); 93 95 JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(cell); 94 96 … … 96 98 return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode()); 97 99 98 if (propertyName == exec->propertyNames().byteLength)99 return reject(exec, s lot.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.")); 100 102 101 103 return Base::put(thisObject, exec, propertyName, value, slot); … … 106 108 const PropertyDescriptor& descriptor, bool shouldThrow) 107 109 { 110 VM& vm = exec->vm(); 111 auto scope = DECLARE_THROW_SCOPE(vm); 108 112 JSArrayBuffer* thisObject = jsCast<JSArrayBuffer*>(object); 109 113 110 if (propertyName == exec->propertyNames().byteLength)111 return reject(exec, s houldThrow, "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.")); 112 116 113 117 return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow); -
trunk/Source/JavaScriptCore/runtime/JSCJSValue.cpp
r207023 r207411 159 159 return false; 160 160 JSValue prototype; 161 if (propertyName != exec->propertyNames().underscoreProto) {161 if (propertyName != vm.propertyNames->underscoreProto) { 162 162 for (; !obj->structure()->hasReadOnlyOrGetterSetterPropertiesExcludingProto(); obj = asObject(prototype)) { 163 163 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)); 169 166 } 170 167 } … … 174 171 PropertyOffset offset = obj->structure()->get(vm, propertyName, attributes); 175 172 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)); 181 175 182 176 JSValue gs = obj->getDirect(offset); … … 198 192 } 199 193 200 if (slot.isStrictMode()) 201 throwTypeError(exec, scope, ReadonlyPropertyWriteError); 202 return false; 194 return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError)); 203 195 } 204 196 … … 222 214 return putResult; 223 215 224 if (shouldThrow) 225 throwTypeError(exec, scope, ReadonlyPropertyWriteError); 226 return false; 216 return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError)); 227 217 } 228 218 -
trunk/Source/JavaScriptCore/runtime/JSDataView.cpp
r205198 r207411 118 118 PutPropertySlot& slot) 119 119 { 120 VM& vm = exec->vm(); 121 auto scope = DECLARE_THROW_SCOPE(vm); 120 122 JSDataView* thisObject = jsCast<JSDataView*>(cell); 121 123 … … 123 125 return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode()); 124 126 125 if (propertyName == exec->propertyNames().byteLength126 || propertyName == exec->propertyNames().byteOffset)127 return reject(exec, s lot.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.")); 128 130 129 131 return Base::put(thisObject, exec, propertyName, value, slot); … … 134 136 const PropertyDescriptor& descriptor, bool shouldThrow) 135 137 { 138 VM& vm = exec->vm(); 139 auto scope = DECLARE_THROW_SCOPE(vm); 136 140 JSDataView* thisObject = jsCast<JSDataView*>(object); 137 if (propertyName == exec->propertyNames().byteLength138 || propertyName == exec->propertyNames().byteOffset)139 return reject(exec, s houldThrow, "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.")); 140 144 141 145 return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow); -
trunk/Source/JavaScriptCore/runtime/JSFunction.cpp
r207347 r207411 447 447 } 448 448 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)) { 450 450 // This will trigger the property to be reified, if this is not already the case! 451 451 bool okay = thisObject->hasProperty(exec, propertyName); … … 454 454 return Base::put(thisObject, exec, propertyName, value, slot); 455 455 } 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)); 461 458 thisObject->reifyLazyPropertyIfNeeded(vm, exec, propertyName); 462 459 scope.release(); … … 511 508 512 509 bool valueCheck; 513 if (propertyName == exec->propertyNames().arguments) {510 if (propertyName == vm.propertyNames->arguments) { 514 511 if (thisObject->jsExecutable()->isClass()) { 515 512 thisObject->reifyLazyPropertyIfNeeded(vm, exec, propertyName); … … 523 520 } 524 521 valueCheck = !descriptor.value() || sameValue(exec, descriptor.value(), retrieveArguments(exec, thisObject)); 525 } else if (propertyName == exec->propertyNames().caller) {522 } else if (propertyName == vm.propertyNames->caller) { 526 523 if (thisObject->jsExecutable()->isClass()) { 527 524 thisObject->reifyLazyPropertyIfNeeded(vm, exec, propertyName); … … 540 537 } 541 538 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)); 567 549 return true; 568 550 } -
trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h
r206525 r207411 89 89 }; 90 90 91 static const char* typedArrayBufferHasBeenDetachedErrorMessage = "Underlying ArrayBuffer has been detached from the view";91 static const char* const typedArrayBufferHasBeenDetachedErrorMessage = "Underlying ArrayBuffer has been detached from the view"; 92 92 93 93 template<typename Adaptor> … … 177 177 178 178 if (isNeutered()) { 179 throwTypeError(exec, scope, typedArrayBufferHasBeenDetachedErrorMessage);179 throwTypeError(exec, scope, ASCIILiteral(typedArrayBufferHasBeenDetachedErrorMessage)); 180 180 return false; 181 181 } -
trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h
r206525 r207411 361 361 const PropertyDescriptor& descriptor, bool shouldThrow) 362 362 { 363 VM& vm = exec->vm(); 364 auto scope = DECLARE_THROW_SCOPE(vm); 363 365 JSGenericTypedArrayView* thisObject = jsCast<JSGenericTypedArrayView*>(object); 364 366 365 367 if (parseIndex(propertyName)) { 366 368 if (descriptor.isAccessorDescriptor()) 367 return reject(exec, s houldThrow, "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.")); 368 370 369 371 if (descriptor.configurable()) 370 return reject(exec, s houldThrow, "Attempting to configure non-configurable property.");372 return reject(exec, scope, shouldThrow, ASCIILiteral("Attempting to configure non-configurable property.")); 371 373 372 374 if (!descriptor.enumerable() || !descriptor.writable()) 373 return reject(exec, s houldThrow, "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.")); 374 376 375 377 if (descriptor.value()) { … … 387 389 JSCell* cell, ExecState* exec, PropertyName propertyName) 388 390 { 391 VM& vm = exec->vm(); 392 auto scope = DECLARE_THROW_SCOPE(vm); 389 393 JSGenericTypedArrayView* thisObject = jsCast<JSGenericTypedArrayView*>(cell); 390 394 391 395 if (thisObject->isNeutered()) 392 return reject(exec, true, typedArrayBufferHasBeenDetachedErrorMessage);396 return reject(exec, scope, true, ASCIILiteral(typedArrayBufferHasBeenDetachedErrorMessage)); 393 397 394 398 if (parseIndex(propertyName)) -
trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h
r206525 r207411 50 50 auto scope = DECLARE_THROW_SCOPE(vm); 51 51 52 JSValue constructor = exemplar->get(exec, exec->propertyNames().constructor);52 JSValue constructor = exemplar->get(exec, vm.propertyNames->constructor); 53 53 RETURN_IF_EXCEPTION(scope, nullptr); 54 54 … … 60 60 } 61 61 62 JSValue species = constructor.get(exec, exec->propertyNames().speciesSymbol);62 JSValue species = constructor.get(exec, vm.propertyNames->speciesSymbol); 63 63 RETURN_IF_EXCEPTION(scope, nullptr); 64 64 … … 73 73 return view; 74 74 75 throwTypeError(exec, scope, typedArrayBufferHasBeenDetachedErrorMessage);75 throwTypeError(exec, scope, ASCIILiteral(typedArrayBufferHasBeenDetachedErrorMessage)); 76 76 return nullptr; 77 77 } … … 553 553 return JSValue::encode(result); 554 554 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")); 556 556 return JSValue::encode(JSValue()); 557 557 } -
trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp
r207023 r207411 205 205 // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-defineownproperty-p-desc 206 206 if (shouldThrow) 207 throwTypeError(exec, scope, ASCIILiteral( "Attempting to define property on object that is not extensible."));207 throwTypeError(exec, scope, ASCIILiteral(NonExtensibleObjectPropertyDefineError)); 208 208 return false; 209 209 } -
trunk/Source/JavaScriptCore/runtime/JSObject.cpp
r207023 r207411 62 62 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSFinalObject); 63 63 64 const char* ReadonlyPropertyWriteError = "Attempted to assign to readonly property."; 65 const char* UnconfigurablePropertyChangeAccessMechanismError = "Attempting to change access mechanism for an unconfigurable property."; 64 const char* const NonExtensibleObjectPropertyDefineError = "Attempting to define property on object that is not extensible."; 65 const char* const ReadonlyPropertyWriteError = "Attempted to assign to readonly property."; 66 const char* const ReadonlyPropertyChangeError = "Attempting to change value of a readonly property."; 67 const char* const UnableToDeletePropertyError = "Unable to delete property."; 68 const char* const UnconfigurablePropertyChangeAccessMechanismError = "Attempting to change access mechanism for an unconfigurable property."; 69 const char* const UnconfigurablePropertyChangeConfigurabilityError = "Attempting to change configurable attribute of unconfigurable property."; 70 const char* const UnconfigurablePropertyChangeEnumerabilityError = "Attempting to change enumerable attribute of unconfigurable property."; 71 const char* const UnconfigurablePropertyChangeWritabilityError = "Attempting to change writable attribute of unconfigurable property."; 66 72 67 73 const ClassInfo JSObject::s_info = { "Object", 0, 0, CREATE_METHOD_TABLE(JSObject) }; … … 390 396 // 9.1.9.1-4-a If ownDesc.[[Writable]] is false, return false. 391 397 if (!ownDescriptor.writable()) 392 return reject(exec, s houldThrow, ReadonlyPropertyWriteError);398 return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError)); 393 399 394 400 // 9.1.9.1-4-b If Type(Receiver) is not Object, return false. 395 401 if (!receiver.isObject()) 396 return reject(exec, s houldThrow, ReadonlyPropertyWriteError);402 return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError)); 397 403 398 404 // In OrdinarySet, the receiver may not be the same to the object. … … 409 415 // 9.1.9.1-4-d-i If IsAccessorDescriptor(existingDescriptor) is true, return false. 410 416 if (existingDescriptor.isAccessorDescriptor()) 411 return reject(exec, s houldThrow, ReadonlyPropertyWriteError);417 return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError)); 412 418 413 419 // 9.1.9.1-4-d-ii If existingDescriptor.[[Writable]] is false, return false. 414 420 if (!existingDescriptor.writable()) 415 return reject(exec, s houldThrow, ReadonlyPropertyWriteError);421 return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError)); 416 422 417 423 // 9.1.9.1-4-d-iii Let valueDesc be the PropertyDescriptor{[[Value]]: V}. … … 435 441 JSValue setter = ownDescriptor.setter(); 436 442 if (!setter.isObject()) 437 return reject(exec, s houldThrow, ReadonlyPropertyWriteError);443 return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError)); 438 444 439 445 // 9.1.9.1-8 Perform ? Call(setter, Receiver, << V >>). … … 443 449 444 450 CallData callData; 445 CallType callType = setterObject->methodTable( exec->vm())->getCallData(setterObject, callData);451 CallType callType = setterObject->methodTable(vm)->getCallData(setterObject, callData); 446 452 call(exec, setterObject, callType, callData, receiver, args); 447 453 … … 461 467 462 468 VM& vm = exec->vm(); 469 auto scope = DECLARE_THROW_SCOPE(vm); 463 470 464 471 JSObject* obj = this; … … 468 475 if (isValidOffset(offset)) { 469 476 if (attributes & ReadOnly) { 470 ASSERT(structure(vm)->prototypeChainMayInterceptStoreTo( exec->vm(), propertyName) || obj == this);471 return reject(exec, s lot.isStrictMode(), ReadonlyPropertyWriteError);477 ASSERT(structure(vm)->prototypeChainMayInterceptStoreTo(vm, propertyName) || obj == this); 478 return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError)); 472 479 } 473 480 … … 512 519 } 513 520 514 ASSERT(!structure(vm)->prototypeChainMayInterceptStoreTo( exec->vm(), propertyName) || obj == this);521 ASSERT(!structure(vm)->prototypeChainMayInterceptStoreTo(vm, propertyName) || obj == this); 515 522 if (!putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot)) 516 return reject(exec, s lot.isStrictMode(), ReadonlyPropertyWriteError);523 return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError)); 517 524 return true; 518 525 } … … 1296 1303 RETURN_IF_EXCEPTION(scope, false); 1297 1304 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)); 1303 1307 1304 1308 JSValue nextPrototype = prototype; 1305 1309 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")); 1311 1312 // FIXME: The specification currently says we should check if the [[GetPrototypeOf]] internal method of nextPrototype 1312 1313 // is not the ordinary object internal method. However, we currently restrict this to Proxy objects as it would allow … … 1988 1989 bool JSObject::defineOwnIndexedProperty(ExecState* exec, unsigned index, const PropertyDescriptor& descriptor, bool throwException) 1989 1990 { 1991 VM& vm = exec->vm(); 1992 auto scope = DECLARE_THROW_SCOPE(vm); 1993 1990 1994 ASSERT(index <= MAX_ARRAY_INDEX); 1991 1995 … … 2000 2004 } 2001 2005 2002 ensureArrayStorageExistsAndEnterDictionaryIndexingMode( exec->vm());2006 ensureArrayStorageExistsAndEnterDictionaryIndexingMode(vm); 2003 2007 } 2004 2008 2005 2009 if (descriptor.attributes() & (ReadOnly | Accessor)) 2006 notifyPresenceOfIndexedAccessors( exec->vm());2010 notifyPresenceOfIndexedAccessors(vm); 2007 2011 2008 2012 SparseArrayValueMap* map = m_butterfly.get()->arrayStorage()->m_sparseMap.get(); … … 2019 2023 if (!isStructureExtensible()) { 2020 2024 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)); 2022 2026 } 2023 2027 … … 2055 2059 // 7.a. Reject, if the [[Configurable]] field of Desc is true. 2056 2060 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)); 2058 2062 // 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. 2059 2063 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)); 2061 2065 } 2062 2066 … … 2067 2071 // 9.a. Reject, if the [[Configurable]] field of current is false. 2068 2072 if (!current.configurable()) 2069 return reject(exec, throwException, UnconfigurablePropertyChangeAccessMechanismError);2073 return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError)); 2070 2074 // 9.b. If IsDataDescriptor(current) is true, then convert the property named P of object O from a 2071 2075 // data property to an accessor property. Preserve the existing values of the converted property's … … 2081 2085 // 10.a.i. Reject, if the [[Writable]] field of current is false and the [[Writable]] field of Desc is true. 2082 2086 if (descriptor.writable()) 2083 return reject(exec, throwException, "Attempting to change writable attribute of unconfigurable property.");2087 return reject(exec, scope, throwException, ASCIILiteral(UnconfigurablePropertyChangeWritabilityError)); 2084 2088 // 10.a.ii. If the [[Writable]] field of current is false, then 2085 2089 // 10.a.ii.1. Reject, if the [[Value]] field of Desc is present and SameValue(Desc.[[Value]], current.[[Value]]) is false. 2086 2090 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)); 2088 2092 } 2089 2093 // 10.b. else, the [[Configurable]] field of current is true, so any change is acceptable. … … 2094 2098 // 11.i. Reject, if the [[Set]] field of Desc is present and SameValue(Desc.[[Set]], current.[[Set]]) is false. 2095 2099 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.")); 2097 2101 // 11.ii. Reject, if the [[Get]] field of Desc is present and SameValue(Desc.[[Get]], current.[[Get]]) is false. 2098 2102 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.")); 2100 2104 } 2101 2105 } … … 2263 2267 if (i >= length) { 2264 2268 // 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)); 2270 2271 length = i + 1; 2271 2272 storage->setLength(length); … … 2362 2363 { 2363 2364 VM& vm = exec->vm(); 2365 auto scope = DECLARE_THROW_SCOPE(vm); 2364 2366 2365 2367 // i should be a valid array index that is outside of the current vector. … … 2393 2395 } 2394 2396 // 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); 2396 2398 return map->putDirect(exec, this, i, value, attributes, mode); 2397 2399 } … … 2403 2405 // Prohibit growing the array if length is not writable. 2404 2406 if (map->lengthIsReadOnly()) 2405 return reject(exec, mode == PutDirectIndexShouldThrow, ReadonlyPropertyWriteError);2407 return reject(exec, scope, mode == PutDirectIndexShouldThrow, ASCIILiteral(ReadonlyPropertyWriteError)); 2406 2408 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)); 2408 2410 } 2409 2411 length = i + 1; … … 2414 2416 // We will continue to use a sparse map if SparseMode is set, a vector would be too sparse, or if allocation fails. 2415 2417 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)) 2417 2419 return map->putDirect(exec, this, i, value, attributes, mode); 2418 2420 … … 2917 2919 // unless extensions are prevented! 2918 2920 // 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)); 2924 2923 if (!object) 2925 2924 return true; … … 2940 2939 // Filter out invalid changes 2941 2940 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)); 2952 2945 } 2953 2946 … … 2965 2958 // Changing between a normal property or an accessor property 2966 2959 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)); 2972 2962 2973 2963 if (!object) … … 2982 2972 if (descriptor.isDataDescriptor()) { 2983 2973 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)); 2989 2976 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)); 2995 2979 } 2996 2980 } … … 3007 2991 ASSERT(descriptor.isAccessorDescriptor()); 3008 2992 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)); 3024 2999 } 3025 3000 -
trunk/Source/JavaScriptCore/runtime/JSObject.h
r207023 r207411 69 69 70 70 JS_EXPORT_PRIVATE JSObject* throwTypeError(ExecState*, ThrowScope&, const String&); 71 extern JS_EXPORTDATA const char* ReadonlyPropertyWriteError; 72 extern JS_EXPORTDATA const char* UnconfigurablePropertyChangeAccessMechanismError; 71 extern JS_EXPORTDATA const char* const NonExtensibleObjectPropertyDefineError; 72 extern JS_EXPORTDATA const char* const ReadonlyPropertyWriteError; 73 extern JS_EXPORTDATA const char* const ReadonlyPropertyChangeError; 74 extern JS_EXPORTDATA const char* const UnableToDeletePropertyError; 75 extern JS_EXPORTDATA const char* const UnconfigurablePropertyChangeAccessMechanismError; 76 extern JS_EXPORTDATA const char* const UnconfigurablePropertyChangeConfigurabilityError; 77 extern JS_EXPORTDATA const char* const UnconfigurablePropertyChangeEnumerabilityError; 78 extern JS_EXPORTDATA const char* const UnconfigurablePropertyChangeWritabilityError; 73 79 74 80 COMPILE_ASSERT(None < FirstInternalAttribute, None_is_below_FirstInternalAttribute); -
trunk/Source/JavaScriptCore/runtime/JSObjectInlines.h
r207023 r207411 178 178 if (thisObject->canPerformFastPutInline(exec, vm, propertyName)) { 179 179 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)); 185 182 return true; 186 183 } -
trunk/Source/JavaScriptCore/runtime/JSProxy.cpp
r206154 r207411 1 1 /* 2 * Copyright (C) 2011 , 2012Apple Inc. All rights reserved.2 * Copyright (C) 2011-2012, 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 151 151 auto scope = DECLARE_THROW_SCOPE(exec->vm()); 152 152 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")); 157 154 } 158 155 -
trunk/Source/JavaScriptCore/runtime/JSSymbolTableObject.h
r207023 r207411 184 184 if (fastEntry.isReadOnly() && !ignoreReadOnlyErrors) { 185 185 if (shouldThrowReadOnlyError) 186 throwTypeError(exec, scope, ReadonlyPropertyWriteError);186 throwTypeError(exec, scope, ASCIILiteral(ReadonlyPropertyWriteError)); 187 187 putResult = false; 188 188 return true; -
trunk/Source/JavaScriptCore/runtime/Lookup.h
r207023 r207411 255 255 inline bool putEntry(ExecState* exec, const HashTableValue* entry, JSObject* base, JSObject* thisValue, PropertyName propertyName, JSValue value, PutPropertySlot& slot) 256 256 { 257 VM& vm = exec->vm(); 258 auto scope = DECLARE_THROW_SCOPE(vm); 259 257 260 if (entry->attributes() & BuiltinOrFunctionOrLazyProperty) { 258 261 if (!(entry->attributes() & ReadOnly)) { … … 260 263 // logically the object already had the property, so this is just a replace. 261 264 if (JSObject* thisObject = jsDynamicCast<JSObject*>(thisValue)) 262 thisObject->putDirect( exec->vm(), propertyName, value);265 thisObject->putDirect(vm, propertyName, value); 263 266 return true; 264 267 } 265 return reject(exec, s lot.isStrictMode(), ReadonlyPropertyWriteError);268 return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError)); 266 269 } 267 270 268 271 if (entry->attributes() & Accessor) 269 return reject(exec, s lot.isStrictMode(), ReadonlyPropertyWriteError);272 return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError)); 270 273 271 274 if (!(entry->attributes() & ReadOnly)) { … … 281 284 } 282 285 283 return reject(exec, s lot.isStrictMode(), ReadonlyPropertyWriteError);286 return reject(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError)); 284 287 } 285 288 -
trunk/Source/JavaScriptCore/runtime/RegExpObject.cpp
r206386 r207411 102 102 bool RegExpObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow) 103 103 { 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) { 105 108 RegExpObject* regExp = asRegExpObject(object); 106 109 if (descriptor.configurablePresent() && descriptor.configurable()) 107 return reject(exec, s houldThrow, "Attempting to change configurable attribute of unconfigurable property.");110 return reject(exec, scope, shouldThrow, ASCIILiteral(UnconfigurablePropertyChangeConfigurabilityError)); 108 111 if (descriptor.enumerablePresent() && descriptor.enumerable()) 109 return reject(exec, s houldThrow, "Attempting to change enumerable attribute of unconfigurable property.");112 return reject(exec, scope, shouldThrow, ASCIILiteral(UnconfigurablePropertyChangeEnumerabilityError)); 110 113 if (descriptor.isAccessorDescriptor()) 111 return reject(exec, s houldThrow, UnconfigurablePropertyChangeAccessMechanismError);114 return reject(exec, scope, shouldThrow, ASCIILiteral(UnconfigurablePropertyChangeAccessMechanismError)); 112 115 if (!regExp->m_lastIndexIsWritable) { 113 116 if (descriptor.writablePresent() && descriptor.writable()) 114 return reject(exec, s houldThrow, "Attempting to change writable attribute of unconfigurable property.");117 return reject(exec, scope, shouldThrow, ASCIILiteral(UnconfigurablePropertyChangeWritabilityError)); 115 118 if (!sameValue(exec, regExp->getLastIndex(), descriptor.value())) 116 return reject(exec, s houldThrow, "Attempting to change value of a readonly property.");119 return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyChangeError)); 117 120 return true; 118 121 } -
trunk/Source/JavaScriptCore/runtime/RegExpObject.h
r207023 r207411 23 23 #include "JSObject.h" 24 24 #include "RegExp.h" 25 #include "Reject.h" 25 26 #include "ThrowScope.h" 26 27 … … 51 52 return true; 52 53 } 53 throwTypeError(exec, scope, ReadonlyPropertyWriteError);54 throwTypeError(exec, scope, ASCIILiteral(ReadonlyPropertyWriteError)); 54 55 return false; 55 56 } … … 60 61 61 62 if (LIKELY(m_lastIndexIsWritable)) { 62 m_lastIndex.set( exec->vm(), this, lastIndex);63 m_lastIndex.set(vm, this, lastIndex); 63 64 return true; 64 65 } 65 66 66 if (shouldThrow) 67 throwTypeError(exec, scope, ReadonlyPropertyWriteError); 68 return false; 67 return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError)); 69 68 } 70 69 JSValue getLastIndex() const -
trunk/Source/JavaScriptCore/runtime/Reject.h
r206525 r207411 31 31 namespace JSC { 32 32 33 inline bool reject(ExecState* exec, bool throwException, const char*message)33 inline bool reject(ExecState* exec, ThrowScope& scope, bool throwException, ASCIILiteral message) 34 34 { 35 VM& vm = exec->vm();36 auto scope = DECLARE_THROW_SCOPE(vm);37 35 if (throwException) 38 36 throwTypeError(exec, scope, message); -
trunk/Source/JavaScriptCore/runtime/SparseArrayValueMap.cpp
r207178 r207411 103 103 if (result.isNewEntry && !array->isStructureExtensible()) { 104 104 remove(result.iterator); 105 if (shouldThrow) 106 throwTypeError(exec, scope, ReadonlyPropertyWriteError); 107 return false; 105 return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError)); 108 106 } 109 107 … … 113 111 bool SparseArrayValueMap::putDirect(ExecState* exec, JSObject* array, unsigned i, JSValue value, unsigned attributes, PutDirectIndexMode mode) 114 112 { 113 VM& vm = exec->vm(); 114 auto scope = DECLARE_THROW_SCOPE(vm); 115 115 ASSERT(value); 116 116 117 bool shouldThrow = (mode == PutDirectIndexShouldThrow); 118 117 119 AddResult result = add(array, i); 118 120 SparseArrayEntry& entry = result.iterator->value; … … 124 126 if (result.isNewEntry) { 125 127 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)); 127 129 } 128 130 if (entry.attributes & ReadOnly) 129 return reject(exec, mode == PutDirectIndexShouldThrow, ReadonlyPropertyWriteError);131 return reject(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError)); 130 132 } 131 133 entry.attributes = attributes; 132 entry.set( exec->vm(), this, value);134 entry.set(vm, this, value); 133 135 return true; 134 136 } … … 158 160 159 161 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)); 165 164 166 165 set(vm, map, value); -
trunk/Source/JavaScriptCore/runtime/StringObject.cpp
r207023 r207411 71 71 return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode()); 72 72 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)); 78 75 if (Optional<uint32_t> index = parseIndex(propertyName)) 79 76 return putByIndex(cell, exec, index.value(), value, slot.isStrictMode()); … … 87 84 88 85 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)); 94 88 return JSObject::putByIndex(cell, exec, propertyName, value, shouldThrow); 95 89 } -
trunk/Source/JavaScriptCore/runtime/SymbolConstructor.cpp
r206386 r207411 108 108 } 109 109 110 const char* SymbolKeyForTypeError = "Symbol.keyFor requires that the first argument be a symbol";110 const char* const SymbolKeyForTypeError = "Symbol.keyFor requires that the first argument be a symbol"; 111 111 112 112 EncodedJSValue JSC_HOST_CALL symbolConstructorKeyFor(ExecState* exec) … … 117 117 JSValue symbolValue = exec->argument(0); 118 118 if (!symbolValue.isSymbol()) 119 return JSValue::encode(throwTypeError(exec, scope, SymbolKeyForTypeError));119 return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral(SymbolKeyForTypeError))); 120 120 121 121 SymbolImpl& uid = asSymbol(symbolValue)->privateName().uid(); -
trunk/Source/WebCore/ChangeLog
r207409 r207411 1 2016-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 1 17 2016-10-17 Miguel Gomez <magomez@igalia.com> 2 18 -
trunk/Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp
r207150 r207411 245 245 RefPtr<Uint8Array> publicExponentArray = toUint8Array(publicExponentValue); 246 246 if (!publicExponentArray) { 247 throwTypeError(&state, scope, "Expected a Uint8Array in publicExponent");247 throwTypeError(&state, scope, ASCIILiteral("Expected a Uint8Array in publicExponent")); 248 248 return nullptr; 249 249 } -
trunk/Source/WebCore/bindings/js/JSIDBDatabaseCustom.cpp
r206976 r207411 60 60 JSValue optionsValue = state.argument(1); 61 61 if (!optionsValue.isUndefinedOrNull() && !optionsValue.isObject()) 62 return throwTypeError(&state, scope, "Not an object.");62 return throwTypeError(&state, scope, ASCIILiteral("Not an object.")); 63 63 64 64 IDBKeyPath keyPath; -
trunk/Source/WebCore/bridge/c/c_instance.cpp
r205569 r207411 161 161 162 162 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.")); 164 164 165 165 CMethod* method = static_cast<CMethod*>(runtimeMethod->method());
Note: See TracChangeset
for help on using the changeset viewer.