Skip to content

Commit

Permalink
Constructor var name cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Mar 12, 2019
1 parent 2c0585f commit fc232ac
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/fs/stat-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function init() {
ELECTRON
} = ENV

const { prototype } = Stats
const StatsProto = Stats.prototype

function statSync(thePath) {
if (typeof thePath !== "string") {
Expand All @@ -37,7 +37,7 @@ function init() {
// https://github.com/brave/muon/blob/master/lib/common/asar.js
if (ELECTRON &&
! (cached instanceof Stats)) {
setPrototypeOf(cached, prototype)
setPrototypeOf(cached, StatsProto)
}
} catch {
cached = null
Expand Down
14 changes: 7 additions & 7 deletions src/generic/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import shared from "../shared.js"
import unapply from "../util/unapply.js"

function init() {
const { prototype } = Array
const safeProto = SafeArray.prototype
const ArrayProto = Array.prototype
const SafeProto = SafeArray.prototype

return {
concat: unapply(safeProto.concat),
concat: unapply(SafeProto.concat),
from: SafeArray.from,
indexOf: unapply(prototype.indexOf),
join: unapply(prototype.join),
indexOf: unapply(ArrayProto.indexOf),
join: unapply(ArrayProto.join),
of: SafeArray.of,
push: unapply(prototype.push),
unshift: unapply(prototype.unshift)
push: unapply(ArrayProto.push),
unshift: unapply(ArrayProto.unshift)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ if (! ELECTRON ||
Module.wrapper = staticWrapper
}

const { prototype } = Module
const ModuleProto = Module.prototype

prototype._compile = protoCompile
prototype.constructor = Module
prototype.load = protoLoad
prototype.require = req
ModuleProto._compile = protoCompile
ModuleProto.constructor = Module
ModuleProto.load = protoLoad
ModuleProto.require = req

// Initialize `Module._extensions` with only the enumerable string keyed
// properties of `RealModule._extensions` to avoid `shared.symbol.wrapper`
Expand Down
8 changes: 4 additions & 4 deletions src/safe/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ function init() {
const safeVM = safe(realVM)
const { Script } = safeVM
const SafeScript = safe(Script)
const SafeProto = SafeScript.prototype

const contextifyProto = getPrototypeOf(Script.prototype)
const names = ownKeys(contextifyProto)
const { prototype } = SafeScript

for (const name of names) {
if (! has(prototype, name)) {
copyProperty(prototype, contextifyProto, name)
if (! has(SafeProto, name)) {
copyProperty(SafeProto, contextifyProto, name)
}
}

setPrototypeOf(prototype, contextifyProto)
setPrototypeOf(SafeProto, contextifyProto)

setProperty(safeVM, "Script", SafeScript)

Expand Down
4 changes: 2 additions & 2 deletions src/util/instance-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import shared from "../shared.js"

function init() {
function instanceOf(value, Ctor) {
const { prototype } = Ctor
const CtorProto = Ctor.prototype

if (isObjectLike(value)) {
let proto = value

while ((proto = getPrototypeOf(proto)) !== null) {
if (proto === prototype) {
if (proto === CtorProto) {
return true
}
}
Expand Down
40 changes: 20 additions & 20 deletions src/util/prepare-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,48 +117,48 @@ function init() {
descriptors.forEach((descriptor, name) => {
Reflect.defineProperty(context, name, descriptor)

const builtin = context[name]
const realmBuiltin = realmBuiltins[name]
const Builtin = context[name]
const RealmBuiltin = realmBuiltins[name]

if (builtin === realmBuiltin ||
! isObjectLike(builtin) ||
! isObjectLike(realmBuiltin)) {
if (Builtin === RealmBuiltin ||
! isObjectLike(Builtin) ||
! isObjectLike(RealmBuiltin)) {
return
}

if (name === "Error") {
realmBuiltin.prepareStackTrace =
(...args) => Reflect.apply(builtin.prepareStackTrace, builtin, args)
RealmBuiltin.prepareStackTrace =
(...args) => Reflect.apply(Builtin.prepareStackTrace, Builtin, args)
} else if (name === "Object") {
Reflect.defineProperty(builtin, Symbol.hasInstance, {
Reflect.defineProperty(Builtin, Symbol.hasInstance, {
configurable: true,
value: function (instance) {
if (this === builtin) {
return instance instanceof realmBuiltin ||
instanceOf(instance, builtin)
if (this === Builtin) {
return instance instanceof RealmBuiltin ||
instanceOf(instance, Builtin)
}

return instanceOf(instance, this)
}
})
}

if (typeof realmBuiltin === "function") {
if (has(realmBuiltin, "prototype")) {
const { prototype } = realmBuiltin
if (typeof RealmBuiltin === "function") {
if (has(RealmBuiltin, "prototype")) {
const RealmProto = RealmBuiltin.prototype

if (isObjectLike(prototype)) {
const builtinProto = builtin.prototype
if (isObjectLike(RealmProto)) {
const BuiltinProto = Builtin.prototype

if (has(builtinProto, "constructor")) {
prototype.constructor = builtinProto.constructor
if (has(BuiltinProto, "constructor")) {
setProperty(RealmProto, "constructor", BuiltinProto.constructor)
}

setPrototypeOf(prototype, builtinProto)
setPrototypeOf(RealmProto, BuiltinProto)
}
}

setPrototypeOf(realmBuiltin, getPrototypeOf(builtin))
setPrototypeOf(RealmBuiltin, getPrototypeOf(Builtin))
}
})

Expand Down

0 comments on commit fc232ac

Please sign in to comment.