refactor(ext/webidl): use TypedArrayPrototypeGetSymbolToStringTag (#17602)

This commit is contained in:
Kenta Moriuchi 2023-02-10 06:45:47 +09:00 committed by GitHub
parent 717daf4748
commit 8da235adce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -486,14 +486,6 @@ converters.DataView = (V, opts = {}) => {
return V;
};
// Returns the unforgeable `TypedArray` constructor name or `undefined`,
// if the `this` value isn't a valid `TypedArray` object.
//
// https://tc39.es/ecma262/#sec-get-%typedarray%.prototype-@@tostringtag
const typedArrayNameGetter = ObjectGetOwnPropertyDescriptor(
ObjectGetPrototypeOf(Uint8Array).prototype,
SymbolToStringTag,
).get;
ArrayPrototypeForEach(
[
Int8Array,
@ -510,7 +502,7 @@ ArrayPrototypeForEach(
const name = func.name;
const article = RegExpPrototypeTest(/^[AEIOU]/, name) ? "an" : "a";
converters[name] = (V, opts = {}) => {
if (!ArrayBufferIsView(V) || typedArrayNameGetter.call(V) !== name) {
if (TypedArrayPrototypeGetSymbolToStringTag(V) !== name) {
throw makeException(
TypeError,
`is not ${article} ${name} object`,