Skip to content

Commit

Permalink
buffer: expose Blob as a global
Browse files Browse the repository at this point in the history
`Blob` is defined as a global in the spec. We have WPT's for it,
and it's graduated experimental. Time to expose it as a global.

Signed-off-by: James M Snell <[email protected]>

PR-URL: #41270
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
  • Loading branch information
jasnell committed Dec 24, 2021
1 parent 99c18f4 commit cea76db
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ module.exports = {
BigInt: 'readable',
BigInt64Array: 'readable',
BigUint64Array: 'readable',
Blob: 'readable',
DOMException: 'readable',
Event: 'readable',
EventTarget: 'readable',
Expand Down
2 changes: 1 addition & 1 deletion doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ added:
- v14.18.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/00000
pr-url: https://github.com/nodejs/node/pull/41270
description: No longer experimental.
-->

Expand Down
10 changes: 10 additions & 0 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ added: v17.3.0

If `abortSignal.aborted` is `true`, throws `abortSignal.reason`.

## Class: `Blob`

<!-- YAML
added: REPLACEME
-->

<!-- type=global -->

See {Blob}.

## Class: `Buffer`

<!-- YAML
Expand Down
2 changes: 2 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ rules:
# disabled with --no-harmony-atomics CLI flag.
- name: Atomics
message: "Use `const { Atomics } = globalThis;` instead of the global."
- name: Blob
message: "Use `const { Blob } = require('buffer');` instead of the global."
- name: Buffer
message: "Use `const { Buffer } = require('buffer');` instead of the global."
- name: DOMException
Expand Down
7 changes: 7 additions & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ function setupGlobalProxy() {

function setupBuffer() {
const {
Blob,
Buffer,
atob,
btoa,
Expand All @@ -456,6 +457,12 @@ function setupBuffer() {
delete bufferBinding.zeroFill;

ObjectDefineProperties(globalThis, {
'Blob': {
value: Blob,
enumerable: false,
writable: true,
configurable: true,
},
'Buffer': {
value: Buffer,
enumerable: false,
Expand Down

0 comments on commit cea76db

Please sign in to comment.