@@ -42,17 +42,20 @@ const {
4242
4343const { getConstructorOf, removeColors } = require ( 'internal/util' ) ;
4444const {
45- ERR_ARG_NOT_ITERABLE ,
46- ERR_INVALID_ARG_TYPE ,
47- ERR_INVALID_ARG_VALUE ,
48- ERR_INVALID_FILE_URL_HOST ,
49- ERR_INVALID_FILE_URL_PATH ,
50- ERR_INVALID_THIS ,
51- ERR_INVALID_TUPLE ,
52- ERR_INVALID_URL ,
53- ERR_INVALID_URL_SCHEME ,
54- ERR_MISSING_ARGS
55- } = require ( 'internal/errors' ) . codes ;
45+ codes : {
46+ ERR_ARG_NOT_ITERABLE ,
47+ ERR_INVALID_ARG_TYPE ,
48+ ERR_INVALID_ARG_VALUE ,
49+ ERR_INVALID_FILE_URL_HOST ,
50+ ERR_INVALID_FILE_URL_PATH ,
51+ ERR_INVALID_THIS ,
52+ ERR_INVALID_TUPLE ,
53+ ERR_INVALID_URL ,
54+ ERR_INVALID_URL_SCHEME ,
55+ ERR_MISSING_ARGS ,
56+ ERR_NO_CRYPTO ,
57+ } ,
58+ } = require ( 'internal/errors' ) ;
5659const {
5760 CHAR_AMPERSAND ,
5861 CHAR_BACKWARD_SLASH ,
@@ -103,7 +106,7 @@ const {
103106const {
104107 storeDataObject,
105108 revokeDataObject,
106- } = internalBinding ( 'buffer ' ) ;
109+ } = internalBinding ( 'blob ' ) ;
107110
108111const context = Symbol ( 'context' ) ;
109112const cannotBeBase = Symbol ( 'cannot-be-base' ) ;
@@ -115,26 +118,22 @@ const kFormat = Symbol('format');
115118
116119let blob ;
117120let cryptoRandom ;
118- let threadId ;
119121
120122function lazyBlob ( ) {
121- if ( blob === undefined )
122- blob = require ( 'internal/blob' ) ;
123+ blob ??= require ( 'internal/blob' ) ;
123124 return blob ;
124125}
125126
126127function lazyCryptoRandom ( ) {
127- if ( cryptoRandom === undefined )
128- cryptoRandom = require ( 'internal/crypto/random' ) ;
128+ try {
129+ cryptoRandom ??= require ( 'internal/crypto/random' ) ;
130+ } catch {
131+ // If Node.js built without crypto support, we'll fall
132+ // through here and handle it later.
133+ }
129134 return cryptoRandom ;
130135}
131136
132- function lazyThreadId ( ) {
133- if ( threadId === undefined )
134- threadId = require ( 'worker_threads' ) . threadId ;
135- return threadId ;
136- }
137-
138137// https://tc39.github.io/ecma262/#sec-%iteratorprototype%-object
139138const IteratorPrototype = ObjectGetPrototypeOf (
140139 ObjectGetPrototypeOf ( [ ] [ SymbolIterator ] ( ) )
@@ -959,22 +958,29 @@ class URL {
959958 }
960959
961960 static createObjectURL ( obj ) {
961+ const cryptoRandom = lazyCryptoRandom ( ) ;
962+ if ( cryptoRandom === undefined )
963+ throw new ERR_NO_CRYPTO ( ) ;
964+
965+ // Yes, lazy loading is annoying but because of circular
966+ // references between the url, internal/blob, and buffer
967+ // modules, lazy loading here makes sure that things work.
962968 const blob = lazyBlob ( ) ;
963969 if ( ! blob . isBlob ( obj ) )
964970 throw new ERR_INVALID_ARG_TYPE ( 'obj' , 'Blob' , obj ) ;
965971
966- const id = lazyCryptoRandom ( ) . randomUUID ( ) ;
972+ const id = cryptoRandom . randomUUID ( ) ;
967973
968974 storeDataObject ( id , obj [ blob . kHandle ] , obj . size , obj . type ) ;
969975
970- return `blob:node: ${ lazyThreadId ( ) } :${ id } ` ;
976+ return `blob:nodedata :${ id } ` ;
971977 }
972978
973979 static revokeObjectURL ( url ) {
974980 url = `${ url } ` ;
975981 try {
976982 const parsed = new URL ( url ) ;
977- const { 2 : id } = parsed . pathname . split ( ':' ) ;
983+ const { 1 : id } = StringPrototypeSplit ( parsed . pathname , ':' ) ;
978984 if ( id !== undefined )
979985 revokeDataObject ( id ) ;
980986 } catch {
0 commit comments