Skip to content

Commit

Permalink
Merge pull request #386 from canjs/ie11-configurable
Browse files Browse the repository at this point in the history
Ie11 configurable
  • Loading branch information
thomaswilburn committed Sep 17, 2018
2 parents 3fe59b0 + a942593 commit e845796
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
9 changes: 7 additions & 2 deletions can-define.js
Expand Up @@ -46,12 +46,14 @@ if(process.env.NODE_ENV !== 'production') {
if (definition.get) {
Object.defineProperty(definition.get, "name", {
value: "get "+canReflect.getName(obj) + "."+prop,
writable: true
writable: true,
configurable: true
});
}
if (definition.set) {
Object.defineProperty(definition.set, "name", {
value: "set "+canReflect.getName(obj) + "."+prop
value: "set "+canReflect.getName(obj) + "."+prop,
configurable: true
});
}
return Object.defineProperty(obj, prop, definition);
Expand Down Expand Up @@ -271,16 +273,19 @@ define.property = function(typePrototype, prop, definition, dataInitializers, co
if (definition.get) {
Object.defineProperty(definition.get, "name", {
value: canReflect.getName(typePrototype) + "'s " + prop + " getter",
configurable: true
});
}
if (definition.set) {
Object.defineProperty(definition.set, "name", {
value: canReflect.getName(typePrototype) + "'s " + prop + " setter",
configurable: true
});
}
if(isValueResolver(definition)) {
Object.defineProperty(definition.value, "name", {
value: canReflect.getName(typePrototype) + "'s " + prop + " value",
configurable: true
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions list/list.js
Expand Up @@ -341,6 +341,7 @@ var eventsProtoSymbols = ("getOwnPropertySymbols" in Object) ?

eventsProtoSymbols.forEach(function(sym) {
Object.defineProperty(DefineList.prototype, sym, {
configurable: true,
enumerable:false,
value: define.eventsProto[sym],
writable: true
Expand Down Expand Up @@ -705,9 +706,8 @@ var defineListProto = {
var ret;
if(this._computed && this._computed[key] && this._computed[key].compute) {
ret = {};
ret.valueDependencies = new Set([
this._computed[key].compute
]);
ret.valueDependencies = new Set();
ret.valueDependencies.add(this._computed[key].compute);
}
return ret;
},
Expand Down
24 changes: 23 additions & 1 deletion map/map-test.js
Expand Up @@ -1439,6 +1439,28 @@ QUnit.test("expandos use default type (#383)", function(){
});

QUnit.test("do not enumerate anything other than key properties (#369)", function(){
// Internet Explorer doesn't correctly skip properties that are non-enumerable
// on the current object, but enumerable on the prototype:
var ancestor = { prop: true };
var F = function() {};
F.prototype = ancestor;
var descendant = new F();
Object.defineProperty(descendant, "prop", {
writable: true,
configurable: true,
enumerable: false,
value: true
});

var test = {};
for (var k in descendant) {
test[k] = descendant[k];
}
if (test.prop) {
return QUnit.ok(test.prop, "Browser doesn't correctly skip shadowed enumerable properties");
}


var Type = DefineMap.extend({
aProp: "string",
aMethod: function(){}
Expand All @@ -1447,7 +1469,7 @@ QUnit.test("do not enumerate anything other than key properties (#369)", functio
var instance = new Type({aProp: "VALUE", anExpando: "VALUE"});

var props = {};
for(var prop in instance) {
for (var prop in instance) {
props[prop] = true;
}
QUnit.deepEqual(props,{
Expand Down
6 changes: 3 additions & 3 deletions map/map.js
Expand Up @@ -251,9 +251,8 @@ var defineMapProto = {
var ret;
if(this._computed && this._computed[key] && this._computed[key].compute) {
ret = {};
ret.valueDependencies = new Set([
this._computed[key].compute
]);
ret.valueDependencies = new Set();
ret.valueDependencies.add(this._computed[key].compute);
}
return ret;
}
Expand Down Expand Up @@ -290,6 +289,7 @@ var eventsProtoSymbols = ("getOwnPropertySymbols" in Object) ?

eventsProtoSymbols.forEach(function(sym) {
Object.defineProperty(DefineMap.prototype, sym, {
configurable: true,
enumerable:false,
value: define.eventsProto[sym],
writable: true
Expand Down
23 changes: 4 additions & 19 deletions test/test-define-only.js
Expand Up @@ -1216,10 +1216,10 @@ testHelpers.dev.devOnlyTest("Setting a value with only a get() generates a warni
QUnit.equal(finishErrorCheck(), 1);
});

testHelpers.dev.devOnlyTest("warn on using a Constructor for small-t type definintions", function() {
QUnit.expect(2);
testHelpers.dev.devOnlyTest("warn on using a Constructor for small-t type definitions", function() {
QUnit.expect(1);

var message = 'can-define: the definition for VM{}.currency uses a constructor for "type". Did you mean "Type"?';
var message = /can-define: the definition for [\w{}\.]+ uses a constructor for "type"\. Did you mean "Type"\?/;
var finishErrorCheck = testHelpers.dev.willWarn(message);

function Currency() {
Expand All @@ -1241,27 +1241,12 @@ testHelpers.dev.devOnlyTest("warn on using a Constructor for small-t type defini

QUnit.equal(finishErrorCheck(), 1);

message = 'can-define: the definition for VM2{}.currency uses a constructor for "type". Did you mean "Type"?';
finishErrorCheck = testHelpers.dev.willWarn(message);

function VM2() {}

define(VM2.prototype, {
currency: {
type: Currency, // should be `Type: Currency`
default: function() {
return new Currency({});
}
}
});

QUnit.equal(finishErrorCheck(), 1);
});

testHelpers.dev.devOnlyTest("warn with constructor for Value instead of Default (#340)", function() {
QUnit.expect(1);

var message = "can-define: Change the 'Value' definition for VM{}.currency to 'Default'.";
var message = /can-define: Change the 'Value' definition for [\w\.{}]+.currency to 'Default'./;
var finishErrorCheck = testHelpers.dev.willWarn(message);

function Currency() {
Expand Down

0 comments on commit e845796

Please sign in to comment.