Skip to content

Commit

Permalink
lib: make properties on Blob and URL enumerable
Browse files Browse the repository at this point in the history
PR-URL: #44918
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
KhafraDev authored and RafaelGSS committed Nov 10, 2022
1 parent ea0cfc9 commit 17ef1bb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
ArrayFrom,
MathMax,
MathMin,
ObjectDefineProperties,
ObjectDefineProperty,
PromiseResolve,
PromiseReject,
Expand Down Expand Up @@ -45,6 +46,7 @@ const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEmptyObject,
kEnumerableProperty,
} = require('internal/util');
const { inspect } = require('internal/util/inspect');

Expand Down Expand Up @@ -364,6 +366,15 @@ ObjectDefineProperty(Blob.prototype, SymbolToStringTag, {
value: 'Blob',
});

ObjectDefineProperties(Blob.prototype, {
size: kEnumerableProperty,
type: kEnumerableProperty,
slice: kEnumerableProperty,
stream: kEnumerableProperty,
text: kEnumerableProperty,
arrayBuffer: kEnumerableProperty,
});

function resolveObjectURL(url) {
url = `${url}`;
try {
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,11 @@ ObjectDefineProperties(URL.prototype, {
toJSON: kEnumerableProperty,
});

ObjectDefineProperties(URL, {
createObjectURL: kEnumerableProperty,
revokeObjectURL: kEnumerableProperty,
});

function update(url, params) {
if (!url)
return;
Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@ assert.throws(() => new Blob({}), {
});
}

{
const descriptors = Object.getOwnPropertyDescriptors(Blob.prototype);
const enumerable = [
'size',
'type',
'slice',
'stream',
'text',
'arrayBuffer',
];

for (const prop of enumerable) {
assert.notStrictEqual(descriptors[prop], undefined);
assert.strictEqual(descriptors[prop].enumerable, true);
}
}

{
const b = new Blob(['test', 42]);
b.text().then(common.mustCall((text) => {
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-whatwg-url-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const { URL, URLSearchParams } = require('url');
testAccessor(URL.prototype, name, readonly);
});

[
{ name: 'createObjectURL' },
{ name: 'revokeObjectURL' },
].forEach(({ name }) => {
testStaticAccessor(URL, name);
});

[
{ name: 'append' },
{ name: 'delete' },
Expand Down Expand Up @@ -98,3 +105,12 @@ function testAccessor(target, name, readonly = false) {
);
}
}

function testStaticAccessor(target, name) {
const desc = Object.getOwnPropertyDescriptor(target, name);
assert.notStrictEqual(desc, undefined);

assert.strictEqual(desc.configurable, true);
assert.strictEqual(desc.enumerable, true);
assert.strictEqual(desc.writable, true);
}

0 comments on commit 17ef1bb

Please sign in to comment.