| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 05d73ac commit c8d039a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,7 +50,6 @@ const { | |||
| 50 | 50 | ||
| 51 | 51 | const { | |
| 52 | 52 | validateObject, | |
| 53 | - validateString, | ||
| 54 | 53 | isUint32, | |
| 55 | 54 | } = require('internal/validators'); | |
| 56 | 55 | ||
@@ -76,22 +75,10 @@ function getSource(source, encoding) { | |||
| 76 | 75 | if (isBlob(source)) | |
| 77 | 76 | return [source.size, source[kHandle]]; | |
| 78 | 77 | ||
| 79 | - if (typeof source === 'string') { | ||
| 80 | - source = lazyBuffer().from(source, encoding); | ||
| 81 | - } else if (isAnyArrayBuffer(source)) { | ||
| 78 | + if (isAnyArrayBuffer(source)) { | ||
| 82 | 79 | source = new Uint8Array(source); | |
| 83 | 80 | } else if (!isArrayBufferView(source)) { | |
| 84 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 85 | - 'source', | ||
| 86 | - [ | ||
| 87 | - 'string', | ||
| 88 | - 'ArrayBuffer', | ||
| 89 | - 'SharedArrayBuffer', | ||
| 90 | - 'Buffer', | ||
| 91 | - 'TypedArray', | ||
| 92 | - 'DataView' | ||
| 93 | - ], | ||
| 94 | - source); | ||
| 81 | + source = lazyBuffer().from(`${source}`, encoding); | ||
| 95 | 82 | } | |
| 96 | 83 | ||
| 97 | 84 | // We copy into a new Uint8Array because the underlying | |
@@ -112,19 +99,16 @@ class InternalBlob extends JSTransferable { | |||
| 112 | 99 | } | |
| 113 | 100 | ||
| 114 | 101 | class Blob extends JSTransferable { | |
| 115 | - constructor(sources = [], options) { | ||
| 102 | + constructor(sources = [], options = {}) { | ||
| 116 | 103 | emitExperimentalWarning('buffer.Blob'); | |
| 117 | 104 | if (sources === null || | |
| 118 | 105 | typeof sources[SymbolIterator] !== 'function' || | |
| 119 | 106 | typeof sources === 'string') { | |
| 120 | 107 | throw new ERR_INVALID_ARG_TYPE('sources', 'Iterable', sources); | |
| 121 | 108 | } | |
| 122 | - if (options !== undefined) | ||
| 123 | - validateObject(options, 'options'); | ||
| 124 | - const { | ||
| 125 | - encoding = 'utf8', | ||
| 126 | - type = '', | ||
| 127 | - } = { ...options }; | ||
| 109 | + validateObject(options, 'options'); | ||
| 110 | + const { encoding = 'utf8' } = options; | ||
| 111 | + let { type = '' } = options; | ||
| 128 | 112 | ||
| 129 | 113 | let length = 0; | |
| 130 | 114 | const sources_ = ArrayFrom(sources, (source) => { | |
@@ -133,16 +117,14 @@ class Blob extends JSTransferable { | |||
| 133 | 117 | return src; | |
| 134 | 118 | }); | |
| 135 | 119 | ||
| 136 | - // This is a MIME media type but we're not actively checking the syntax. | ||
| 137 | - // But, to be fair, neither does Chrome. | ||
| 138 | - validateString(type, 'options.type'); | ||
| 139 | - | ||
| 140 | 120 | if (!isUint32(length)) | |
| 141 | 121 | throw new ERR_BUFFER_TOO_LARGE(0xFFFFFFFF); | |
| 142 | 122 | ||
| 143 | 123 | super(); | |
| 144 | 124 | this[kHandle] = createBlob(sources_, length); | |
| 145 | 125 | this[kLength] = length; | |
| 126 | + | ||
| 127 | + type = `${type}`; | ||
| 146 | 128 | this[kType] = RegExpPrototypeTest(disallowedTypeCharacters, type) ? | |
| 147 | 129 | '' : StringPrototypeToLowerCase(type); | |
| 148 | 130 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,10 +23,6 @@ assert.throws(() => new Blob({}), { | |||
| 23 | 23 | code: 'ERR_INVALID_ARG_TYPE' | |
| 24 | 24 | }); | |
| 25 | 25 | ||
| 26 | - assert.throws(() => new Blob(['test', 1]), { | ||
| 27 | - code: 'ERR_INVALID_ARG_TYPE' | ||
| 28 | - }); | ||
| 29 | - | ||
| 30 | 26 | { | |
| 31 | 27 | const b = new Blob([]); | |
| 32 | 28 | assert(b); | |
@@ -44,15 +40,9 @@ assert.throws(() => new Blob(['test', 1]), { | |||
| 44 | 40 | } | |
| 45 | 41 | ||
| 46 | 42 | { | |
| 47 | - assert.throws(() => new Blob([], { type: 1 }), { | ||
| 48 | - code: 'ERR_INVALID_ARG_TYPE' | ||
| 49 | - }); | ||
| 50 | - assert.throws(() => new Blob([], { type: false }), { | ||
| 51 | - code: 'ERR_INVALID_ARG_TYPE' | ||
| 52 | - }); | ||
| 53 | - assert.throws(() => new Blob([], { type: {} }), { | ||
| 54 | - code: 'ERR_INVALID_ARG_TYPE' | ||
| 55 | - }); | ||
| 43 | + assert.strictEqual(new Blob([], { type: 1 }).type, '1'); | ||
| 44 | + assert.strictEqual(new Blob([], { type: false }).type, 'false'); | ||
| 45 | + assert.strictEqual(new Blob([], { type: {} }).type, '[object object]'); | ||
| 56 | 46 | } | |
| 57 | 47 | ||
| 58 | 48 | { | |
@@ -194,3 +184,10 @@ assert.throws(() => new Blob(['test', 1]), { | |||
| 194 | 184 | writable: false | |
| 195 | 185 | }); | |
| 196 | 186 | } | |
| 187 | + | ||
| 188 | + { | ||
| 189 | + const b = new Blob(['test', 42]); | ||
| 190 | + b.text().then(common.mustCall((text) => { | ||
| 191 | + assert.strictEqual(text, 'test42'); | ||
| 192 | + })); | ||
| 193 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments