diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-01-27 13:36:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 13:36:36 +0100 |
commit | 884143218fad0e18f7553aaf079d52de703f7601 (patch) | |
tree | 9b9e9d30ea647041438ef8fa974b8d4234cabf73 /ext/web/09_file.js | |
parent | dcf8f144ab0516936bfa4e93357d71f1732d880e (diff) |
refactor: update runtime code for primordial checks for "instanceof" (#13497)
Diffstat (limited to 'ext/web/09_file.js')
-rw-r--r-- | ext/web/09_file.js | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/ext/web/09_file.js b/ext/web/09_file.js index 289db22ec..fbc00326e 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -15,7 +15,7 @@ const core = window.Deno.core; const webidl = window.__bootstrap.webidl; const { - ArrayBuffer, + ArrayBufferPrototype, ArrayBufferPrototypeSlice, ArrayBufferIsView, ArrayPrototypePush, @@ -23,6 +23,7 @@ DatePrototypeGetTime, MathMax, MathMin, + ObjectPrototypeIsPrototypeOf, RegExpPrototypeTest, StringPrototypeCharAt, StringPrototypeToLowerCase, @@ -109,7 +110,7 @@ const processedParts = []; let size = 0; for (const element of parts) { - if (element instanceof ArrayBuffer) { + if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, element)) { const chunk = new Uint8Array(ArrayBufferPrototypeSlice(element, 0)); ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk)); size += element.byteLength; @@ -121,7 +122,7 @@ ); size += element.byteLength; ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk)); - } else if (element instanceof Blob) { + } else if (ObjectPrototypeIsPrototypeOf(BlobPrototype, element)) { ArrayPrototypePush(processedParts, element); size += element.size; } else if (typeof element === "string") { @@ -157,7 +158,7 @@ */ function getParts(blob, bag = []) { for (const part of blob[_parts]) { - if (part instanceof Blob) { + if (ObjectPrototypeIsPrototypeOf(BlobPrototype, part)) { getParts(part, bag); } else { ArrayPrototypePush(bag, part._id); @@ -204,13 +205,13 @@ /** @returns {number} */ get size() { - webidl.assertBranded(this, Blob); + webidl.assertBranded(this, BlobPrototype); return this[_size]; } /** @returns {string} */ get type() { - webidl.assertBranded(this, Blob); + webidl.assertBranded(this, BlobPrototype); return this[_type]; } @@ -221,7 +222,7 @@ * @returns {Blob} */ slice(start = undefined, end = undefined, contentType = undefined) { - webidl.assertBranded(this, Blob); + webidl.assertBranded(this, BlobPrototype); const prefix = "Failed to execute 'slice' on 'Blob'"; if (start !== undefined) { start = webidl.converters["long long"](start, { @@ -316,7 +317,7 @@ * @returns {ReadableStream<Uint8Array>} */ stream() { - webidl.assertBranded(this, Blob); + webidl.assertBranded(this, BlobPrototype); const partIterator = toIterator(this[_parts]); const stream = new ReadableStream({ type: "bytes", @@ -338,7 +339,7 @@ * @returns {Promise<string>} */ async text() { - webidl.assertBranded(this, Blob); + webidl.assertBranded(this, BlobPrototype); const buffer = await this.arrayBuffer(); return core.decode(new Uint8Array(buffer)); } @@ -347,7 +348,7 @@ * @returns {Promise<ArrayBuffer>} */ async arrayBuffer() { - webidl.assertBranded(this, Blob); + webidl.assertBranded(this, BlobPrototype); const stream = this.stream(); const bytes = new Uint8Array(this.size); let offset = 0; @@ -361,7 +362,7 @@ [SymbolFor("Deno.customInspect")](inspect) { return inspect(consoleInternal.createFilteredInspectProxy({ object: this, - evaluate: this instanceof Blob, + evaluate: ObjectPrototypeIsPrototypeOf(BlobPrototype, this), keys: [ "size", "type", @@ -371,15 +372,22 @@ } webidl.configurePrototype(Blob); + const BlobPrototype = Blob.prototype; - webidl.converters["Blob"] = webidl.createInterfaceConverter("Blob", Blob); + webidl.converters["Blob"] = webidl.createInterfaceConverter( + "Blob", + Blob.prototype, + ); webidl.converters["BlobPart"] = (V, opts) => { // Union for ((ArrayBuffer or ArrayBufferView) or Blob or USVString) if (typeof V == "object") { - if (V instanceof Blob) { + if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) { return webidl.converters["Blob"](V, opts); } - if (V instanceof ArrayBuffer || V instanceof SharedArrayBuffer) { + if ( + ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) || + ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V) + ) { return webidl.converters["ArrayBuffer"](V, opts); } if (ArrayBufferIsView(V)) { @@ -458,18 +466,19 @@ /** @returns {string} */ get name() { - webidl.assertBranded(this, File); + webidl.assertBranded(this, FilePrototype); return this[_Name]; } /** @returns {number} */ get lastModified() { - webidl.assertBranded(this, File); + webidl.assertBranded(this, FilePrototype); return this[_LastModified]; } } webidl.configurePrototype(File); + const FilePrototype = File.prototype; webidl.converters["FilePropertyBag"] = webidl.createDictionaryConverter( "FilePropertyBag", @@ -593,6 +602,8 @@ blobFromObjectUrl, getParts, Blob, + BlobPrototype, File, + FilePrototype, }; })(this); |