lib: make properties on Blob and URL enumerable

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Khafra
2022-10-14 19:49:39 -04:00
committed by GitHub
parent 4264b19861
commit 6fb466bc38
4 changed files with 49 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ const {
ArrayFrom,
MathMax,
MathMin,
ObjectDefineProperties,
ObjectDefineProperty,
PromiseResolve,
PromiseReject,
@@ -45,6 +46,7 @@ const {
createDeferredPromise,
customInspectSymbol: kInspect,
kEmptyObject,
kEnumerableProperty,
} = require('internal/util');
const { inspect } = require('internal/util/inspect');
@@ -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 {

View File

@@ -1065,6 +1065,11 @@ ObjectDefineProperties(URL.prototype, {
toJSON: kEnumerableProperty,
});
ObjectDefineProperties(URL, {
createObjectURL: kEnumerableProperty,
revokeObjectURL: kEnumerableProperty,
});
function update(url, params) {
if (!url)
return;

View File

@@ -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) => {

View File

@@ -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' },
@@ -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);
}