Skip to content

Commit

Permalink
fix: support Object.prototype.toString
Browse files Browse the repository at this point in the history
  • Loading branch information
piquark6046 committed Dec 27, 2024
1 parent 0533d6f commit 45989f1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions sources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,32 @@ Win.Proxy = new Proxy(Win.Proxy, {
//
return Reflect.construct(Target, Args, NewTarget)
}
})

Win.Object.prototype.toString = new Proxy(Win.Object.prototype.toString, {
apply(Target: typeof Object.prototype.toString, ThisArg: unknown, Args: []) {
let TensorResult: Array<number> = [0, 0, 0] // string, number, boolean
if (typeof ThisArg === 'object') {
Object.keys(ThisArg).forEach((Key: string) => {
switch (typeof ThisArg[Key]) {
case 'string':
if (ThisArg[Key].length > 5) {
TensorResult[0]++
}
break
case 'number':
TensorResult[1]++
break
case 'boolean':
TensorResult[2]++
break
}
})
}
if (TensorResult.every((Result) => Result >= 3) && typeof ThisArg['content'] !== 'object') {
HideLeftover()
throw new Error()
}
return Reflect.apply(Target, ThisArg, Args)
}
})

0 comments on commit 45989f1

Please sign in to comment.