1+ // deno-lint-ignore-file no-explicit-any prefer-const no-unused-vars
12// This Source Code Form is subject to the terms of the Mozilla Public
23// License, v. 2.0. If a copy of the MPL was not distributed with this
34// file, You can obtain one at https://mozilla.org/MPL/2.0/.
45
6+ // @ts -ignore deno lint stuff
57type RequestInfo = Request ;
68
79// method => normalized method
@@ -56,6 +58,7 @@ interface RequestInit {
5658 /**
5759 * A string to set request's method.
5860 */
61+ // @ts -ignore deno lint stuff
5962 method ?: keyof typeof KNOWN_METHODS ;
6063 /**
6164 * A string to indicate whether the request will use CORS, or will be
@@ -84,29 +87,34 @@ interface RequestInit {
8487 /**
8588 * Can only be null. Used to disassociate request from any Window.
8689 */
90+ // @ts -ignore deno lint stuff
8791 window ?: any ;
8892}
8993
94+ const requestSymbol = Symbol ( "[[request]]" ) ;
95+ const signalSymbol = Symbol ( "[[signal]]" ) ;
96+ const bodySymbol = Symbol ( "[[body]]" ) ;
97+ // @ts -ignore deno lint stuff
9098class Request {
91- #request ;
99+ [ requestSymbol ] : any ;
92100 // TODO: comment in nova support module
93101 // #headers;
94- #signal ;
95- #body ;
102+ [ signalSymbol ] : AbortSignal | null = null ;
103+ [ bodySymbol ] : any = null ;
96104
97105 /** https://fetch.spec.whatwg.org/#request-class */
98- constructor ( input : RequestInfo , init : RequestInit = { __proto__ : null } ) {
106+ constructor ( input : RequestInfo , init : RequestInit = { __proto__ : null } as any ) {
99107 // 1. Let request be null.
100- let request = null ;
108+ let request : any = null ;
101109
102110 // 2. Let fallbackMode be null.
103- let fallbackMode = null ;
111+ let fallbackMode : any = null ;
104112
105113 // 3. Let baseURL be this’s relevant settings object’s API base URL.
106114 // const baseUrl = environmentSettingsObject.settingsObject.baseUrl
107115
108116 // 4. Let signal be null.
109- let signal = null ;
117+ let signal : any = null ;
110118
111119 // 5. If input is a string, then:
112120 if ( typeof input === "string" ) {
@@ -118,7 +126,7 @@ class Request {
118126 const parsedURL = new URL ( input ) ;
119127 request = newInnerRequest (
120128 "GET" ,
121- parsedURL ,
129+ parsedURL as any ,
122130 ( ) => [ ] ,
123131 null ,
124132 true ,
@@ -131,11 +139,12 @@ class Request {
131139 if ( ! Object . prototype . isPrototypeOf . call ( RequestPrototype , input ) ) {
132140 throw new TypeError ( "Unreachable" ) ;
133141 }
134- const originalReq = input . #request;
142+
143+ const originalReq = input [ requestSymbol ] ;
135144 // fold in of step 12 from below
136145 request = cloneInnerRequest ( originalReq , true ) ;
137146 request . redirectCount = 0 ; // reset to 0 - cloneInnerRequest copies the value
138- signal = input . #signal ;
147+ signal = input [ signalSymbol ] ;
139148 }
140149
141150 // 7. Let origin be this’s relevant settings object’s origin.
@@ -288,7 +297,7 @@ class Request {
288297 }
289298
290299 // 27. Set this’s request to request.
291- this . #request = request ;
300+ this [ requestSymbol ] = request ;
292301
293302 // // 28. Set this’s signal to a new AbortSignal object with this’s relevant
294303 // // Realm.
@@ -340,9 +349,9 @@ class Request {
340349 // }
341350
342351 // 34. Let inputBody be input’s request’s body if input is a Request object; otherwise null.
343- let inputBody = null ;
352+ let inputBody : any = null ;
344353 if ( Object . prototype . isPrototypeOf . call ( RequestPrototype , input ) ) {
345- inputBody = input . #body ;
354+ inputBody = input [ bodySymbol ] ;
346355 }
347356
348357 // 35. If either init["body"] exists and is non-null or inputBody is non-null, and request’s method is `GET` or `HEAD`, then throw a TypeError.
@@ -377,11 +386,11 @@ class Request {
377386 // 41. If initBody is null and inputBody is non-null, then:
378387 if ( initBody === null && inputBody !== null ) {
379388 // 1. If input is unusable, then throw a TypeError.
380- if ( input . #body && input . #body . unusable ( ) ) {
389+ if ( input [ bodySymbol ] && input [ bodySymbol ] . unusable ( ) ) {
381390 throw new TypeError ( "Input request's body is unusable" ) ;
382391 }
383392 // 2. Set finalBody to the result of creating a proxy for inputBody.
384- finalBody = inputBody . createProxy ( ) ;
393+ finalBody = ( inputBody as any ) . createProxy ( ) ;
385394 }
386395
387396 // 42. Set this’s request’s body to finalBody.
@@ -394,18 +403,18 @@ class Request {
394403 const credentials = request . credentials ;
395404 console . log ( "credentials" , credentials ) ;
396405
397- this . #request = request ;
406+ this [ requestSymbol ] = request ;
398407 }
399408
400409 // Returns request’s HTTP method, which is "GET" by default.
401410 get method ( ) {
402- return this . #request . method ;
411+ return this [ requestSymbol ] . method ;
403412 }
404413
405414 // Returns the URL of request as a string.
406415 get url ( ) {
407416 // The url getter steps are to return this’s request’s URL, serialized.
408- return this . #request . url ;
417+ return this [ requestSymbol ] . url ;
409418 }
410419
411420 // Returns a Headers object consisting of the headers associated with request.
@@ -419,7 +428,7 @@ class Request {
419428 // or "script".
420429 get destination ( ) {
421430 // The destination getter are to return this’s request’s destination.
422- return this . #request . destination ;
431+ return this [ requestSymbol ] . destination ;
423432 }
424433
425434 // Returns the referrer of request. Its value can be a same-origin URL if
@@ -428,84 +437,84 @@ class Request {
428437 // during fetching to determine the value of the `Referer` header of the
429438 // request being made.
430439 get referrer ( ) {
431- if ( this . #request . referrer === "no-referrer" ) {
440+ if ( this [ requestSymbol ] . referrer === "no-referrer" ) {
432441 return "" ;
433442 }
434443
435444 // 2. If this’s request’s referrer is "client", then return
436445 // "about:client".
437- if ( this . #request . referrer === "client" ) {
446+ if ( this [ requestSymbol ] . referrer === "client" ) {
438447 return "about:client" ;
439448 }
440449
441450 // Return this’s request’s referrer, serialized.
442- return this . #request . referrer . toString ( ) ;
451+ return this [ requestSymbol ] . referrer . toString ( ) ;
443452 }
444453
445454 // Returns the referrer policy associated with request.
446455 // This is used during fetching to compute the value of the request’s
447456 // referrer.
448457 get referrerPolicy ( ) {
449- return this . #request . referrerPolicy ;
458+ return this [ requestSymbol ] . referrerPolicy ;
450459 }
451460
452461 // Returns the mode associated with request, which is a string indicating
453462 // whether the request will use CORS, or will be restricted to same-origin
454463 // URLs.
455464 get mode ( ) {
456- return this . #request . mode ;
465+ return this [ requestSymbol ] . mode ;
457466 }
458467
459468 // Returns the credentials mode associated with request,
460469 // which is a string indicating whether credentials will be sent with the
461470 // request always, never, or only when sent to a same-origin URL.
462471 get credentials ( ) {
463- return this . #request . credentials ;
472+ return this [ requestSymbol ] . credentials ;
464473 }
465474
466475 // Returns the cache mode associated with request,
467476 // which is a string indicating how the request will
468477 // interact with the browser’s cache when fetching.
469478 get cache ( ) {
470- return this . #request . cache ;
479+ return this [ requestSymbol ] . cache ;
471480 }
472481
473482 // Returns the redirect mode associated with request,
474483 // which is a string indicating how redirects for the
475484 // request will be handled during fetching. A request
476485 // will follow redirects by default.
477486 get redirect ( ) {
478- return this . redirect . redirect ;
487+ return this [ requestSymbol ] . redirect ;
479488 }
480489
481490 get integrity ( ) {
482- return this . #request . integrity ;
491+ return this [ requestSymbol ] . integrity ;
483492 }
484493
485494 // Returns a boolean indicating whether or not request can outlive the
486495 // global in which it was created.
487496 get keepalive ( ) {
488- return this . #request . keepalive ;
497+ return this [ requestSymbol ] . keepalive ;
489498 }
490499
491500 get isReloadNavigation ( ) {
492- return this . #request . reloadNavigation ;
501+ return this [ requestSymbol ] . reloadNavigation ;
493502 }
494503
495504 get isHistoryNavigation ( ) {
496- return this . #request . historyNavigation ;
505+ return this [ requestSymbol ] . historyNavigation ;
497506 }
498507
499508 get signal ( ) {
500- return this . #signal ;
509+ return this [ signalSymbol ] ;
501510 }
502511
503512 get body ( ) {
504- return this . #request . body ? this . #request . body . stream : null ;
513+ return this [ requestSymbol ] . body ? this [ requestSymbol ] . body . stream : null ;
505514 }
506515
507516 get bodyUsed ( ) {
508- return ! ! this . #request . body ;
517+ return ! ! this [ requestSymbol ] . body ;
509518 }
510519
511520 get duplex ( ) {
@@ -581,7 +590,7 @@ const RequestPrototype = Request.prototype;
581590/** https://fetch.spec.whatwg.org/#concept-request-clone */
582591function cloneInnerRequest ( request : any , skipBody = false ) : any {
583592 const headerList = request . headerList . push (
584- ( x ) => [ x [ 0 ] , x [ 1 ] ] ,
593+ ( x : any ) => [ x [ 0 ] , x [ 1 ] ] ,
585594 ) ;
586595
587596 let body = null ;
@@ -651,7 +660,6 @@ function configureInterface(interface_: any) {
651660}
652661
653662// TODO: removed nova support module
654- // deno-lint-ignore no-explicit-any
655663function configureProperties ( obj : any ) {
656664 const descriptors = Object . getOwnPropertyDescriptors ( obj ) ;
657665 for ( const key in descriptors ) {
0 commit comments