refactor: ginify Session (#23569)
This commit is contained in:
parent
3f3a760a01
commit
de44d28c8e
11 changed files with 135 additions and 111 deletions
|
@ -2,7 +2,6 @@ import * as url from 'url';
|
|||
import { Readable, Writable } from 'stream';
|
||||
import { app } from 'electron';
|
||||
import { ClientRequestConstructorOptions, UploadProgress } from 'electron/main';
|
||||
const { Session } = process.electronBinding('session');
|
||||
const { net, Net, isValidHeaderName, isValidHeaderValue, createURLLoader } = process.electronBinding('net');
|
||||
|
||||
const kSupportedProtocols = new Set(['http:', 'https:']);
|
||||
|
@ -250,7 +249,8 @@ function parseOptions (optionsIn: ClientRequestConstructorOptions | string): Nod
|
|||
}
|
||||
}
|
||||
if (options.session) {
|
||||
if (options.session instanceof Session) {
|
||||
// Weak check, but it should be enough to catch 99% of accidental misuses.
|
||||
if (options.session.constructor && options.session.constructor.name === 'Session') {
|
||||
urlLoaderOptions.session = options.session;
|
||||
} else {
|
||||
throw new TypeError('`session` should be an instance of the Session class');
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const { EventEmitter } = require('events');
|
||||
const { app, deprecate } = require('electron');
|
||||
const { fromPartition, Session } = process.electronBinding('session');
|
||||
const { fromPartition } = process.electronBinding('session');
|
||||
|
||||
// Public API.
|
||||
Object.defineProperties(exports, {
|
||||
|
@ -15,9 +15,3 @@ Object.defineProperties(exports, {
|
|||
value: fromPartition
|
||||
}
|
||||
});
|
||||
|
||||
Object.setPrototypeOf(Session.prototype, EventEmitter.prototype);
|
||||
|
||||
Session.prototype._init = function () {
|
||||
app.emit('session-created', this);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue