From 15b4cd40bdf897fe2fd3ee7405ed4ed928237494 Mon Sep 17 00:00:00 2001 From: kuriyosh Date: Fri, 14 Jan 2022 16:32:47 +0900 Subject: [PATCH 1/7] test: improve test coverage of internal/blob --- test/parallel/test-blob.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index 53b9ddb0cb3e81..5c48dd5565d5be 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -198,6 +198,8 @@ assert.throws(() => new Blob({}), { const b = new Blob(); assert.strictEqual(inspect(b, { depth: null }), 'Blob { size: 0, type: \'\' }'); + assert.strictEqual(inspect(b, { depth: 1 }), + 'Blob { size: 0, type: \'\' }'); assert.strictEqual(inspect(b, { depth: -1 }), '[Blob]'); } @@ -228,8 +230,36 @@ assert.throws(() => new Blob({}), { code: 'ERR_INVALID_ARG_VALUE', }); }); + + assert.throws(() => new Blob([new Uint8Array(0xffffffff), [1]]), { + code: 'ERR_BUFFER_TOO_LARGE', + }); } +{ + assert.throws(() => Reflect.get(Blob.prototype, 'type', {}), { + code: 'ERR_INVALID_THIS', + }); + assert.throws(() => Reflect.get(Blob.prototype, 'size', {}), { + code: 'ERR_INVALID_THIS', + }); + assert.throws(() => Blob.prototype.slice(Blob.prototype, 0, 1), { + code: 'ERR_INVALID_THIS', + }); + assert.throws(() => Blob.prototype.stream.call(), { + code: 'ERR_INVALID_THIS', + }); +} + +(async () => { + assert.rejects(async () => Blob.prototype.arrayBuffer.call(), { + code: 'ERR_INVALID_THIS', + }); + assert.rejects(async () => Blob.prototype.text.call(), { + code: 'ERR_INVALID_THIS', + }); +})().then(common.mustCall()); + (async () => { const blob = new Blob([ new Uint8Array([0x50, 0x41, 0x53, 0x53]), From 8b1c102ecab46fcf695749ed67866714c3564c91 Mon Sep 17 00:00:00 2001 From: kuriyosh Date: Fri, 21 Jan 2022 19:21:10 +0900 Subject: [PATCH 2/7] test: over size array in some platforms --- test/parallel/test-blob.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index 5c48dd5565d5be..c05a8042eecabe 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -231,8 +231,10 @@ assert.throws(() => new Blob({}), { }); }); - assert.throws(() => new Blob([new Uint8Array(0xffffffff), [1]]), { - code: 'ERR_BUFFER_TOO_LARGE', + const overSizeArray = Array(17).fill(new Uint8Array(0xfffffff)); + + assert.throws(() => new Blob(overSizeArray), { + code: "ERR_BUFFER_TOO_LARGE", }); } From 23d0c4537dd6542e7c8c4ef88e055c0504d8ff31 Mon Sep 17 00:00:00 2001 From: kuriyosh Date: Fri, 28 Jan 2022 10:47:30 +0900 Subject: [PATCH 3/7] fix: skip oversized buffer test for memory limitation --- test/parallel/test-blob.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index c05a8042eecabe..45f756013a8917 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -231,11 +231,17 @@ assert.throws(() => new Blob({}), { }); }); - const overSizeArray = Array(17).fill(new Uint8Array(0xfffffff)); - - assert.throws(() => new Blob(overSizeArray), { - code: "ERR_BUFFER_TOO_LARGE", - }); + try { + const overSizedArray = [new Uint8Array(0xffffffff), [1]]; + assert.throws(() => new Blob(overSizedArray), { + code: 'ERR_BUFFER_TOO_LARGE', + }); + } catch (e) { + if (e.message !== 'Array buffer allocation failed') throw (e); + common.skip( + 'Insufficient memory on this platform for oversized buffer test.' + ); + } } { From 24fa55ec45156aabd93f19dccf0cf0506ad648a2 Mon Sep 17 00:00:00 2001 From: kuriyosh Date: Sat, 29 Jan 2022 12:07:45 +0900 Subject: [PATCH 4/7] fix: remove parens in throw statement --- test/parallel/test-blob.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index 45f756013a8917..bc3ac30c6be7bb 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -237,7 +237,7 @@ assert.throws(() => new Blob({}), { code: 'ERR_BUFFER_TOO_LARGE', }); } catch (e) { - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.message !== 'Array buffer allocation failed') throw e; common.skip( 'Insufficient memory on this platform for oversized buffer test.' ); From 89ccf1230c932f4d2fb026bce1e8b6677c863893 Mon Sep 17 00:00:00 2001 From: kuriyosh Date: Fri, 18 Feb 2022 15:17:40 +0900 Subject: [PATCH 5/7] test: fix mustcall error --- test/parallel/test-blob-buffer-too-large.js | 18 ++++++++++++++++++ test/parallel/test-blob.js | 12 ------------ 2 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 test/parallel/test-blob-buffer-too-large.js diff --git a/test/parallel/test-blob-buffer-too-large.js b/test/parallel/test-blob-buffer-too-large.js new file mode 100644 index 00000000000000..d0ce2b863ea4d2 --- /dev/null +++ b/test/parallel/test-blob-buffer-too-large.js @@ -0,0 +1,18 @@ +// Flags: --no-warnings +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const { Blob } = require('buffer'); + +try { + new Blob([new Uint8Array(0xffffffff), [1]]); +} catch (e) { + if (e.message === 'Array buffer allocation failed') { + common.skip( + 'Insufficient memory on this platform for oversized buffer test.' + ); + } else { + assert.strictEqual(e.code, 'ERR_BUFFER_TOO_LARGE'); + } +} diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index bc3ac30c6be7bb..fe66ff08f945e1 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -230,18 +230,6 @@ assert.throws(() => new Blob({}), { code: 'ERR_INVALID_ARG_VALUE', }); }); - - try { - const overSizedArray = [new Uint8Array(0xffffffff), [1]]; - assert.throws(() => new Blob(overSizedArray), { - code: 'ERR_BUFFER_TOO_LARGE', - }); - } catch (e) { - if (e.message !== 'Array buffer allocation failed') throw e; - common.skip( - 'Insufficient memory on this platform for oversized buffer test.' - ); - } } { From 12b8651fe13cb2a11314ff8644dd91161849e5dc Mon Sep 17 00:00:00 2001 From: Yoshiki Kurihara Date: Fri, 4 Mar 2022 15:57:49 +0900 Subject: [PATCH 6/7] test: skip invalid array length --- test/parallel/test-blob-buffer-too-large.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-blob-buffer-too-large.js b/test/parallel/test-blob-buffer-too-large.js index d0ce2b863ea4d2..70cdf1c4fd6c5c 100644 --- a/test/parallel/test-blob-buffer-too-large.js +++ b/test/parallel/test-blob-buffer-too-large.js @@ -8,7 +8,8 @@ const { Blob } = require('buffer'); try { new Blob([new Uint8Array(0xffffffff), [1]]); } catch (e) { - if (e.message === 'Array buffer allocation failed') { + if (e.message === 'Array buffer allocation failed' || + e.message === 'Invalid typed array length: 4294967295') { common.skip( 'Insufficient memory on this platform for oversized buffer test.' ); From 5f423b56cee21983fdb2ba122eaaca18b5628f56 Mon Sep 17 00:00:00 2001 From: Yoshiki Kurihara Date: Fri, 8 Apr 2022 12:05:43 +0900 Subject: [PATCH 7/7] test: skip this test in freeBSD env --- test/parallel/test-blob-buffer-too-large.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-blob-buffer-too-large.js b/test/parallel/test-blob-buffer-too-large.js index 70cdf1c4fd6c5c..2fd8b8754bd593 100644 --- a/test/parallel/test-blob-buffer-too-large.js +++ b/test/parallel/test-blob-buffer-too-large.js @@ -5,11 +5,16 @@ const common = require('../common'); const assert = require('assert'); const { Blob } = require('buffer'); +if (common.isFreeBSD) + common.skip('Oversized buffer make the FreeBSD CI runner crash'); + try { new Blob([new Uint8Array(0xffffffff), [1]]); } catch (e) { - if (e.message === 'Array buffer allocation failed' || - e.message === 'Invalid typed array length: 4294967295') { + if ( + e.message === 'Array buffer allocation failed' || + e.message === 'Invalid typed array length: 4294967295' + ) { common.skip( 'Insufficient memory on this platform for oversized buffer test.' );