From b4bdced49a0ee6f88df5ad4508b3d64b82b80ed9 Mon Sep 17 00:00:00 2001 From: Zachary Wu Date: Thu, 19 Oct 2023 20:54:02 +0800 Subject: [PATCH 1/2] Fix: Cannot set properties of undefined (setting 'TYPED_ARRAY_SUPPORT') --- .vscode/settings.json | 3 +++ polyfills/buffer-es6.js | 54 ++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..13ee2b0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "nuxt.isNuxtApp": false +} \ No newline at end of file diff --git a/polyfills/buffer-es6.js b/polyfills/buffer-es6.js index 83e5664..ce39aa5 100644 --- a/polyfills/buffer-es6.js +++ b/polyfills/buffer-es6.js @@ -208,6 +208,33 @@ var isArray = Array.isArray || function (arr) { var INSPECT_MAX_BYTES = 50; +/** + * The Buffer constructor returns instances of `Uint8Array` that have their + * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of + * `Uint8Array`, so the returned instances will have all the node `Buffer` methods + * and the `Uint8Array` methods. Square bracket notation works as expected -- it + * returns a single octet. + * + * The `Uint8Array` prototype remains unmodified. + */ + +function Buffer (arg, encodingOrOffset, length) { + if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { + return new Buffer(arg, encodingOrOffset, length) + } + + // Common case. + if (typeof arg === 'number') { + if (typeof encodingOrOffset === 'string') { + throw new Error( + 'If encoding is specified then the first argument must be a string' + ) + } + return allocUnsafe(this, arg) + } + return from(this, arg, encodingOrOffset, length) +} + /** * If `Buffer.TYPED_ARRAY_SUPPORT`: * === true Use Uint8Array implementation (fastest) @@ -266,33 +293,6 @@ function createBuffer (that, length) { return that } -/** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - -function Buffer (arg, encodingOrOffset, length) { - if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { - return new Buffer(arg, encodingOrOffset, length) - } - - // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new Error( - 'If encoding is specified then the first argument must be a string' - ) - } - return allocUnsafe(this, arg) - } - return from(this, arg, encodingOrOffset, length) -} - Buffer.poolSize = 8192; // not used by this implementation // TODO: Legacy, not needed anymore. Remove in next major version. From 70cec414d5278bda2d09c9ce81e8faf896abac14 Mon Sep 17 00:00:00 2001 From: Zachary <31946145+YuAnWu0000@users.noreply.github.com> Date: Mon, 11 Dec 2023 10:05:03 +0000 Subject: [PATCH 2/2] Delete: vscode settings --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 13ee2b0..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "nuxt.isNuxtApp": false -} \ No newline at end of file