Skip to content

Commit 1f2f800

Browse files
committed
fix: do not allow non constructor calls
1 parent 1e07e0f commit 1f2f800

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

array.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var setPrototypeOf = require("es5-ext/object/set-prototype-of")
88
var defineProperty = Object.defineProperty, ArrayIterator;
99

1010
ArrayIterator = module.exports = function (arr, kind) {
11-
if (!(this instanceof ArrayIterator)) return new ArrayIterator(arr, kind);
11+
if (!(this instanceof ArrayIterator)) throw new TypeError("Constructor requires 'new'");
1212
Iterator.call(this, arr);
1313
if (!kind) kind = "value";
1414
else if (contains.call(kind, "key+value")) kind = "key+value";

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var clear = require("es5-ext/array/#/clear")
1111
var defineProperty = Object.defineProperty, defineProperties = Object.defineProperties, Iterator;
1212

1313
module.exports = Iterator = function (list, context) {
14-
if (!(this instanceof Iterator)) return new Iterator(list, context);
14+
if (!(this instanceof Iterator)) throw new TypeError("Constructor requires 'new'");
1515
defineProperties(this, {
1616
__list__: d("w", value(list)),
1717
__context__: d("w", context),

string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var setPrototypeOf = require("es5-ext/object/set-prototype-of")
1010
var defineProperty = Object.defineProperty, StringIterator;
1111

1212
StringIterator = module.exports = function (str) {
13-
if (!(this instanceof StringIterator)) return new StringIterator(str);
13+
if (!(this instanceof StringIterator)) throw new TypeError("Constructor requires 'new'");
1414
str = String(str);
1515
Iterator.call(this, str);
1616
defineProperty(this, "__length__", d("", str.length));

0 commit comments

Comments
 (0)