Skip to content

Commit 17ef1bb

Browse files
KhafraDevRafaelGSS
authored andcommitted
lib: make properties on Blob and URL enumerable
PR-URL: #44918 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent ea0cfc9 commit 17ef1bb

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

lib/internal/blob.js

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
ArrayFrom,
55
MathMax,
66
MathMin,
7+
ObjectDefineProperties,
78
ObjectDefineProperty,
89
PromiseResolve,
910
PromiseReject,
@@ -45,6 +46,7 @@ const {
4546
createDeferredPromise,
4647
customInspectSymbol: kInspect,
4748
kEmptyObject,
49+
kEnumerableProperty,
4850
} = require('internal/util');
4951
const { inspect } = require('internal/util/inspect');
5052

@@ -364,6 +366,15 @@ ObjectDefineProperty(Blob.prototype, SymbolToStringTag, {
364366
value: 'Blob',
365367
});
366368

369+
ObjectDefineProperties(Blob.prototype, {
370+
size: kEnumerableProperty,
371+
type: kEnumerableProperty,
372+
slice: kEnumerableProperty,
373+
stream: kEnumerableProperty,
374+
text: kEnumerableProperty,
375+
arrayBuffer: kEnumerableProperty,
376+
});
377+
367378
function resolveObjectURL(url) {
368379
url = `${url}`;
369380
try {

lib/internal/url.js

+5
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,11 @@ ObjectDefineProperties(URL.prototype, {
10651065
toJSON: kEnumerableProperty,
10661066
});
10671067

1068+
ObjectDefineProperties(URL, {
1069+
createObjectURL: kEnumerableProperty,
1070+
revokeObjectURL: kEnumerableProperty,
1071+
});
1072+
10681073
function update(url, params) {
10691074
if (!url)
10701075
return;

test/parallel/test-blob.js

+17
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ assert.throws(() => new Blob({}), {
187187
});
188188
}
189189

190+
{
191+
const descriptors = Object.getOwnPropertyDescriptors(Blob.prototype);
192+
const enumerable = [
193+
'size',
194+
'type',
195+
'slice',
196+
'stream',
197+
'text',
198+
'arrayBuffer',
199+
];
200+
201+
for (const prop of enumerable) {
202+
assert.notStrictEqual(descriptors[prop], undefined);
203+
assert.strictEqual(descriptors[prop].enumerable, true);
204+
}
205+
}
206+
190207
{
191208
const b = new Blob(['test', 42]);
192209
b.text().then(common.mustCall((text) => {

test/parallel/test-whatwg-url-properties.js

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ const { URL, URLSearchParams } = require('url');
2828
testAccessor(URL.prototype, name, readonly);
2929
});
3030

31+
[
32+
{ name: 'createObjectURL' },
33+
{ name: 'revokeObjectURL' },
34+
].forEach(({ name }) => {
35+
testStaticAccessor(URL, name);
36+
});
37+
3138
[
3239
{ name: 'append' },
3340
{ name: 'delete' },
@@ -98,3 +105,12 @@ function testAccessor(target, name, readonly = false) {
98105
);
99106
}
100107
}
108+
109+
function testStaticAccessor(target, name) {
110+
const desc = Object.getOwnPropertyDescriptor(target, name);
111+
assert.notStrictEqual(desc, undefined);
112+
113+
assert.strictEqual(desc.configurable, true);
114+
assert.strictEqual(desc.enumerable, true);
115+
assert.strictEqual(desc.writable, true);
116+
}

0 commit comments

Comments
 (0)