mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
@@ -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 {
|
||||
|
||||
@@ -1065,6 +1065,11 @@ ObjectDefineProperties(URL.prototype, {
|
||||
toJSON: kEnumerableProperty,
|
||||
});
|
||||
|
||||
ObjectDefineProperties(URL, {
|
||||
createObjectURL: kEnumerableProperty,
|
||||
revokeObjectURL: kEnumerableProperty,
|
||||
});
|
||||
|
||||
function update(url, params) {
|
||||
if (!url)
|
||||
return;
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user