|
"use strict"; |
|
|
|
if (typeof QUnit === 'undefined') { |
|
var assert = require("assert"); |
|
|
|
global.test = function(name, callback) { |
|
assert.doesNotThrow(callback); |
|
}; |
|
|
|
global.equal = assert.equal; |
|
global.ok = assert.ok; |
|
} |
|
|
|
test('Frozen prototype with string property only', function() { |
|
|
|
var Clazz = function() { |
|
this.prop1 = 'instance'; |
|
}; |
|
|
|
Clazz.prototype.prop1 = 'initial'; |
|
Object.freeze(Clazz.prototype); |
|
|
|
var instance = new Clazz(); |
|
ok(Object.isExtensible(instance), "instance should be extensible"); |
|
ok(!Object.isExtensible(Clazz.prototype), "prototype should not be extensible"); |
|
equal(false, Object.getOwnPropertyDescriptor(Clazz.prototype, 'prop1').writable, "prototype property 'prop1' should not be writable"); |
|
equal(true, instance.hasOwnProperty('prop1'), "instance should have own property 'prop1'"); |
|
equal(true, Object.getOwnPropertyDescriptor(instance, 'prop1').writable, "instance property 'prop1' should be writable"); |
|
equal('instance', instance.prop1); |
|
|
|
}); |
|
|
|
test('Frozen prototype with function property, set to string in instance', function() { |
|
var Clazz = function() { |
|
this.prop1 = 'instance'; |
|
}; |
|
|
|
Clazz.prototype.prop1 = function() { return 'initial'; }; |
|
Object.freeze(Clazz.prototype); |
|
|
|
var instance = new Clazz(); |
|
equal('instance', instance.prop1); |
|
|
|
}); |
|
|
|
test('Frozen prototype with two function properties, set both to strings in instance', function() { |
|
var Clazz = function() { |
|
this.prop1 = 'instance'; |
|
this.prop2 = 'instance'; |
|
}; |
|
|
|
Clazz.prototype.prop1 = function() { return 'initial'; }; |
|
Clazz.prototype.prop2 = function() { return 'initial'; }; |
|
Object.freeze(Clazz.prototype); |
|
|
|
var instance = new Clazz(); |
|
equal('instance', instance.prop1); |
|
equal('instance', instance.prop2); |
|
|
|
}); |
|
|
|
test('Frozen prototype with two function properties, set to string and function in instance via Object.defineProperty()', function() { |
|
var Clazz = function() { |
|
Object.defineProperty(this, 'prop1', { value: 'instance', enumerable: true, writable: true }); |
|
Object.defineProperty(this, 'prop2', { value: function() { return 'instance'; }, enumerable: true, writable: true }); |
|
}; |
|
|
|
Clazz.prototype.prop1 = function() { return 'initial'; }; |
|
Clazz.prototype.prop2 = function() { return 'initial'; }; |
|
Object.freeze(Clazz.prototype); |
|
|
|
var instance = new Clazz(); |
|
equal('instance', instance.prop1); |
|
equal('instance', instance.prop2()); |
|
|
|
}); |
|
|
|
test('Frozen prototype with two function properties, set to string and function in instance via assignment', function() { |
|
var Clazz = function() { |
|
this.prop1 = 'instance'; |
|
this.prop2 = function() { return 'instance'; }; |
|
}; |
|
|
|
Clazz.prototype.prop1 = function() { return 'initial'; }; |
|
Clazz.prototype.prop2 = function() { return 'initial'; }; |
|
Object.freeze(Clazz.prototype); |
|
|
|
var instance = new Clazz(); |
|
equal('instance', instance.prop1); |
|
equal('instance', instance.prop2()); |
|
|
|
}); |
|
|
|
test('Frozen prototype with single function property, set to function in instance via assignment', function() { |
|
var Clazz = function() { |
|
this.prop1 = function() { return 'instance'; }; |
|
}; |
|
|
|
Clazz.prototype.prop1 = function() { return 'initial'; }; |
|
Object.freeze(Clazz.prototype); |
|
|
|
var instance = new Clazz(); |
|
equal('instance', instance.prop1()); |
|
|
|
}); |
|
|