Skip to content

Commit 99ae769

Browse files
committed
#220 Prevent new constructor creation if undefined is passed explicitly
1 parent 4df3d1a commit 99ae769

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

big.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@
8989
var x = this;
9090

9191
// Enable constructor usage without new.
92-
if (!(x instanceof Big)) return n === UNDEFINED ? _Big_() : new Big(n);
92+
if (!(x instanceof Big)) {
93+
return n === UNDEFINED && arguments.length === 0 ? _Big_() : new Big(n);
94+
}
9395

9496
// Duplicate.
9597
if (n instanceof Big) {
@@ -630,8 +632,8 @@
630632

631633
return this.minus(x.times(y));
632634
};
633-
634-
635+
636+
635637
/*
636638
* Return a new Big whose value is the value of this Big negated.
637639
*/

big.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ function _Big_() {
8686
var x = this;
8787

8888
// Enable constructor usage without new.
89-
if (!(x instanceof Big)) return n === UNDEFINED ? _Big_() : new Big(n);
89+
if (!(x instanceof Big)) {
90+
return n === UNDEFINED && arguments.length === 0 ? _Big_() : new Big(n);
91+
}
92+
9093

9194
// Duplicate.
9295
if (n instanceof Big) {

0 commit comments

Comments
 (0)