11// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
22// Copyright Joyent and Node contributors. All rights reserved. MIT license.
33
4- // TODO(petamoriken): enable prefer-primordials for node polyfills
5- // deno-lint-ignore-file prefer-primordials
6-
74import { notImplemented } from "ext:deno_node/_utils.ts" ;
85import { urlToHttpOptions } from "ext:deno_node/internal/url.ts" ;
96import {
@@ -17,6 +14,14 @@ import { type ServerHandler, ServerImpl as HttpServer } from "node:http";
1714import { validateObject } from "ext:deno_node/internal/validators.mjs" ;
1815import { kEmptyObject } from "ext:deno_node/internal/util.mjs" ;
1916import { Buffer } from "node:buffer" ;
17+ import { primordials } from "ext:core/mod.js" ;
18+ const {
19+ ArrayPrototypeShift,
20+ ArrayPrototypeUnshift,
21+ ArrayIsArray,
22+ ObjectPrototypeIsPrototypeOf,
23+ ObjectAssign,
24+ } = primordials ;
2025
2126export class Server extends HttpServer {
2227 constructor ( opts , requestListener ?: ServerHandler ) {
@@ -29,11 +34,11 @@ export class Server extends HttpServer {
2934 validateObject ( opts , "options" ) ;
3035 }
3136
32- if ( opts . cert && Array . isArray ( opts . cert ) ) {
37+ if ( opts . cert && ArrayIsArray ( opts . cert ) ) {
3338 notImplemented ( "https.Server.opts.cert array type" ) ;
3439 }
3540
36- if ( opts . key && Array . isArray ( opts . key ) ) {
41+ if ( opts . key && ArrayIsArray ( opts . key ) ) {
3742 notImplemented ( "https.Server.opts.key array type" ) ;
3843 }
3944
@@ -42,10 +47,12 @@ export class Server extends HttpServer {
4247
4348 _additionalServeOptions ( ) {
4449 return {
45- cert : this . _opts . cert instanceof Buffer
50+ cert : ObjectPrototypeIsPrototypeOf ( Buffer , this . _opts . cert )
51+ // deno-lint-ignore prefer-primordials
4652 ? this . _opts . cert . toString ( )
4753 : this . _opts . cert ,
48- key : this . _opts . key instanceof Buffer
54+ key : ObjectPrototypeIsPrototypeOf ( Buffer , this . _opts . key )
55+ // deno-lint-ignore prefer-primordials
4956 ? this . _opts . key . toString ( )
5057 : this . _opts . key ,
5158 } ;
@@ -159,18 +166,18 @@ export function request(...args: any[]) {
159166 let options = { } ;
160167
161168 if ( typeof args [ 0 ] === "string" ) {
162- const urlStr = args . shift ( ) ;
169+ const urlStr = ArrayPrototypeShift ( args ) ;
163170 options = urlToHttpOptions ( new URL ( urlStr ) ) ;
164- } else if ( args [ 0 ] instanceof URL ) {
165- options = urlToHttpOptions ( args . shift ( ) ) ;
171+ } else if ( ObjectPrototypeIsPrototypeOf ( URL , args [ 0 ] ) ) {
172+ options = urlToHttpOptions ( ArrayPrototypeShift ( args ) ) ;
166173 }
167174
168175 if ( args [ 0 ] && typeof args [ 0 ] !== "function" ) {
169- Object . assign ( options , args . shift ( ) ) ;
176+ ObjectAssign ( options , ArrayPrototypeShift ( args ) ) ;
170177 }
171178
172179 options . _defaultAgent = globalAgent ;
173- args . unshift ( options ) ;
180+ ArrayPrototypeUnshift ( args , options ) ;
174181
175182 return new HttpsClientRequest ( args [ 0 ] , args [ 1 ] ) ;
176183}
0 commit comments