[Pkg-javascript-commits] [sockjs-client] 03/22: Make the condition on `this` more accurate. In principle it might run in a global context other than window.
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:46 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.
commit ec1632f96675a59fab6d4d3beb2d4594eb5152e8
Author: Michael Bridgen <mikeb at squaremobius.net>
Date: Thu Nov 29 16:42:08 2012 +0000
Make the condition on `this` more accurate. In principle it might run in a global context other than window.
---
lib/sockjs.js | 2 +-
tests/html/src/tests.coffee | 19 ++++++++++++++++---
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/lib/sockjs.js b/lib/sockjs.js
index 6038fee..1e42489 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -7,7 +7,7 @@
*/
var SockJS = function(url, dep_protocols_whitelist, options) {
- if (this === _window) {
+ if (!(this instanceof SockJS)) {
// makes `new` optional
return new SockJS(url, dep_protocols_whitelist, options);
}
diff --git a/tests/html/src/tests.coffee b/tests/html/src/tests.coffee
index 90ef2db..7370210 100644
--- a/tests/html/src/tests.coffee
+++ b/tests/html/src/tests.coffee
@@ -8,18 +8,26 @@ protocols = ['websocket',
'iframe-xhr-polling',
'jsonp-polling']
-newSockJS = (path, protocol) ->
+url_and_options = (path, protocol) ->
url = if /^http/.test(path) then path else client_opts.url + path
options = jQuery.extend({}, client_opts.sockjs_opts)
if protocol
options.protocols_whitelist = [protocol]
+ [url, options]
+
+newSockJS = (path, protocol) ->
+ [url, options] = url_and_options(path, protocol)
return new SockJS(url, null, options)
-echo_factory_factory = (protocol, messages) ->
+cons_without_new = (path, protocol) ->
+ [url, options] = url_and_options(path, protocol)
+ return SockJS(url, null, options)
+
+echo_factory_factory = (protocol, messages, cons = newSockJS) ->
return ->
expect(2 + messages.length)
a = messages.slice(0)
- r = newSockJS('/echo', protocol)
+ r = cons('/echo', protocol)
r.onopen = (e) ->
#log('onopen ' + e)
ok(true)
@@ -47,6 +55,10 @@ echo_factory_factory = (protocol, messages) ->
ok(true)
start()
+factor_echo_without_new = (protocol) ->
+ messages = [ 'data' ]
+ return echo_factory_factory(protocol, messages, cons_without_new)
+
factor_echo_basic = (protocol) ->
messages = [ 'data' ]
return echo_factory_factory(protocol, messages)
@@ -290,6 +302,7 @@ test_protocol_messages = (protocol) ->
test "[disabled by config]", ->
log('Disabled by config: "' + protocol + '"')
else
+ asyncTest("echo0", factor_echo_without_new(protocol))
asyncTest("echo1", factor_echo_basic(protocol))
asyncTest("echo2", factor_echo_rich(protocol))
asyncTest("unicode", factor_echo_unicode(protocol))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git
More information about the Pkg-javascript-commits
mailing list