mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
util: add MIME utilities (#21128)
Co-authored-by: Rich Trott <rtrott@gmail.com> Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs/node/pull/21128 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
1f7e8d609a
commit
87cdf7d412
16 changed files with 5123 additions and 17 deletions
|
@ -266,12 +266,36 @@ const {
|
|||
FinalizationRegistry,
|
||||
FunctionPrototypeCall,
|
||||
Map,
|
||||
ObjectDefineProperties,
|
||||
ObjectDefineProperty,
|
||||
ObjectFreeze,
|
||||
ObjectSetPrototypeOf,
|
||||
Promise,
|
||||
PromisePrototypeThen,
|
||||
ReflectApply,
|
||||
ReflectConstruct,
|
||||
ReflectSet,
|
||||
ReflectGet,
|
||||
RegExp,
|
||||
RegExpPrototype,
|
||||
RegExpPrototypeExec,
|
||||
RegExpPrototypeGetDotAll,
|
||||
RegExpPrototypeGetFlags,
|
||||
RegExpPrototypeGetGlobal,
|
||||
RegExpPrototypeGetHasIndices,
|
||||
RegExpPrototypeGetIgnoreCase,
|
||||
RegExpPrototypeGetMultiline,
|
||||
RegExpPrototypeGetSource,
|
||||
RegExpPrototypeGetSticky,
|
||||
RegExpPrototypeGetUnicode,
|
||||
Set,
|
||||
SymbolIterator,
|
||||
SymbolMatch,
|
||||
SymbolMatchAll,
|
||||
SymbolReplace,
|
||||
SymbolSearch,
|
||||
SymbolSpecies,
|
||||
SymbolSplit,
|
||||
WeakMap,
|
||||
WeakRef,
|
||||
WeakSet,
|
||||
|
@ -490,5 +514,128 @@ primordials.SafePromiseRace = (promises, mapFn) =>
|
|||
);
|
||||
|
||||
|
||||
const {
|
||||
exec: OriginalRegExpPrototypeExec,
|
||||
[SymbolMatch]: OriginalRegExpPrototypeSymbolMatch,
|
||||
[SymbolMatchAll]: OriginalRegExpPrototypeSymbolMatchAll,
|
||||
[SymbolReplace]: OriginalRegExpPrototypeSymbolReplace,
|
||||
[SymbolSearch]: OriginalRegExpPrototypeSymbolSearch,
|
||||
[SymbolSplit]: OriginalRegExpPrototypeSymbolSplit,
|
||||
} = RegExpPrototype;
|
||||
|
||||
class RegExpLikeForStringSplitting {
|
||||
#regex;
|
||||
constructor() {
|
||||
this.#regex = ReflectConstruct(RegExp, arguments);
|
||||
}
|
||||
|
||||
get lastIndex() {
|
||||
return ReflectGet(this.#regex, 'lastIndex');
|
||||
}
|
||||
set lastIndex(value) {
|
||||
ReflectSet(this.#regex, 'lastIndex', value);
|
||||
}
|
||||
|
||||
exec() {
|
||||
return ReflectApply(OriginalRegExpPrototypeExec, this.#regex, arguments);
|
||||
}
|
||||
}
|
||||
ObjectSetPrototypeOf(RegExpLikeForStringSplitting.prototype, null);
|
||||
|
||||
primordials.hardenRegExp = function hardenRegExp(pattern) {
|
||||
ObjectDefineProperties(pattern, {
|
||||
[SymbolMatch]: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: OriginalRegExpPrototypeSymbolMatch,
|
||||
},
|
||||
[SymbolMatchAll]: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: OriginalRegExpPrototypeSymbolMatchAll,
|
||||
},
|
||||
[SymbolReplace]: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: OriginalRegExpPrototypeSymbolReplace,
|
||||
},
|
||||
[SymbolSearch]: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: OriginalRegExpPrototypeSymbolSearch,
|
||||
},
|
||||
[SymbolSplit]: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: OriginalRegExpPrototypeSymbolSplit,
|
||||
},
|
||||
constructor: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: {
|
||||
[SymbolSpecies]: RegExpLikeForStringSplitting,
|
||||
}
|
||||
},
|
||||
dotAll: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: RegExpPrototypeGetDotAll(pattern),
|
||||
},
|
||||
exec: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: OriginalRegExpPrototypeExec,
|
||||
},
|
||||
global: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: RegExpPrototypeGetGlobal(pattern),
|
||||
},
|
||||
hasIndices: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: RegExpPrototypeGetHasIndices(pattern),
|
||||
},
|
||||
ignoreCase: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: RegExpPrototypeGetIgnoreCase(pattern),
|
||||
},
|
||||
multiline: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: RegExpPrototypeGetMultiline(pattern),
|
||||
},
|
||||
source: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: RegExpPrototypeGetSource(pattern),
|
||||
},
|
||||
sticky: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: RegExpPrototypeGetSticky(pattern),
|
||||
},
|
||||
unicode: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: RegExpPrototypeGetUnicode(pattern),
|
||||
},
|
||||
});
|
||||
ObjectDefineProperty(pattern, 'flags', {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: RegExpPrototypeGetFlags(pattern),
|
||||
});
|
||||
return pattern;
|
||||
};
|
||||
|
||||
|
||||
primordials.SafeStringPrototypeSearch = (str, regexp) => {
|
||||
regexp.lastIndex = 0;
|
||||
const match = RegExpPrototypeExec(regexp, str);
|
||||
return match ? match.index : -1;
|
||||
};
|
||||
|
||||
ObjectSetPrototypeOf(primordials, null);
|
||||
ObjectFreeze(primordials);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue