haikuwebkit/LayoutTests/streams/clone-array-buffer.html

23 lines
778 B
HTML
Raw Permalink Normal View History

[Readable Streams API] Implement cloneArrayBuffer in WebCore https://bugs.webkit.org/show_bug.cgi?id=170008 Patch by Romain Bellessort <romain.bellessort@crf.canon.fr> on 2017-04-13 Reviewed by Youenn Fablet. Source/WebCore: Implemented cloneArrayBuffer based on existing structuredCloneArrayBuffer implementation. The code has been factorized so that both cloneArrayBuffer and structuredCloneArrayBuffer rely on the same code (which is basically the previous implementation of structuredCloneArrayBuffer + the ability to clone only a part of considered buffer). Test: streams/clone-array-buffer.html * Modules/streams/ReadableByteStreamInternals.js: Deleted cloneArrayBuffer JS implementation. * bindings/js/JSDOMGlobalObject.cpp: (WebCore::JSDOMGlobalObject::addBuiltinGlobals): Add cloneArrayBuffer private declaration. * bindings/js/StructuredClone.cpp: (WebCore::cloneArrayBufferImpl): Added (mostly based on previous structuredCloneArrayBuffer). (WebCore::cloneArrayBuffer): Added. (WebCore::structuredCloneArrayBuffer): Updated. * bindings/js/StructuredClone.h: Added cloneArrayBuffer declaration. * bindings/js/WebCoreBuiltinNames.h: Added cloneArrayBuffer declaration. * testing/Internals.cpp: Added support for testing cloneArrayBuffer. * testing/Internals.h: Added support for testing cloneArrayBuffer. * testing/Internals.idl: Added support for testing cloneArrayBuffer. LayoutTests: Added test to check cloneArrayBuffer behaviour. * streams/clone-array-buffer-expected.txt: Added. * streams/clone-array-buffer.html: Added. Canonical link: https://commits.webkit.org/187740@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215322 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-13 16:40:25 +00:00
<!DOCTYPE html>
<script src='../resources/testharness.js'></script>
<script src='../resources/testharnessreport.js'></script>
<script>
'use strict';
const CloneArrayBuffer = internals.cloneArrayBuffer.bind(internals);
test(function() {
const typedArray = new Uint8Array([3, 5, 7]);
const clonedBuffer = CloneArrayBuffer(typedArray.buffer, 1, 1);
const otherArray = new Uint8Array(clonedBuffer);
assert_equals(otherArray.byteLength, 1);
assert_equals(otherArray.byteOffset, 0);
assert_equals(otherArray.buffer.byteLength, 1);
assert_equals(otherArray[0], 5);
// Check that when typedArray is modified, otherArray is not modified.
typedArray[1] = 0;
assert_equals(otherArray[0], 5);
}, "Test cloneArrayBuffer implementation");
</script>