From af2341363fd7361c3ef15725b50876bef5f37b2d Mon Sep 17 00:00:00 2001 From: brucejo Date: Mon, 11 Dec 2017 05:27:14 -0800 Subject: [PATCH 1/4] Fix HTML.isArray to work across frames. --- packages/htmljs/html.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/htmljs/html.js b/packages/htmljs/html.js index ce758772d..913e95d63 100644 --- a/packages/htmljs/html.js +++ b/packages/htmljs/html.js @@ -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) { From e503814f6f936f05cdf3b35899cd16a85c91415c Mon Sep 17 00:00:00 2001 From: brucejo Date: Wed, 20 Dec 2017 16:32:52 -0800 Subject: [PATCH 2/4] Use HTML.isArray where appropriate. --- packages/blaze/builtins.js | 2 +- packages/html-tools/parse.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/blaze/builtins.js b/packages/blaze/builtins.js index 18e165c09..21fcd21eb 100644 --- a/packages/blaze/builtins.js +++ b/packages/blaze/builtins.js @@ -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; }; diff --git a/packages/html-tools/parse.js b/packages/html-tools/parse.js index 109e9fa2f..7b3296327 100644 --- a/packages/html-tools/parse.js +++ b/packages/html-tools/parse.js @@ -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( From e0f4b56320963e65723ac3bae50cbce4c183725b Mon Sep 17 00:00:00 2001 From: brucejo Date: Wed, 20 Dec 2017 16:34:13 -0800 Subject: [PATCH 3/4] use lodash.isPlainObject technique to determine if object is a plain object. --- packages/htmljs/html.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/htmljs/html.js b/packages/htmljs/html.js index 913e95d63..f1141a239 100644 --- a/packages/htmljs/html.js +++ b/packages/htmljs/html.js @@ -182,10 +182,16 @@ 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 proto = x; + while(Object.getPrototypeOf(proto) !== null) { + proto = Object.getPrototypeOf(proto); + } + let plain = Object.getPrototypeOf(x) === proto; + return !plain && + (typeof x.constructor === 'function') && + (x instanceof x.constructor); }; HTML.isNully = function (node) { From 2acf08c4ffa26b4048d67a58dff107a37d1a5549 Mon Sep 17 00:00:00 2001 From: brucejo Date: Wed, 20 Dec 2017 16:56:43 -0800 Subject: [PATCH 4/4] Added one other case... --- packages/htmljs/html.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/htmljs/html.js b/packages/htmljs/html.js index f1141a239..55c8adac2 100644 --- a/packages/htmljs/html.js +++ b/packages/htmljs/html.js @@ -184,11 +184,17 @@ HTML.isConstructedObject = function (x) { // `(new Foo).constructor` is `Object`, not `Foo`). if(!x || (typeof x !== 'object')) return false; // Is this a plain object? - let proto = x; - while(Object.getPrototypeOf(proto) !== null) { - proto = Object.getPrototypeOf(proto); + 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; } - let plain = Object.getPrototypeOf(x) === proto; + return !plain && (typeof x.constructor === 'function') && (x instanceof x.constructor);