From 3bf43ab2d356797b6607ca91e3d899d442b36673 Mon Sep 17 00:00:00 2001 From: bgando Date: Thu, 31 Aug 2017 12:49:07 -0400 Subject: [PATCH] Update to give warning if value is set to a constructor --- can-define.js | 6 +++--- map/map-test.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/can-define.js b/can-define.js index 9cd0cc5..0a590a4 100644 --- a/can-define.js +++ b/can-define.js @@ -239,9 +239,9 @@ define.property = function(objPrototype, prop, definition, dataInitializers, com if ((definition.value !== undefined || definition.Value !== undefined)) { //!steal-remove-start - // If value is an object or array, give a warning - if (definition.value !== null && typeof definition.value === 'object') { - dev.warn("can-define: The value for options is set to an object. This will be shared by all instances of the DefineMap. Use a function that returns the object instead."); + // If value is an object, array, or constructor give a warning + if (definition.value !== null && (typeof definition.value === 'object' || canReflect.isConstructorLike(definition.value || {}))) { + dev.warn("can-define: The value for " + prop + " is set to an object or constructor. Use a function or primitive instead."); } //!steal-remove-end getInitialValue = Observation.ignore(make.get.defaultValue(prop, definition, typeConvert, eventsSetter)); diff --git a/map/map-test.js b/map/map-test.js index a01d2cf..d3a0eb2 100644 --- a/map/map-test.js +++ b/map/map-test.js @@ -839,11 +839,11 @@ QUnit.test("non-Object constructor", function() { }); if(System.env.indexOf("production") < 0) { - QUnit.test('Setting a value with an object type generates a warning (#148)', function() { + QUnit.test('Setting a value with an object or constructor type generates a warning (#148)', function() { QUnit.expect(2); var oldwarn = canDev.warn; canDev.warn = function(mesg) { - QUnit.equal(mesg, "can-define: The value for options is set to an object. This will be shared by all instances of the DefineMap. Use a function that returns the object instead."); + QUnit.equal(mesg, "can-define: The value for options is set to an object or constructor. Use a function or primitive instead."); }; //should issue a warning DefineMap.extend({ @@ -854,7 +854,7 @@ if(System.env.indexOf("production") < 0) { //should issue a warning DefineMap.extend({ options: { - value: [] + value: DefineMap } });