Changeset 217052 in webkit
- Timestamp:
- May 18, 2017 11:22:19 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r217050 r217052 1 2017-05-18 Keith Miller <keith_miller@apple.com> 2 3 WebAssembly API: test with neutered inputs 4 https://bugs.webkit.org/show_bug.cgi?id=163899 5 6 Reviewed by JF Bastien. 7 8 * wasm/js-api/neutered-inputs.js: Added. 9 (const.testFunction): 10 (const.testConstructor): 11 * wasm/js-api/test_basic_api.js: 12 (const.c.in.constructorProperties.switch): 13 1 14 2017-05-18 Filip Pizlo <fpizlo@apple.com> 2 15 -
trunk/JSTests/wasm/js-api/test_basic_api.js
r214260 r217052 62 62 assert.throws(() => new WebAssembly[c](buffer), Error, `WebAssembly.Module doesn't parse at byte 0 / 0: expected a module of at least 8 bytes (evaluating 'new WebAssembly[c](buffer)')`); 63 63 assert.instanceof(new WebAssembly[c](emptyModuleArray), WebAssembly.Module); 64 // FIXME test neutered TypedArray and TypedArrayView. https://bugs.webkit.org/show_bug.cgi?id=16389965 64 break; 66 65 case "Instance": -
trunk/LayoutTests/ChangeLog
r217047 r217052 1 2017-05-18 Keith Miller <keith_miller@apple.com> 2 3 WebAssembly API: test with neutered inputs 4 https://bugs.webkit.org/show_bug.cgi?id=163899 5 6 Reviewed by JF Bastien. 7 8 This patch dups Saam's de-modularized builder. 9 10 * workers/sab/postMessage-transfer-type-error-expected.txt: 11 * workers/wasm-mem-post-message-expected.txt: Added. 12 * workers/wasm-mem-post-message.html: Added. 13 * workers/wasm-mem-post-message/test.js: Added. 14 (worker.onmessage): 15 * workers/wasm-mem-post-message/worker.js: Added. 16 (onmessage): 17 * workers/wasm-resources/builder.js: Added. 18 (const._fail): 19 (const.isNotA.assert.isNotA): 20 (const): 21 (switch.typeof): 22 (Builder): 23 (Builder.prototype.setChecked): 24 (Builder.prototype.setPreamble): 25 (Builder.prototype._functionIndexSpaceKeyHash): 26 (Builder.prototype._registerFunctionToIndexSpace): 27 (Builder.prototype._getFunctionFromIndexSpace): 28 (Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): 29 (Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.const.codeBuilder.End.switch.case.string_appeared_here.e): 30 (Builder.prototype._registerSectionBuilders.this.Unknown): 31 1 32 2017-05-18 Chris Dumez <cdumez@apple.com> 2 33 -
trunk/LayoutTests/workers/sab/postMessage-transfer-type-error-expected.txt
r212301 r217052 4 4 5 5 6 PASS postMessageTransferSharedArrayBuffer() threw exception TypeError: Type error.6 PASS postMessageTransferSharedArrayBuffer() threw exception TypeError: Cannot transfer a SharedArrayBuffer. 7 7 PASS successfullyParsed is true 8 8 -
trunk/Source/JavaScriptCore/API/JSTypedArray.cpp
r211247 r217052 318 318 } 319 319 320 void* JSObjectGetArrayBufferBytesPtr(JSContextRef ctx, JSObjectRef objectRef, JSValueRef* )320 void* JSObjectGetArrayBufferBytesPtr(JSContextRef ctx, JSObjectRef objectRef, JSValueRef* exception) 321 321 { 322 322 ExecState* exec = toJS(ctx); … … 327 327 if (JSArrayBuffer* jsBuffer = jsDynamicCast<JSArrayBuffer*>(vm, object)) { 328 328 ArrayBuffer* buffer = jsBuffer->impl(); 329 if (buffer->isWasmMemory()) { 330 setException(exec, exception, createTypeError(exec, ASCIILiteral("Cannot get the backing buffer for a WebAssembly.Memory"))); 331 return nullptr; 332 } 333 329 334 buffer->pinAndLock(); 330 335 return buffer->data(); -
trunk/Source/JavaScriptCore/ChangeLog
r217051 r217052 1 2017-05-18 Keith Miller <keith_miller@apple.com> 2 3 WebAssembly API: test with neutered inputs 4 https://bugs.webkit.org/show_bug.cgi?id=163899 5 6 Reviewed by JF Bastien. 7 8 Add tests to check that we properly throw a type error when 9 we get a transferred ArrayBuffer. Also, we should make sure 10 we cannot post message a wasm memory's ArrayBuffer. 11 12 * API/JSTypedArray.cpp: 13 (JSObjectGetArrayBufferBytesPtr): 14 * runtime/ArrayBuffer.cpp: 15 (JSC::ArrayBuffer::makeShared): 16 (JSC::ArrayBuffer::makeWasmMemory): 17 (JSC::ArrayBuffer::transferTo): 18 (JSC::ArrayBuffer::neuter): 19 (JSC::ArrayBuffer::notifyIncommingReferencesOfTransfer): 20 (JSC::errorMesasgeForTransfer): 21 * runtime/ArrayBuffer.h: 22 (JSC::ArrayBuffer::isLocked): 23 (JSC::ArrayBuffer::isWasmMemory): 24 * wasm/js/JSWebAssemblyMemory.cpp: 25 (JSC::JSWebAssemblyMemory::buffer): 26 (JSC::JSWebAssemblyMemory::grow): 27 1 28 2017-05-18 Joseph Pecoraro <pecoraro@apple.com> 2 29 -
trunk/Source/JavaScriptCore/runtime/ArrayBuffer.cpp
r212035 r217052 249 249 : m_contents(WTFMove(contents)) 250 250 , m_pinCount(0) 251 , m_isWasmMemory(false) 251 252 , m_locked(false) 252 253 { … … 274 275 { 275 276 m_contents.makeShared(); 277 m_locked = true; 278 } 279 280 void ArrayBuffer::makeWasmMemory() 281 { 282 m_locked = true; 283 m_isWasmMemory = true; 276 284 } 277 285 … … 320 328 321 329 m_contents.transferTo(result); 330 notifyIncommingReferencesOfTransfer(vm); 331 return true; 332 } 333 334 // We allow neutering wasm memory ArrayBuffers even though they are locked. 335 void ArrayBuffer::neuter(VM& vm) 336 { 337 ASSERT(isWasmMemory()); 338 ArrayBufferContents unused; 339 m_contents.transferTo(unused); 340 notifyIncommingReferencesOfTransfer(vm); 341 } 342 343 void ArrayBuffer::notifyIncommingReferencesOfTransfer(VM& vm) 344 { 322 345 for (size_t i = numberOfIncomingReferences(); i--;) { 323 346 JSCell* cell = incomingReferenceAt(i); … … 327 350 watchpoint->fireAll(); 328 351 } 329 return true; 352 } 353 354 ASCIILiteral errorMesasgeForTransfer(ArrayBuffer* buffer) 355 { 356 ASSERT(buffer->isLocked()); 357 if (buffer->isShared()) 358 return ASCIILiteral("Cannot transfer a SharedArrayBuffer"); 359 if (buffer->isWasmMemory()) 360 return ASCIILiteral("Cannot transfer a WebAssembly.Memory"); 361 return ASCIILiteral("Cannot transfer an ArrayBuffer whose backing store has been accessed by the JavaScriptCore C API"); 330 362 } 331 363 -
trunk/Source/JavaScriptCore/runtime/ArrayBuffer.h
r215686 r217052 32 32 #include <wtf/StdLibExtras.h> 33 33 #include <wtf/ThreadSafeRefCounted.h> 34 #include <wtf/text/WTFString.h> 34 35 35 36 namespace JSC { … … 123 124 inline bool isShared() const; 124 125 inline ArrayBufferSharingMode sharingMode() const { return isShared() ? ArrayBufferSharingMode::Shared : ArrayBufferSharingMode::Default; } 125 126 126 127 inline size_t gcSizeEstimateInBytes() const; 127 128 … … 132 133 inline void unpin(); 133 134 inline void pinAndLock(); 135 inline bool isLocked(); 136 137 void makeWasmMemory(); 138 inline bool isWasmMemory(); 134 139 135 140 JS_EXPORT_PRIVATE bool transferTo(VM&, ArrayBufferContents&); 136 141 JS_EXPORT_PRIVATE bool shareWith(ArrayBufferContents&); 142 143 void neuter(VM&); 137 144 bool isNeutered() { return !m_contents.m_data; } 138 145 139 146 static ptrdiff_t offsetOfData() { return OBJECT_OFFSETOF(ArrayBuffer, m_contents) + OBJECT_OFFSETOF(ArrayBufferContents, m_data); } 140 147 … … 150 157 static inline int clampValue(int x, int left, int right); 151 158 159 void notifyIncommingReferencesOfTransfer(VM&); 160 152 161 ArrayBufferContents m_contents; 153 unsigned m_pinCount : 31; 154 bool m_locked : 1; // m_locked == true means that some API user fetched m_contents directly from a TypedArray object. 162 unsigned m_pinCount : 30; 163 bool m_isWasmMemory : 1; 164 // m_locked == true means that some API user fetched m_contents directly from a TypedArray object, 165 // the buffer is backed by a WebAssembly.Memory, or is a SharedArrayBuffer. 166 bool m_locked : 1; 155 167 156 168 public: … … 217 229 } 218 230 231 bool ArrayBuffer::isLocked() 232 { 233 return m_locked; 234 } 235 236 bool ArrayBuffer::isWasmMemory() 237 { 238 return m_isWasmMemory; 239 } 240 241 JS_EXPORT_PRIVATE ASCIILiteral errorMesasgeForTransfer(ArrayBuffer*); 242 219 243 } // namespace JSC 220 244 -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp
r217049 r217052 69 69 auto destructor = [protectedMemory = WTFMove(protectedMemory)] (void*) { }; 70 70 m_buffer = ArrayBuffer::createFromBytes(memory().memory(), memory().size(), WTFMove(destructor)); 71 m_buffer->makeWasmMemory(); 71 72 m_bufferWrapper.set(vm, this, JSArrayBuffer::create(vm, globalObject->m_arrayBufferStructure.get(), m_buffer.get())); 72 73 RELEASE_ASSERT(m_bufferWrapper); … … 111 112 // Neuter the old array. 112 113 if (m_buffer) { 113 ArrayBufferContents dummyContents; 114 m_buffer->transferTo(vm, dummyContents); 114 m_buffer->neuter(vm); 115 115 m_buffer = nullptr; 116 116 m_bufferWrapper.clear(); -
trunk/Source/WebCore/ChangeLog
r217049 r217052 1 2017-05-18 Keith Miller <keith_miller@apple.com> 2 3 WebAssembly API: test with neutered inputs 4 https://bugs.webkit.org/show_bug.cgi?id=163899 5 6 Reviewed by JF Bastien. 7 8 Make it not possible to transfer an ArrayBuffer that is backed by a 9 wasm memory. 10 11 Test: workers/wasm-mem-post-message.html 12 13 * bindings/js/SerializedScriptValue.cpp: 14 (WebCore::SerializedScriptValue::create): 15 1 16 2017-05-18 Commit Queue <commit-queue@webkit.org> 2 17 -
trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp
r216428 r217052 2997 2997 if (arrayBuffer->isNeutered()) 2998 2998 return Exception { DATA_CLONE_ERR }; 2999 if (arrayBuffer->isShared()) 3000 return Exception { TypeError }; 2999 if (arrayBuffer->isLocked()) { 3000 auto scope = DECLARE_THROW_SCOPE(vm); 3001 throwVMTypeError(&state, scope, errorMesasgeForTransfer(arrayBuffer)); 3002 return Exception { ExistingExceptionError }; 3003 } 3001 3004 arrayBuffers.append(WTFMove(arrayBuffer)); 3002 3005 continue;
Note: See TracChangeset
for help on using the changeset viewer.