Changeset 195360 in webkit
- Timestamp:
- Jan 20, 2016 11:32:30 AM (8 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r195330 r195360 1 2016-01-19 Keith Miller <keith_miller@apple.com> 2 3 [ES6] Fix various issues with TypedArrays. 4 https://bugs.webkit.org/show_bug.cgi?id=153245 5 6 Reviewed by Geoffrey Garen. 7 8 This patch fixes a couple of issues with TypedArrays: 9 10 1) We were not checking if a view had been neutered and throwing an error 11 if it had in the our TypedArray.prototype functions. 12 13 2) The TypedArray.prototype.set function had a couple of minor issues with 14 checking for the offset being negative. 15 16 3) The JSArrayBufferView class did not check if the backing store had 17 been neutered when computing the offset even though the view's vector 18 pointer had been set to NULL. This meant that under some conditions we 19 could, occasionally, return a garbage number as the offset. Now, we only 20 neuter views if the backing ArrayBuffer's view is actually transfered. 21 22 * jsc.cpp: 23 (GlobalObject::finishCreation): 24 (functionNeuterTypedArray): 25 * runtime/JSArrayBufferView.h: 26 (JSC::JSArrayBufferView::isNeutered): 27 * runtime/JSArrayBufferViewInlines.h: 28 (JSC::JSArrayBufferView::byteOffset): 29 * runtime/JSGenericTypedArrayViewPrototypeFunctions.h: 30 (JSC::genericTypedArrayViewProtoFuncSet): 31 (JSC::genericTypedArrayViewProtoFuncEntries): 32 (JSC::genericTypedArrayViewProtoFuncCopyWithin): 33 (JSC::genericTypedArrayViewProtoFuncFill): 34 (JSC::genericTypedArrayViewProtoFuncIndexOf): 35 (JSC::genericTypedArrayViewProtoFuncJoin): 36 (JSC::genericTypedArrayViewProtoFuncKeys): 37 (JSC::genericTypedArrayViewProtoFuncLastIndexOf): 38 (JSC::genericTypedArrayViewProtoFuncReverse): 39 (JSC::genericTypedArrayViewPrivateFuncSort): 40 (JSC::genericTypedArrayViewProtoFuncSlice): 41 (JSC::genericTypedArrayViewProtoFuncSubarray): 42 (JSC::typedArrayViewProtoFuncValues): 43 * runtime/JSTypedArrayViewPrototype.cpp: 44 (JSC::typedArrayViewPrivateFuncLength): 45 (JSC::typedArrayViewPrivateFuncSort): Deleted. 46 * tests/stress/typedarray-functions-with-neutered.js: Added. 47 (getGetter): 48 (unit): 49 (args.new.Int32Array): 50 (arrays.typedArrays.map): 51 (checkProtoFunc.throwsCorrectError): 52 (checkProtoFunc): 53 (test): 54 1 55 2016-01-19 Andy VanWagoner <thetalecrafter@gmail.com> 2 56 -
trunk/Source/JavaScriptCore/runtime/ArrayBuffer.cpp
r172129 r195360 45 45 bool isNeuterable = !m_pinCount; 46 46 47 if (isNeuterable) 48 m_contents.transfer(result); 49 else { 47 if (!isNeuterable) { 50 48 m_contents.copyTo(result); 51 49 if (!result.m_data) 52 50 return false; 51 return true; 53 52 } 54 53 54 m_contents.transfer(result); 55 55 for (size_t i = numberOfIncomingReferences(); i--;) { 56 56 JSCell* cell = incomingReferenceAt(i); -
trunk/Source/JavaScriptCore/runtime/JSArrayBufferView.h
r191221 r195360 160 160 ArrayBuffer* buffer(); 161 161 PassRefPtr<ArrayBufferView> impl(); 162 bool isNeutered() { return hasArrayBuffer() && !vector(); } 162 163 void neuter(); 163 164 -
trunk/Source/JavaScriptCore/runtime/JSArrayBufferViewInlines.h
r191221 r195360 67 67 if (!hasArrayBuffer()) 68 68 return 0; 69 69 70 ASSERT(!vector() == !buffer()->data()); 71 70 72 ptrdiff_t delta = 71 73 bitwise_cast<uint8_t*>(vector()) - static_cast<uint8_t*>(buffer()->data()); -
trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h
r194310 r195360 44 44 namespace JSC { 45 45 46 static const char* typedArrayBufferHasBeenDetachedErrorMessage = "Underlying ArrayBuffer has been detached from the view"; 47 46 48 inline unsigned argumentClampedIndexFromStartOrEnd(ExecState* exec, int argument, unsigned length, unsigned undefinedValue = 0) 47 49 { … … 69 71 unsigned offset; 70 72 if (exec->argumentCount() >= 2) { 71 offset = exec->uncheckedArgument(1).toUInt32(exec);73 double offsetNumber = exec->uncheckedArgument(1).toInteger(exec); 72 74 if (exec->hadException()) 73 75 return JSValue::encode(jsUndefined()); 76 if (offsetNumber < 0) 77 return throwVMRangeError(exec, "Offset should not be negative"); 78 offset = offsetNumber; 74 79 } else 75 80 offset = 0; 81 82 if (thisObject->isNeutered()) 83 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 76 84 77 85 JSObject* sourceArray = jsDynamicCast<JSObject*>(exec->uncheckedArgument(0)); … … 80 88 81 89 unsigned length; 82 if (isTypedView(sourceArray->classInfo()->typedArrayStorageType)) 83 length = jsDynamicCast<JSArrayBufferView*>(sourceArray)->length(); 84 else 90 if (isTypedView(sourceArray->classInfo()->typedArrayStorageType)) { 91 JSArrayBufferView* sourceView = jsCast<JSArrayBufferView*>(sourceArray); 92 if (sourceView->isNeutered()) 93 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 94 95 length = jsCast<JSArrayBufferView*>(sourceArray)->length(); 96 } else 85 97 length = sourceArray->get(exec, exec->vm().propertyNames->length).toUInt32(exec); 86 98 … … 97 109 // 22.2.3.6 98 110 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 111 if (thisObject->isNeutered()) 112 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 99 113 100 114 return JSValue::encode(JSArrayIterator::create(exec, exec->callee()->globalObject()->arrayIteratorStructure(), ArrayIterateKeyValue, thisObject)); … … 106 120 // 22.2.3.5 107 121 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 122 if (thisObject->isNeutered()) 123 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 108 124 109 125 if (exec->argumentCount() < 2) … … 134 150 // 22.2.3.8 135 151 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 152 if (thisObject->isNeutered()) 153 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 136 154 137 155 JSValue valueToInsert = exec->argument(0); … … 157 175 // 22.2.3.13 158 176 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 177 if (thisObject->isNeutered()) 178 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 159 179 160 180 if (!exec->argumentCount()) … … 182 202 EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncJoin(ExecState* exec) 183 203 { 204 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 205 if (thisObject->isNeutered()) 206 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 207 184 208 // 22.2.3.14 185 209 auto joinWithSeparator = [&] (StringView separator) -> EncodedJSValue { … … 215 239 // 22.2.3.15 216 240 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 241 if (thisObject->isNeutered()) 242 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 217 243 218 244 return JSValue::encode(JSArrayIterator::create(exec, exec->callee()->globalObject()->arrayIteratorStructure(), ArrayIterateKey, thisObject)); … … 224 250 // 22.2.3.16 225 251 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 252 if (thisObject->isNeutered()) 253 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 226 254 227 255 if (!exec->argumentCount()) … … 290 318 // 22.2.3.21 291 319 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 320 if (thisObject->isNeutered()) 321 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 292 322 293 323 typename ViewClass::ElementType* array = thisObject->typedVector(); … … 302 332 // 22.2.3.25 303 333 ViewClass* thisObject = jsCast<ViewClass*>(exec->argument(0)); 334 if (thisObject->isNeutered()) 335 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 304 336 305 337 thisObject->sort(); … … 315 347 316 348 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 349 if (thisObject->isNeutered()) 350 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 317 351 318 352 if (!exec->argumentCount()) … … 350 384 351 385 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 386 if (thisObject->isNeutered()) 387 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 352 388 353 389 if (!exec->argumentCount()) … … 386 422 // 22.2.3.29 387 423 ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue()); 424 if (thisObject->isNeutered()) 425 return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage); 388 426 389 427 return JSValue::encode(JSArrayIterator::create(exec, exec->callee()->globalObject()->arrayIteratorStructure(), ArrayIterateValue, thisObject)); -
trunk/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp
r191864 r195360 69 69 if (!thisObject) 70 70 return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view")); 71 if (thisObject->isNeutered()) 72 return throwVMTypeError(exec, "Underlying ArrayBuffer has been detached from the view"); 71 73 72 74 return JSValue::encode(jsNumber(thisObject->length())); … … 76 78 { 77 79 JSValue thisValue = exec->argument(0); 78 if (!thisValue.isObject())79 return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));80 80 CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewPrivateFuncSort); 81 81 }
Note: See TracChangeset
for help on using the changeset viewer.