closure 1.1.692 → 1.2.701

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. data/README.md +0 -13
  2. data/closure-library/alltests.js +1 -1
  3. data/closure-library/closure/goog/debug/reflect.js +5 -1
  4. data/closure-library/closure/goog/deps.js +7 -0
  5. data/closure-library/closure/goog/i18n/messageformat.js +4 -1
  6. data/closure-library/closure/goog/i18n/messageformat_test.html +11 -0
  7. data/closure-library/closure/goog/math/vec3.js +0 -19
  8. data/closure-library/closure/goog/messaging/portcaller.js +150 -0
  9. data/closure-library/closure/goog/messaging/portcaller_test.html +66 -0
  10. data/closure-library/closure/goog/messaging/portnetwork.js +78 -0
  11. data/closure-library/closure/goog/messaging/portnetwork_test.html +64 -0
  12. data/closure-library/closure/goog/messaging/portoperator.js +196 -0
  13. data/closure-library/closure/goog/messaging/portoperator_test.html +112 -0
  14. data/closure-library/closure/goog/messaging/testdata/portchannel_inner.html +28 -0
  15. data/closure-library/closure/goog/messaging/testdata/portnetwork_inner.html +35 -0
  16. data/closure-library/closure/goog/messaging/testdata/portnetwork_worker1.js +33 -0
  17. data/closure-library/closure/goog/messaging/testdata/portnetwork_worker2.js +33 -0
  18. data/closure-library/closure/goog/testing/functionmock.js +1 -1
  19. data/closure-library/closure/goog/testing/messaging/mockmessageport.js +85 -0
  20. data/closure-library/closure/goog/testing/messaging/mockportnetwork.js +64 -0
  21. data/closure-library/closure/goog/tweak/tweak.js +1 -1
  22. data/closure-library/closure/goog/ui/advancedtooltip.js +1 -2
  23. data/closure-library/closure/goog/ui/filteredmenu.js +2 -2
  24. data/closure-library/closure/goog/ui/menubutton.js +6 -0
  25. data/closure-library/third_party/closure/goog/dojo/dom/query.js +9 -4
  26. data/closure.gemspec +1 -2
  27. data/config.ru +4 -4
  28. data/lib/closure.rb +3 -1
  29. data/lib/closure/compiler.rb +11 -24
  30. data/lib/closure/goog.rb +37 -16
  31. data/lib/closure/middleware.rb +2 -2
  32. data/lib/closure/script.rb +12 -4
  33. data/lib/closure/server.rb +3 -1
  34. data/lib/closure/show_exceptions.rb +63 -0
  35. data/lib/closure/sources.rb +22 -6
  36. data/lib/closure/templates.rb +2 -2
  37. data/lib/closure/version.rb +1 -1
  38. data/scripts/demos/compiler.build +1 -0
  39. data/scripts/demos/compiler.debug +24 -0
  40. data/scripts/demos/compiler.js.erb +22 -0
  41. data/scripts/demos/compiler.map +114 -0
  42. data/scripts/demos/googly.erb +19 -0
  43. data/scripts/demos/googly.js +24 -0
  44. data/scripts/demos/helloworld.erb +24 -0
  45. data/scripts/demos/index.erb +29 -0
  46. data/scripts/demos/{externs_jquery.js → jquery.js} +0 -0
  47. data/scripts/demos/rails_ujs.erb +38 -0
  48. data/scripts/{examples/rails/ujs.js → demos/rails_ujs.js} +0 -0
  49. data/scripts/externs/jquery-ui.externs +10 -0
  50. data/scripts/externs/jquery.externs +4 -0
  51. data/scripts/{demos/externs_jquery.externs → externs/jquery_1_4_2.externs} +1 -1
  52. data/scripts/index.erb +19 -0
  53. metadata +36 -24
  54. data/scripts/demos/compile.js.erb +0 -8
  55. data/scripts/demos/compile.out +0 -1
  56. data/scripts/demos/compiler.haml +0 -17
  57. data/scripts/demos/compiler.js +0 -12
  58. data/scripts/demos/externs.haml +0 -16
  59. data/scripts/demos/externs.js.erb +0 -8
  60. data/scripts/demos/externs.out +0 -1
  61. data/scripts/demos/externs_jquerytest.js +0 -11
  62. data/scripts/demos/helloworld.haml +0 -15
  63. data/scripts/demos/index.haml +0 -21
  64. data/scripts/demos/rails_ujs.haml +0 -24
  65. data/scripts/favicon.ico +0 -0
  66. data/scripts/index.haml +0 -14
@@ -0,0 +1,196 @@
1
+ // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS-IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ /**
16
+ * @fileoverview The central node of a {@link goog.messaging.PortNetwork}. The
17
+ * operator is responsible for providing the two-way communication channels (via
18
+ * {@link MessageChannel}s) between each pair of nodes in the network that need
19
+ * to communicate with one another. Each network should have one and only one
20
+ * operator.
21
+ *
22
+ */
23
+
24
+ goog.provide('goog.messaging.PortOperator');
25
+
26
+ goog.require('goog.Disposable');
27
+ goog.require('goog.asserts');
28
+ goog.require('goog.debug.Logger');
29
+ goog.require('goog.messaging.PortChannel');
30
+ goog.require('goog.messaging.PortNetwork'); // interface
31
+ goog.require('goog.object');
32
+
33
+
34
+
35
+ /**
36
+ * The central node of a PortNetwork.
37
+ *
38
+ * @param {string} name The name of this node.
39
+ * @constructor
40
+ * @extends {goog.Disposable}
41
+ * @implements {goog.messaging.PortNetwork}
42
+ */
43
+ goog.messaging.PortOperator = function(name) {
44
+ goog.base(this);
45
+
46
+ /**
47
+ * The collection of channels for communicating with other contexts in the
48
+ * network. These are the channels that are returned to the user, as opposed
49
+ * to the channels used for internal network communication. This is lazily
50
+ * populated as the user requests communication with other contexts, or other
51
+ * contexts request communication with the operator.
52
+ *
53
+ * @type {!Object.<!goog.messaging.PortChannel>}
54
+ * @private
55
+ */
56
+ this.connections_ = {};
57
+
58
+ /**
59
+ * The collection of channels for internal network communication with other
60
+ * contexts. This is not lazily populated, and always contains entries for
61
+ * each member of the network.
62
+ *
63
+ * @type {!Object.<!goog.messaging.MessageChannel>}
64
+ * @private
65
+ */
66
+ this.switchboard_ = {};
67
+
68
+ /**
69
+ * The name of the operator context.
70
+ *
71
+ * @type {string}
72
+ * @private
73
+ */
74
+ this.name_ = name;
75
+ };
76
+ goog.inherits(goog.messaging.PortOperator, goog.Disposable);
77
+
78
+
79
+ /**
80
+ * The logger for PortOperator.
81
+ * @type {goog.debug.Logger}
82
+ * @private
83
+ */
84
+ goog.messaging.PortOperator.prototype.logger_ =
85
+ goog.debug.Logger.getLogger('goog.messaging.PortOperator');
86
+
87
+
88
+ /** @inheritDoc */
89
+ goog.messaging.PortOperator.prototype.dial = function(name) {
90
+ this.connectSelfToPort_(name);
91
+ return this.connections_[name];
92
+ };
93
+
94
+
95
+ /**
96
+ * Adds a caller to the network with the given name. This port should have no
97
+ * services registered on it. It will be disposed along with the PortOperator.
98
+ *
99
+ * @param {string} name The name of the port to add.
100
+ * @param {!goog.messaging.MessageChannel} port The port to add. Must be either
101
+ * a {@link goog.messaging.PortChannel} or a decorator wrapping a
102
+ * PortChannel; in particular, it must be able to send and receive
103
+ * {@link MessagePort}s.
104
+ */
105
+ goog.messaging.PortOperator.prototype.addPort = function(name, port) {
106
+ this.switchboard_[name] = port;
107
+ port.registerService(goog.messaging.PortNetwork.REQUEST_CONNECTION_SERVICE,
108
+ goog.bind(this.requestConnection_, this, name));
109
+ };
110
+
111
+
112
+ /**
113
+ * Connects two contexts by creating a {@link MessageChannel} and sending one
114
+ * end to one context and the other end to the other. Called when we receive a
115
+ * request from a caller to connect it to another context (including potentially
116
+ * the operator).
117
+ *
118
+ * @param {string} sourceName The name of the context requesting the connection.
119
+ * @param {string} requestedName The name of the context to which the connection
120
+ * is requested.
121
+ * @private
122
+ */
123
+ goog.messaging.PortOperator.prototype.requestConnection_ = function(
124
+ sourceName, requestedName) {
125
+ if (requestedName == this.name_) {
126
+ this.connectSelfToPort_(sourceName);
127
+ return;
128
+ }
129
+
130
+ var sourceChannel = this.switchboard_[sourceName];
131
+ var requestedChannel = this.switchboard_[requestedName];
132
+
133
+ goog.asserts.assert(goog.isDefAndNotNull(sourceChannel));
134
+ if (!requestedChannel) {
135
+ var err = 'Port "' + sourceName + '" requested a connection to port "' +
136
+ requestedName + '", which doesn\'t exist';
137
+ this.logger_.warning(err);
138
+ sourceChannel.send(goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE,
139
+ {'success': false, 'message': err});
140
+ return;
141
+ }
142
+
143
+ var messageChannel = new MessageChannel();
144
+ sourceChannel.send(goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE, {
145
+ 'success': true,
146
+ 'name': requestedName,
147
+ 'port': messageChannel.port1
148
+ });
149
+ requestedChannel.send(goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE, {
150
+ 'success': true,
151
+ 'name': sourceName,
152
+ 'port': messageChannel.port2
153
+ });
154
+ };
155
+
156
+
157
+ /**
158
+ * Connects together the operator and a caller by creating a
159
+ * {@link MessageChannel} and sending one end to the remote context.
160
+ *
161
+ * @param {string} contextName The name of the context to which to connect the
162
+ * operator.
163
+ * @private
164
+ */
165
+ goog.messaging.PortOperator.prototype.connectSelfToPort_ = function(
166
+ contextName) {
167
+ if (contextName in this.connections_) {
168
+ // We've already established a connection with this port.
169
+ return;
170
+ }
171
+
172
+ var contextChannel = this.switchboard_[contextName];
173
+ if (!contextChannel) {
174
+ throw Error('Port "' + contextName + '" doesn\'t exist');
175
+ }
176
+
177
+ var messageChannel = new MessageChannel();
178
+ contextChannel.send(goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE, {
179
+ 'success': true,
180
+ 'name': this.name_,
181
+ 'port': messageChannel.port1
182
+ });
183
+ messageChannel.port2.start();
184
+ this.connections_[contextName] =
185
+ new goog.messaging.PortChannel(messageChannel.port2);
186
+ };
187
+
188
+
189
+ /** @inheritDoc */
190
+ goog.messaging.PortOperator.prototype.disposeInternal = function() {
191
+ goog.object.forEach(this.switchboard_, goog.dispose);
192
+ goog.object.forEach(this.connections_, goog.dispose);
193
+ delete this.switchboard_;
194
+ delete this.connections_;
195
+ goog.base(this, 'disposeInternal');
196
+ };
@@ -0,0 +1,112 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <!--
4
+ Copyright 2011 The Closure Library Authors. All Rights Reserved.
5
+
6
+ Use of this source code is governed by the Apache License, Version 2.0.
7
+ See the COPYING file for details.
8
+ -->
9
+ <!--
10
+ -->
11
+ <head>
12
+ <title>
13
+ Closure Unit Tests - goog.messaging.PortOperator
14
+ </title>
15
+ <script src="../base.js"></script>
16
+ <script>
17
+ goog.require('goog.events.EventTarget');
18
+ goog.require('goog.messaging.PortChannel');
19
+ goog.require('goog.messaging.PortNetwork');
20
+ goog.require('goog.messaging.PortOperator');
21
+ goog.require('goog.testing.MockControl');
22
+ goog.require('goog.testing.PropertyReplacer');
23
+ goog.require('goog.testing.messaging.MockMessagePort');
24
+ goog.require('goog.testing.jsunit');
25
+ goog.require('goog.testing.messaging.MockMessageChannel');
26
+ </script>
27
+ </head>
28
+ <body>
29
+ <script>
30
+
31
+ var stubs = new goog.testing.PropertyReplacer();
32
+
33
+ var mockControl;
34
+ var mockChannel1;
35
+ var mockChannel2;
36
+ var operator;
37
+
38
+ function setUp() {
39
+ mockControl = new goog.testing.MockControl();
40
+ var index = 0;
41
+ stubs.set(goog.global, 'MessageChannel', function() {
42
+ this.port1 = makeMockPort(index, 1);
43
+ this.port2 = makeMockPort(index, 2);
44
+ index += 1;
45
+ });
46
+
47
+ mockChannel1 = new goog.testing.messaging.MockMessageChannel(mockControl);
48
+ mockChannel2 = new goog.testing.messaging.MockMessageChannel(mockControl);
49
+ operator = new goog.messaging.PortOperator('operator');
50
+ operator.addPort('1', mockChannel1);
51
+ operator.addPort('2', mockChannel2);
52
+ }
53
+
54
+ function tearDown() {
55
+ goog.dispose(operator);
56
+ mockControl.$verifyAll();
57
+ stubs.reset();
58
+ }
59
+
60
+ function makeMockPort(index, port) {
61
+ return new goog.testing.messaging.MockMessagePort(
62
+ {index: index, port: port}, mockControl);
63
+ }
64
+
65
+ function testConnectSelfToPortViaRequestConnection() {
66
+ mockChannel1.send(goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE, {
67
+ success: true, name: 'operator', port: makeMockPort(0, 1)
68
+ });
69
+ mockControl.$replayAll();
70
+ mockChannel1.receive(
71
+ goog.messaging.PortNetwork.REQUEST_CONNECTION_SERVICE, 'operator');
72
+ var port = operator.dial('1').port_;
73
+ assertObjectEquals({index: 0, port: 2}, port.id);
74
+ assertEquals(true, port.started);
75
+ }
76
+
77
+ function testConnectSelfToPortViaGetPort() {
78
+ mockChannel1.send(goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE, {
79
+ success: true, name: 'operator', port: makeMockPort(0, 1)
80
+ });
81
+ mockControl.$replayAll();
82
+ var port = operator.dial('1').port_;
83
+ assertObjectEquals({index: 0, port: 2}, port.id);
84
+ assertEquals(true, port.started);
85
+ }
86
+
87
+ function testConnectTwoCallers() {
88
+ mockChannel1.send(goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE, {
89
+ success: true, name: '2', port: makeMockPort(0, 1)
90
+ });
91
+ mockChannel2.send(goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE, {
92
+ success: true, name: '1', port: makeMockPort(0, 2)
93
+ });
94
+ mockControl.$replayAll();
95
+ mockChannel1.receive(
96
+ goog.messaging.PortNetwork.REQUEST_CONNECTION_SERVICE, '2');
97
+ }
98
+
99
+ function testConnectCallerToNonexistentCaller() {
100
+ mockChannel1.send(goog.messaging.PortNetwork.GRANT_CONNECTION_SERVICE, {
101
+ success: false,
102
+ message: 'Port "1" requested a connection to port "no", which doesn\'t ' +
103
+ 'exist'
104
+ });
105
+ mockControl.$replayAll();
106
+ mockChannel1.receive(
107
+ goog.messaging.PortNetwork.REQUEST_CONNECTION_SERVICE, 'no');
108
+ }
109
+
110
+ </script>
111
+ </body>
112
+ </html>
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <!--
4
+ Copyright 2010 The Closure Library Authors. All Rights Reserved.
5
+
6
+ Use of this source code is governed by the Apache License, Version 2.0.
7
+ See the COPYING file for details.
8
+ -->
9
+ <!--
10
+ -->
11
+ <head>
12
+ <title>PortChannel test inner document</title>
13
+ <script src="../../base.js"></script>
14
+ <script>
15
+ goog.require('goog.messaging.PortChannel');
16
+ </script>
17
+ </head>
18
+ <body>
19
+ <script>
20
+
21
+ var channel = new goog.messaging.PortChannel(self, '*');
22
+ channel.registerService('ping', function(msg) {
23
+ channel.send('pong', msg);
24
+ });
25
+
26
+ </script>
27
+ </body>
28
+ </html>
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <!--
4
+ Copyright 2011 The Closure Library Authors. All Rights Reserved.
5
+
6
+ Use of this source code is governed by the Apache License, Version 2.0.
7
+ See the COPYING file for details.
8
+ -->
9
+ <!--
10
+ -->
11
+ <head>
12
+ <title>
13
+ Closure Unit Tests - goog.messaging.PortNetwork iframe page
14
+ </title>
15
+ <script src="../../base.js"></script>
16
+ <script src="../../../../third_party/closure/goog/deps.js"></script>
17
+ <script>
18
+ goog.require('goog.messaging.PortCaller');
19
+ goog.require('goog.messaging.PortChannel');
20
+ </script>
21
+ </head>
22
+ <body>
23
+ <script>
24
+ var caller = new goog.messaging.PortCaller(
25
+ new goog.messaging.PortChannel(self, '*'));
26
+
27
+ caller.dial('worker2').registerService('sendToWorker1', function(msg) {
28
+ msg.push('frame');
29
+ caller.dial('worker1').send('sendToMain', msg);
30
+ }, true);
31
+
32
+ </script>
33
+ </body>
34
+ </html>
35
+
@@ -0,0 +1,33 @@
1
+ // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2
+
3
+ // Use of this source code is governed by the Apache License, Version 2.0.
4
+ // See the COPYING file for details.
5
+
6
+ /**
7
+ * @fileoverview A web worker for integration testing the PortPool class.
8
+ *
9
+ * @nocompile
10
+ */
11
+
12
+ self.CLOSURE_BASE_PATH = '../../';
13
+ importScripts('../../bootstrap/webworkers.js');
14
+ importScripts('../../base.js');
15
+ importScripts('../../../../third_party/closure/goog/deps.js');
16
+
17
+ // The provide is necessary to stop the jscompiler from thinking this is an
18
+ // entry point and adding it into the manifest incorrectly.
19
+ goog.provide('goog.messaging.testdata.portnetwork_worker1');
20
+ goog.require('goog.messaging.PortCaller');
21
+ goog.require('goog.messaging.PortChannel');
22
+
23
+ function startListening() {
24
+ var caller = new goog.messaging.PortCaller(
25
+ new goog.messaging.PortChannel(self));
26
+
27
+ caller.dial('frame').registerService('sendToMain', function(msg) {
28
+ msg.push('worker1');
29
+ caller.dial('main').send('result', msg);
30
+ }, true);
31
+ }
32
+
33
+ startListening();
@@ -0,0 +1,33 @@
1
+ // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2
+
3
+ // Use of this source code is governed by the Apache License, Version 2.0.
4
+ // See the COPYING file for details.
5
+
6
+ /**
7
+ * @fileoverview A web worker for integration testing the PortPool class.
8
+ *
9
+ * @nocompile
10
+ */
11
+
12
+ self.CLOSURE_BASE_PATH = '../../';
13
+ importScripts('../../bootstrap/webworkers.js');
14
+ importScripts('../../base.js');
15
+ importScripts('../../../../third_party/closure/goog/deps.js');
16
+
17
+ // The provide is necessary to stop the jscompiler from thinking this is an
18
+ // entry point and adding it into the manifest incorrectly.
19
+ goog.provide('goog.messaging.testdata.portnetwork_worker2');
20
+ goog.require('goog.messaging.PortCaller');
21
+ goog.require('goog.messaging.PortChannel');
22
+
23
+ function startListening() {
24
+ var caller = new goog.messaging.PortCaller(
25
+ new goog.messaging.PortChannel(self));
26
+
27
+ caller.dial('main').registerService('sendToFrame', function(msg) {
28
+ msg.push('worker2');
29
+ caller.dial('frame').send('sendToWorker1', msg);
30
+ }, true);
31
+ }
32
+
33
+ startListening();
@@ -75,7 +75,7 @@ goog.testing.MethodMock = function(scope, functionName) {
75
75
 
76
76
  /**
77
77
  * Resets the global function that we mocked back to its original state.
78
- * @this {Function}
78
+ * @this {goog.testing.FunctionMock}
79
79
  */
80
80
  goog.testing.MethodMock.$tearDown = function() {
81
81
  this.$propertyReplacer_.reset();