@@ -93,11 +93,6 @@ const {
93
93
updateUrl,
94
94
} = internalBinding ( 'url' ) ;
95
95
96
- const {
97
- storeDataObject,
98
- revokeDataObject,
99
- } = internalBinding ( 'blob' ) ;
100
-
101
96
const FORWARD_SLASH = / \/ / g;
102
97
103
98
const context = Symbol ( 'context' ) ;
@@ -782,35 +777,6 @@ class URL {
782
777
return this [ context ] . href ;
783
778
}
784
779
785
- static createObjectURL ( obj ) {
786
- const cryptoRandom = lazyCryptoRandom ( ) ;
787
- if ( cryptoRandom === undefined )
788
- throw new ERR_NO_CRYPTO ( ) ;
789
-
790
- const blob = lazyBlob ( ) ;
791
- if ( ! blob . isBlob ( obj ) )
792
- throw new ERR_INVALID_ARG_TYPE ( 'obj' , 'Blob' , obj ) ;
793
-
794
- const id = cryptoRandom . randomUUID ( ) ;
795
-
796
- storeDataObject ( id , obj [ blob . kHandle ] , obj . size , obj . type ) ;
797
-
798
- return `blob:nodedata:${ id } ` ;
799
- }
800
-
801
- static revokeObjectURL ( url ) {
802
- url = `${ url } ` ;
803
- try {
804
- // TODO(@anonrig): Remove this try/catch by calling `parse` directly.
805
- const parsed = new URL ( url ) ;
806
- const split = StringPrototypeSplit ( parsed . pathname , ':' ) ;
807
- if ( split . length === 2 )
808
- revokeDataObject ( split [ 1 ] ) ;
809
- } catch {
810
- // If there's an error, it's ignored.
811
- }
812
- }
813
-
814
780
static canParse ( url , base = undefined ) {
815
781
url = `${ url } ` ;
816
782
@@ -841,8 +807,6 @@ ObjectDefineProperties(URL.prototype, {
841
807
} ) ;
842
808
843
809
ObjectDefineProperties ( URL , {
844
- createObjectURL : kEnumerableProperty ,
845
- revokeObjectURL : kEnumerableProperty ,
846
810
canParse : {
847
811
__proto__ : null ,
848
812
configurable : true ,
@@ -851,6 +815,59 @@ ObjectDefineProperties(URL, {
851
815
} ,
852
816
} ) ;
853
817
818
+ function installObjectURLMethods ( ) {
819
+ const {
820
+ storeDataObject,
821
+ revokeDataObject,
822
+ } = internalBinding ( 'blob' ) ;
823
+
824
+ function createObjectURL ( obj ) {
825
+ const cryptoRandom = lazyCryptoRandom ( ) ;
826
+ if ( cryptoRandom === undefined )
827
+ throw new ERR_NO_CRYPTO ( ) ;
828
+
829
+ const blob = lazyBlob ( ) ;
830
+ if ( ! blob . isBlob ( obj ) )
831
+ throw new ERR_INVALID_ARG_TYPE ( 'obj' , 'Blob' , obj ) ;
832
+
833
+ const id = cryptoRandom . randomUUID ( ) ;
834
+
835
+ storeDataObject ( id , obj [ blob . kHandle ] , obj . size , obj . type ) ;
836
+
837
+ return `blob:nodedata:${ id } ` ;
838
+ }
839
+
840
+ function revokeObjectURL ( url ) {
841
+ url = `${ url } ` ;
842
+ try {
843
+ // TODO(@anonrig): Remove this try/catch by calling `parse` directly.
844
+ const parsed = new URL ( url ) ;
845
+ const split = StringPrototypeSplit ( parsed . pathname , ':' ) ;
846
+ if ( split . length === 2 )
847
+ revokeDataObject ( split [ 1 ] ) ;
848
+ } catch {
849
+ // If there's an error, it's ignored.
850
+ }
851
+ }
852
+
853
+ ObjectDefineProperties ( URL , {
854
+ createObjectURL : {
855
+ __proto__ : null ,
856
+ configurable : true ,
857
+ writable : true ,
858
+ enumerable : true ,
859
+ value : createObjectURL ,
860
+ } ,
861
+ revokeObjectURL : {
862
+ __proto__ : null ,
863
+ configurable : true ,
864
+ writable : true ,
865
+ enumerable : true ,
866
+ value : revokeObjectURL ,
867
+ } ,
868
+ } ) ;
869
+ }
870
+
854
871
// application/x-www-form-urlencoded parser
855
872
// Ref: https://url.spec.whatwg.org/#concept-urlencoded-parser
856
873
function parseParams ( qs ) {
@@ -1341,6 +1358,7 @@ module.exports = {
1341
1358
pathToFileURL,
1342
1359
toPathIfFileURL,
1343
1360
isURLInstance,
1361
+ installObjectURLMethods,
1344
1362
URL ,
1345
1363
URLSearchParams,
1346
1364
domainToASCII,
0 commit comments