refactor: promisify prototype methods (#16935)
This commit is contained in:
parent
9112ad01be
commit
2492f0bcac
3 changed files with 14 additions and 19 deletions
|
@ -61,7 +61,6 @@
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
|
||||||
using atom::api::Cookies;
|
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
using content::StoragePartition;
|
using content::StoragePartition;
|
||||||
|
|
||||||
|
@ -785,6 +784,8 @@ void Session::BuildPrototype(v8::Isolate* isolate,
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::Cookies;
|
||||||
|
using atom::api::Protocol;
|
||||||
using atom::api::Session;
|
using atom::api::Session;
|
||||||
|
|
||||||
v8::Local<v8::Value> FromPartition(const std::string& partition,
|
v8::Local<v8::Value> FromPartition(const std::string& partition,
|
||||||
|
@ -810,6 +811,9 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
dict.Set(
|
dict.Set(
|
||||||
"Cookies",
|
"Cookies",
|
||||||
Cookies::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
Cookies::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||||
|
dict.Set(
|
||||||
|
"Protocol",
|
||||||
|
Protocol::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||||
dict.SetMethod("fromPartition", &FromPartition);
|
dict.SetMethod("fromPartition", &FromPartition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
// TODO(deepak1556): Deprecate and remove standalone netLog module,
|
// TODO(deepak1556): Deprecate and remove standalone netLog module,
|
||||||
// it is now a property of sessio module.
|
// it is now a property of session module.
|
||||||
const { app, session } = require('electron')
|
const { app, session } = require('electron')
|
||||||
|
|
||||||
// Fallback to default session.
|
// Fallback to default session.
|
||||||
|
|
|
@ -2,22 +2,7 @@
|
||||||
|
|
||||||
const { EventEmitter } = require('events')
|
const { EventEmitter } = require('events')
|
||||||
const { app, deprecate } = require('electron')
|
const { app, deprecate } = require('electron')
|
||||||
const { Session, Cookies } = process.atomBinding('session')
|
const { fromPartition, Session, Cookies, Protocol } = process.atomBinding('session')
|
||||||
const realFromPartition = process.atomBinding('session').fromPartition
|
|
||||||
|
|
||||||
const wrappedSymbol = Symbol('wrapped-deprecate')
|
|
||||||
const fromPartition = (partition) => {
|
|
||||||
const session = realFromPartition(partition)
|
|
||||||
if (!session[wrappedSymbol]) {
|
|
||||||
session[wrappedSymbol] = true
|
|
||||||
const { cookies } = session
|
|
||||||
cookies.flushStore = deprecate.promisify(cookies.flushStore)
|
|
||||||
cookies.get = deprecate.promisify(cookies.get)
|
|
||||||
cookies.remove = deprecate.promisify(cookies.remove)
|
|
||||||
cookies.set = deprecate.promisify(cookies.set)
|
|
||||||
}
|
|
||||||
return session
|
|
||||||
}
|
|
||||||
|
|
||||||
// Public API.
|
// Public API.
|
||||||
Object.defineProperties(exports, {
|
Object.defineProperties(exports, {
|
||||||
|
@ -35,6 +20,12 @@ Object.setPrototypeOf(Session.prototype, EventEmitter.prototype)
|
||||||
Object.setPrototypeOf(Cookies.prototype, EventEmitter.prototype)
|
Object.setPrototypeOf(Cookies.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
Session.prototype._init = function () {
|
Session.prototype._init = function () {
|
||||||
this.protocol.isProtocolHandled = deprecate.promisify(this.protocol.isProtocolHandled)
|
|
||||||
app.emit('session-created', this)
|
app.emit('session-created', this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cookies.prototype.flushStore = deprecate.promisify(Cookies.prototype.flushStore)
|
||||||
|
Cookies.prototype.get = deprecate.promisify(Cookies.prototype.get)
|
||||||
|
Cookies.prototype.remove = deprecate.promisify(Cookies.prototype.remove)
|
||||||
|
Cookies.prototype.set = deprecate.promisify(Cookies.prototype.set)
|
||||||
|
|
||||||
|
Protocol.prototype.isProtocolHandled = deprecate.promisify(Protocol.prototype.isProtocolHandled)
|
||||||
|
|
Loading…
Reference in a new issue