Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dist/knockout-es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@
return;
}

if (!obj.hasOwnProperty(prop)) {
throw new Error('Property \'' + prop + '\' does not exist on the object to be tracked');
}

// Skip properties where descriptor can't be redefined
if (Object.getOwnPropertyDescriptor(obj, prop).configurable === false){
return;
Expand Down
4 changes: 2 additions & 2 deletions dist/knockout-es5.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ return d[c]=function(){return g},(f||e&&"push"in g)&&m(w,g),{configurable:!0,enu
// no need to be lazy if we already have an observable
return f(a,b,c);var e;return c[b]=function(){return d(a)},{configurable:!0,enumerable:!0,get:function(){return d(a)()},set:function(a){d(a,!0)}}}function h(a,b,c){if(b.length){var d=j(a,!0),i={};b.forEach(function(b){
// Skip properties that are already tracked
if(!(b in d)&&Object.getOwnPropertyDescriptor(a,b).configurable!==!1)
if(!(b in d)){if(!a.hasOwnProperty(b))throw new Error("Property '"+b+"' does not exist on the object to be tracked");
// Skip properties where descriptor can't be redefined
{var j=a[b];i[b]=(c.lazy?g:f)(j,b,d),c.deep&&e(j)&&h(j,Object.keys(j),c)}}),Object.defineProperties(a,i)}}function i(a){return!!a&&"object"==typeof a&&a.constructor===Object}
if(Object.getOwnPropertyDescriptor(a,b).configurable!==!1){var j=a[b];i[b]=(c.lazy?g:f)(j,b,d),c.deep&&e(j)&&h(j,Object.keys(j),c)}}}),Object.defineProperties(a,i)}}function i(a){return!!a&&"object"==typeof a&&a.constructor===Object}
// Gets or creates the hidden internal key-value collection of observables corresponding to
// properties on the model object.
function j(a,b){x||(x=z());var c=x.get(a);return!c&&b&&(c={},x.set(a,c)),c}
Expand Down
4 changes: 4 additions & 0 deletions src/knockout-es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@
return;
}

if (!obj.hasOwnProperty(prop)) {
throw new Error('Property \'' + prop + '\' does not exist on the object to be tracked');
}

// Skip properties where descriptor can't be redefined
if (Object.getOwnPropertyDescriptor(obj, prop).configurable === false){
return;
Expand Down
6 changes: 6 additions & 0 deletions test/basic-properties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ describe('Basic properties', function () {
assert.strictEqual( result, true, result.message );
});

it('throws if a property name does not exist on the object', function () {
assert.throw(function() {
ko.track({a: 1, b: 2}, ['a', 'z']);
}, 'Property \'z\' does not exist on the object to be tracked');
});

it('retains existing observable properties, wrapping them in a getter/setter', function() {
var observable = ko.observable(123),
obj = ko.track({ prop: observable });
Expand Down