Add check for disposed model before setting the property
Check if this._ exists before processing the set operation.
440326: [AutoSuggest] JavaScript Error when setting property of remote
object and destroying it in the same response
https://bugs.eclipse.org/bugs/show_bug.cgi?id=440326
Change-Id: I2d3573d2772b4abab11f303ff9892383d882f681
Signed-off-by: Ivan Furnadjiev <ivan@eclipsesource.com>
diff --git a/bundles/org.eclipse.rap.addons.autosuggest/js/rwt/remote/Model.js b/bundles/org.eclipse.rap.addons.autosuggest/js/rwt/remote/Model.js
index 8b33b5a..89d92d5 100644
--- a/bundles/org.eclipse.rap.addons.autosuggest/js/rwt/remote/Model.js
+++ b/bundles/org.eclipse.rap.addons.autosuggest/js/rwt/remote/Model.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 EclipseSource and others.
+ * Copyright (c) 2013, 2014 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -43,7 +43,7 @@
var property = arguments[ 0 ];
var value = arguments[ 1 ];
var options = arguments[ 2 ] || {};
- if( this._.properties[ property ] !== value ) {
+ if( this._ && this._.properties[ property ] !== value ) {
var event = {
"value" : value,
"type" : "change:" + property,
diff --git a/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/ModelSpec.js b/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/ModelSpec.js
index 32ab3e3..64746e0 100644
--- a/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/ModelSpec.js
+++ b/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/ModelSpec.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 EclipseSource and others.
+ * Copyright (c) 2013, 2014 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -177,6 +177,24 @@
expect( rap.fakeRemoteObject.notify ).not.toHaveBeenCalled();
} );
+ it( "does not notify change listener with disposed model", function() {
+ model.addListener( "change:foo", logger );
+ model.destroy();
+
+ model.set( "foo", 23 );
+
+ expect( log.length ).toBe( 0 );
+ } );
+
+ it( "does not call notify on remoteObject with disposed model", function() {
+ spyOn( rap.fakeRemoteObject, "notify" );
+ model.destroy();
+
+ model.set( "foo", 23 );
+
+ expect( rap.fakeRemoteObject.notify ).not.toHaveBeenCalled();
+ } );
+
} );
describe( "destroy", function() {