Skip to content

Commit

Permalink
The CompressionStream / DecompressionStream constructors incorrectly …
Browse files Browse the repository at this point in the history
…throw when the parameter is not a String

https://bugs.webkit.org/show_bug.cgi?id=244958

Reviewed by Youenn Fablet.

* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.serviceworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.worker-expected.txt:
* Source/WebCore/Modules/compression/DecompressionStream.js:
(initializeDecompressionStream):

Canonical link: https://commits.webkit.org/254411@main
  • Loading branch information
cdumez committed Sep 12, 2022
1 parent 46bb540 commit 03f571c
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 21 deletions.
@@ -0,0 +1,5 @@

PASS "a" should cause the constructor to throw
PASS no input should cause the constructor to throw
PASS non-string input should cause the constructor to throw

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,15 @@
// META: global=window,worker

'use strict';

test(t => {
assert_throws_js(TypeError, () => new CompressionStream('a'), 'constructor should throw');
}, '"a" should cause the constructor to throw');

test(t => {
assert_throws_js(TypeError, () => new CompressionStream(), 'constructor should throw');
}, 'no input should cause the constructor to throw');

test(t => {
assert_throws_js(Error, () => new CompressionStream({ toString() { throw Error(); } }), 'constructor should throw');
}, 'non-string input should cause the constructor to throw');
@@ -0,0 +1,5 @@

PASS "a" should cause the constructor to throw
PASS no input should cause the constructor to throw
PASS non-string input should cause the constructor to throw

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,5 @@

PASS "a" should cause the constructor to throw
PASS no input should cause the constructor to throw
PASS non-string input should cause the constructor to throw

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,5 @@

PASS "a" should cause the constructor to throw
PASS no input should cause the constructor to throw
PASS non-string input should cause the constructor to throw

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -1,7 +1,5 @@

PASS "a" should cause the constructor to throw
PASS no input should cause the constructor to throw
FAIL non-string input should cause the constructor to throw assert_throws_js: constructor should throw function "() => new DecompressionStream({ toString() { throw Error(); } })" threw object "TypeError: CompressionStream input must be a string." ("TypeError") expected instance of function "function Error() {
[native code]
}" ("Error")
PASS non-string input should cause the constructor to throw

@@ -1,7 +1,5 @@

PASS "a" should cause the constructor to throw
PASS no input should cause the constructor to throw
FAIL non-string input should cause the constructor to throw assert_throws_js: constructor should throw function "() => new DecompressionStream({ toString() { throw Error(); } })" threw object "TypeError: CompressionStream input must be a string." ("TypeError") expected instance of function "function Error() {
[native code]
}" ("Error")
PASS non-string input should cause the constructor to throw

@@ -1,7 +1,5 @@

PASS "a" should cause the constructor to throw
PASS no input should cause the constructor to throw
FAIL non-string input should cause the constructor to throw assert_throws_js: constructor should throw function "() => new DecompressionStream({ toString() { throw Error(); } })" threw object "TypeError: CompressionStream input must be a string." ("TypeError") expected instance of function "function Error() {
[native code]
}" ("Error")
PASS non-string input should cause the constructor to throw

@@ -1,7 +1,5 @@

PASS "a" should cause the constructor to throw
PASS no input should cause the constructor to throw
FAIL non-string input should cause the constructor to throw assert_throws_js: constructor should throw function "() => new DecompressionStream({ toString() { throw Error(); } })" threw object "TypeError: CompressionStream input must be a string." ("TypeError") expected instance of function "function Error() {
[native code]
}" ("Error")
PASS non-string input should cause the constructor to throw

1 change: 1 addition & 0 deletions LayoutTests/platform/glib/TestExpectations
Expand Up @@ -1816,6 +1816,7 @@ imported/w3c/web-platform-tests/content-security-policy/wasm-unsafe-eval/script-
imported/w3c/web-platform-tests/content-security-policy/wasm-unsafe-eval/script-src-unsafe-eval-allows-wasm.any.serviceworker.html [ Skip ]
imported/w3c/web-platform-tests/content-security-policy/wasm-unsafe-eval/script-src-wasm-unsafe-eval-allows-wasm.any.serviceworker.html [ Skip ]
imported/w3c/web-platform-tests/compression/compression-bad-chunks.tentative.any.serviceworker.html [ Skip ]
imported/w3c/web-platform-tests/compression/compression-constructor-error.tentative.any.serviceworker.html [ Skip ]
imported/w3c/web-platform-tests/compression/compression-including-empty-chunk.tentative.any.serviceworker.html [ Skip ]
imported/w3c/web-platform-tests/compression/compression-multiple-chunks.tentative.any.serviceworker.html [ Skip ]
imported/w3c/web-platform-tests/compression/compression-output-length.tentative.any.serviceworker.html [ Skip ]
Expand Down
7 changes: 2 additions & 5 deletions Source/WebCore/Modules/compression/CompressionStream.js
Expand Up @@ -32,12 +32,9 @@ function initializeCompressionStream(format)
if (arguments.length < 1)
@throwTypeError(errorMessage);

if (typeof arguments[0] !== "string")
@throwTypeError("CompressionStream input must be a string.");

const algorithms = ['gzip', 'deflate', 'deflate-raw'];
const text = arguments[0].toLowerCase();
const findAlgorithm = (element) => element === text;
const lowercaseFormat = @toString(arguments[0]).toLowerCase();
const findAlgorithm = (element) => element === lowercaseFormat;

// Pass the index to our new CompressionStreamEncoder, so we do not need to reparse the string.
// We need to ensure that the Formats.h and this file stay in sync.
Expand Down
6 changes: 2 additions & 4 deletions Source/WebCore/Modules/compression/DecompressionStream.js
Expand Up @@ -32,11 +32,9 @@ function initializeDecompressionStream(format)
if (arguments.length < 1)
@throwTypeError(errorMessage);

if (typeof arguments[0] !== "string")
@throwTypeError("CompressionStream input must be a string.");

const algorithms = ['gzip', 'deflate', 'deflate-raw'];
const findAlgorithm = (element) => element === arguments[0].toLowerCase();
const lowercaseFormat = @toString(arguments[0]).toLowerCase();
const findAlgorithm = (element) => element === lowercaseFormat;

// Pass the index to our new DecompressionStreamDecoder, so we do not need to reparse the string.
// We need to ensure that the Formats.h and this file stay in sync.
Expand Down

0 comments on commit 03f571c

Please sign in to comment.