Do not create remote objects for Script class if not required
diff --git a/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ListenerAdapter.js b/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ListenerAdapter.js
index cb7e9eb..d76cc3b 100644
--- a/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ListenerAdapter.js
+++ b/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ListenerAdapter.js
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012 EclipseSource and others.
+ * Copyright (c) 2012, 2013 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
@@ -12,8 +12,11 @@
 rwt.remote.HandlerRegistry.add( "rwt.clientscripting.Listener", {
 
   factory : function( properties ) {
-    var script = rap.getObject( properties.script );
-    return new org.eclipse.rap.clientscripting.Function( script.getText() );
+    var scriptCode = properties.scriptCode;
+    if( !scriptCode ) {
+      scriptCode = rap.getObject( properties.scriptId ).getText();
+    }
+    return new org.eclipse.rap.clientscripting.Function( scriptCode );
   }
 
 } );
diff --git a/bundles/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/ClientFunction.java b/bundles/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/ClientFunction.java
index 15708d5..0e7d049 100644
--- a/bundles/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/ClientFunction.java
+++ b/bundles/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/ClientFunction.java
@@ -27,17 +27,25 @@
   private final Collection<ClientListenerBinding> bindings;
 
   public ClientFunction( String scriptCode ) {
-    this( new Script( scriptCode ) );
+    this();
+    if( scriptCode == null ) {
+      throw new NullPointerException( "Parameter is null: scriptCode" );
+    }
+    remoteObject.set( "scriptCode", scriptCode );
   }
 
   public ClientFunction( Script script ) {
+    this();
     if( script == null ) {
       throw new NullPointerException( "Parameter is null: script" );
     }
-    ClientScriptingResources.ensure();
+    remoteObject.set( "scriptId", script.getId() );
+  }
+
+  private ClientFunction() {
     bindings = new ArrayList<ClientListenerBinding>();
     remoteObject = RWT.getUISession().getConnection().createRemoteObject( REMOTE_TYPE );
-    remoteObject.set( "script", script.getId() );
+    ClientScriptingResources.ensure();
   }
 
   protected String getRemoteId() {
diff --git a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventBinding_Test.js b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventBinding_Test.js
index c994498..af324de 100644
--- a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventBinding_Test.js
+++ b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventBinding_Test.js
@@ -30,14 +30,12 @@
 
     testCreateBindingByProtocol : function() {
       var code = "var handleEvent = function(){};";
-      var createScript = [ "create", "r3", "rwt.clientscripting.Script", { "text" : code } ];
-      Processor.processOperationArray( createScript );
       Processor.processOperation( {
         "target" : "w4",
         "action" : "create",
         "type" : "rwt.clientscripting.Listener",
         "properties" : {
-          "script" : "r3"
+          "scriptCode" : code
         }
       } );
 
diff --git a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/Function_Test.js b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/Function_Test.js
index 54f7591..bfc697a 100644
--- a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/Function_Test.js
+++ b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/Function_Test.js
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012 EclipseSource and others.
+ * Copyright (c) 2012, 2013 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
@@ -63,6 +63,24 @@
       var ObjectManager = rwt.remote.ObjectRegistry;
       var processor = rwt.remote.MessageProcessor;
       var code = "var handleEvent = function(){};";
+
+      processor.processOperation( {
+        "target" : "w3",
+        "action" : "create",
+        "type" : "rwt.clientscripting.Listener",
+        "properties" : {
+          "scriptCode" : code
+        }
+      } );
+
+      var result = ObjectManager.getObject( "w3" );
+      assertTrue( result instanceof Function );
+    },
+
+    testCreateFunctionByProtocol_withScriptId : function() {
+      var ObjectManager = rwt.remote.ObjectRegistry;
+      var processor = rwt.remote.MessageProcessor;
+      var code = "var handleEvent = function(){};";
       var createScript = [ "create", "r3", "rwt.clientscripting.Script", { "text" : code } ];
       processor.processOperationArray( createScript );
 
@@ -71,7 +89,7 @@
         "action" : "create",
         "type" : "rwt.clientscripting.Listener",
         "properties" : {
-          "script" : "r3"
+          "scriptId" : "r3"
         }
       } );
 
diff --git a/tests/org.eclipse.rap.clientscripting.test/src/org/eclipse/rap/clientscripting/internal/ClientFunction_Test.java b/tests/org.eclipse.rap.clientscripting.test/src/org/eclipse/rap/clientscripting/internal/ClientFunction_Test.java
index 581b763..0c9cff2 100644
--- a/tests/org.eclipse.rap.clientscripting.test/src/org/eclipse/rap/clientscripting/internal/ClientFunction_Test.java
+++ b/tests/org.eclipse.rap.clientscripting.test/src/org/eclipse/rap/clientscripting/internal/ClientFunction_Test.java
@@ -49,7 +49,6 @@
     Fixture.tearDown();
   }
 
-  @SuppressWarnings( "deprecation" )
   @Test
   public void testCreation_failsWithStringNull() {
     try {
@@ -80,7 +79,7 @@
   }
 
   @Test
-  public void testCreationWithString_initializesRemoteObject() {
+  public void testCreationWithString_sendsString() {
     RemoteObject listenerRemoteObject = mock( RemoteObject.class );
     RemoteObject scriptRemoteObject = mock( RemoteObject.class );
     Connection connection = mock( Connection.class );
@@ -90,9 +89,9 @@
     when( scriptRemoteObject.getId() ).thenReturn( "fooId" );
     Fixture.fakeConnection( connection );
 
-    new ClientFunction( new Script( "script code" ) );
+    new ClientFunction( "my script code" );
 
-    verify( listenerRemoteObject ).set( eq( "script" ), eq( "fooId" ) );
+    verify( listenerRemoteObject ).set( eq( "scriptCode" ), eq( "my script code" ) );
   }
 
   @Test
@@ -104,7 +103,7 @@
 
     new ClientFunction( script );
 
-    verify( listenerRemoteObject ).set( eq( "script" ), eq( "fooId" ) );
+    verify( listenerRemoteObject ).set( eq( "scriptId" ), eq( "fooId" ) );
   }
 
   @Test