Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
lib: make properties on Blob and URL enumerable
  • Loading branch information
KhafraDev committed Oct 8, 2022
commit 892e453166e27f7f9916fe57f117eacdc78f23b8
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 @@ -362,6 +364,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.notDeepStrictEqual(desc, undefined);

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