Skip to content

Commit

Permalink
Merge pull request #276 from brucejo75/HTML_isArray_cross_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
filipenevola committed Mar 19, 2021
2 parents 043b66f + 1835f39 commit 4ce1f30
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/blaze/builtins.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Blaze._calculateCondition = function (cond) {
if (cond instanceof Array && cond.length === 0)
if (HTML.isArray(cond) && cond.length === 0)
cond = false;
return !! cond;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/html-tools/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ getContent = HTMLTools.Parse.getContent = function (scanner, shouldStopFunc) {
// as in `FOO.apply(null, content)`.
if (content == null)
content = [];
else if (! (content instanceof Array))
else if (! HTML.isArray(content))
content = [content];

items.push(HTML.getTag(tagName).apply(
Expand Down
25 changes: 17 additions & 8 deletions packages/htmljs/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ Raw.prototype.htmljsType = Raw.htmljsType = ['Raw'];


HTML.isArray = function (x) {
// could change this to use the more convoluted Object.prototype.toString
// approach that works when objects are passed between frames, but does
// it matter?
return (x instanceof Array);
return x instanceof Array || Array.isArray(x);
};

HTML.isConstructedObject = function (x) {
Expand All @@ -185,10 +182,22 @@ HTML.isConstructedObject = function (x) {
// if you assign to a prototype when setting up the class as in:
// `Foo = function () { ... }; Foo.prototype = { ... }`, then
// `(new Foo).constructor` is `Object`, not `Foo`).
return (x && (typeof x === 'object') &&
(x.constructor !== Object) &&
(typeof x.constructor === 'function') &&
(x instanceof x.constructor));
if(!x || (typeof x !== 'object')) return false;
// Is this a plain object?
let plain = false;
if(Object.getPrototypeOf(x) === null) {
plain = true;
} else {
let proto = x;
while(Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto);
}
plain = Object.getPrototypeOf(x) === proto;
}

return !plain &&
(typeof x.constructor === 'function') &&
(x instanceof x.constructor);
};

HTML.isNully = function (node) {
Expand Down

0 comments on commit 4ce1f30

Please sign in to comment.