Comparing version 0.4.3 to 0.4.4
@@ -7,2 +7,5 @@ // Karma configuration | ||
// The WS server is not available with Sauce | ||
config.exclude.push('test/**/WebSocket.spec.js'); | ||
var customLaunchers = { | ||
@@ -9,0 +12,0 @@ 'SL_Chrome': { |
@@ -15,6 +15,8 @@ // Karma configuration | ||
exclude: [ | ||
'test/commonjs.spec.js' | ||
], | ||
reporters: ['progress'], | ||
preprocessors: {}, | ||
//port: 9876, | ||
@@ -21,0 +23,0 @@ colors: true, |
@@ -79,11 +79,11 @@ /* | ||
fork: function (locals) { | ||
var newZone = this._fork(locals); | ||
newZone.constructedAtException = Zone.getStacktrace(); | ||
newZone.constructedAtTime = Date.now(); | ||
return newZone; | ||
}, | ||
_fork: zone.fork | ||
'$fork': function (parentFork) { | ||
return function() { | ||
var newZone = parentFork.apply(this, arguments); | ||
newZone.constructedAtException = Zone.getStacktrace(); | ||
newZone.constructedAtTime = Date.now(); | ||
return newZone; | ||
} | ||
} | ||
}; | ||
{ | ||
"name": "zone.js", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Zones for JavaScript", | ||
@@ -25,2 +25,3 @@ "main": "zone.js", | ||
"karma": "^0.12.31", | ||
"karma-browserify": "^4.1.2", | ||
"karma-chrome-launcher": "^0.1.7", | ||
@@ -27,0 +28,0 @@ "karma-firefox-launcher": "^0.1.4", |
@@ -23,3 +23,3 @@ # Zone.js | ||
```javascript | ||
zone.run(function () { | ||
zone.fork().run(function () { | ||
zone.inTheZone = true; | ||
@@ -26,0 +26,0 @@ |
@@ -5,2 +5,2 @@ // brick does some funny stuff with property descriptors | ||
// this file is intentionally empty; if `lib/brick.js` doesn't error, then we're cool | ||
dump(window.__html__) | ||
console.log(window.__html__) |
@@ -53,2 +53,14 @@ 'use strict'; | ||
}); | ||
it('should honor parent\'s fork()', function () { | ||
zone | ||
.fork({ | ||
'+fork': function() { log.push('fork'); } | ||
}) | ||
.fork(Zone.longStackTraceZone) | ||
.fork(); | ||
expect(log).toEqual(['fork', 'fork']); | ||
}); | ||
}); |
@@ -29,13 +29,16 @@ 'use strict'; | ||
var log = ''; | ||
var logOnClick = function logOnClick () { | ||
var logFunction = function logFunction () { | ||
log += 'a'; | ||
}; | ||
button.addEventListener('click', logOnClick); | ||
button.addEventListener('click', logFunction); | ||
button.addEventListener('focus', logFunction); | ||
button.click(); | ||
expect(log).toEqual('a'); | ||
button.dispatchEvent(new Event('focus')); | ||
expect(log).toEqual('aa'); | ||
button.removeEventListener('click', logOnClick); | ||
button.removeEventListener('click', logFunction); | ||
button.click(); | ||
expect(log).toEqual('a'); | ||
expect(log).toEqual('aa'); | ||
}); | ||
@@ -42,0 +45,0 @@ |
@@ -11,14 +11,20 @@ 'use strict'; | ||
socket.addEventListener('open', done); | ||
socket.addEventListener('error', function() { | ||
fail("Can't establish socket to " + TEST_SERVER_URL + | ||
"! do you have test/ws-server.js running?"); | ||
done(); | ||
}); | ||
}); | ||
afterEach(function () { | ||
afterEach(function (done) { | ||
socket.addEventListener('close', done); | ||
socket.close(); | ||
}); | ||
it('should work with addEventListener', function () { | ||
it('should work with addEventListener', function (done) { | ||
var parent = window.zone; | ||
socket.addEventListener('message', function (contents) { | ||
socket.addEventListener('message', function (event) { | ||
expect(window.zone.parent).toBe(parent); | ||
expect(contents).toBe('HI'); | ||
expect(event.data).toBe('hi'); | ||
done(); | ||
@@ -49,2 +55,3 @@ }); | ||
it('should work with onmessage', function (done) { | ||
@@ -77,3 +84,3 @@ var parent = window.zone; | ||
it('should handle removing onmessage', function () { | ||
it('should handle removing onmessage', function (done) { | ||
var log = ''; | ||
@@ -86,5 +93,9 @@ socket.onmessage = function () { | ||
socket.send('hi'); | ||
expect(log).toEqual(''); | ||
setTimeout(function() { | ||
expect(log).toEqual(''); | ||
done(); | ||
}, 500); | ||
}); | ||
}); |
81
zone.js
@@ -0,4 +1,8 @@ | ||
(function (exports) { | ||
'use strict'; | ||
var zone = null; | ||
function Zone(parentZone, data) { | ||
@@ -82,6 +86,6 @@ var zone = (arguments.length) ? Object.create(parentZone) : this; | ||
var oldZone = window.zone, | ||
var oldZone = zone, | ||
result; | ||
window.zone = this; | ||
exports.zone = zone = this; | ||
@@ -99,3 +103,3 @@ try { | ||
this.afterTask(); | ||
window.zone = oldZone; | ||
exports.zone = zone = oldZone; | ||
} | ||
@@ -105,2 +109,12 @@ return result; | ||
// onError is used to override error handling. | ||
// When a custom error handler is provided, it should most probably rethrow the exception | ||
// not to break the expected control flow: | ||
// | ||
// `promise.then(fnThatThrows).catch(fn);` | ||
// | ||
// When this code is executed in a zone with a custom onError handler that doesn't rethrow, the | ||
// `.catch()` branch will not be taken as the `fnThatThrows` exception will be swallowed by the | ||
// handler. | ||
onError: null, | ||
beforeTask: function () {}, | ||
@@ -332,3 +346,4 @@ onZoneCreated: function () {}, | ||
obj.addEventListener = function (eventName, fn) { | ||
arguments[1] = fn._bound = zone.bind(fn); | ||
fn._bound = fn._bound || {}; | ||
arguments[1] = fn._bound[eventName] = zone.bind(fn); | ||
return addDelegate.apply(this, arguments); | ||
@@ -339,3 +354,7 @@ }; | ||
obj.removeEventListener = function (eventName, fn) { | ||
arguments[1] = arguments[1]._bound || arguments[1]; | ||
if(arguments[1]._bound && arguments[1]._bound[eventName]) { | ||
var _bound = arguments[1]._bound; | ||
arguments[1] = _bound[eventName]; | ||
delete _bound[eventName]; | ||
} | ||
var result = removeDelegate.apply(this, arguments); | ||
@@ -399,4 +418,9 @@ zone.dequeueTask(fn); | ||
if (Zone.canPatchViaPropertyDescriptor()) { | ||
Zone.patchViaPropertyDescriptor(); | ||
// for browsers that we can patch the descriptor: | ||
// - Chrome, Firefox | ||
Zone.patchProperties(HTMLElement.prototype, Zone.onEventNames); | ||
Zone.patchProperties(XMLHttpRequest.prototype); | ||
Zone.patchProperties(WebSocket.prototype); | ||
} else { | ||
// Safari | ||
Zone.patchViaCapturingAllTheEvents(); | ||
@@ -441,9 +465,2 @@ Zone.patchClass('XMLHttpRequest'); | ||
// for browsers that we can patch the descriptor: | ||
// - eventually Chrome once this bug gets resolved | ||
// - Firefox | ||
Zone.patchViaPropertyDescriptor = function () { | ||
Zone.patchProperties(HTMLElement.prototype, Zone.onEventNames); | ||
Zone.patchProperties(XMLHttpRequest.prototype); | ||
}; | ||
@@ -470,11 +487,30 @@ // Whenever any event fires, we check the event target and all parents | ||
// we have to patch the instance since the proto is non-configurable | ||
Zone.patchWebSocket = function() { | ||
var WS = window.WebSocket; | ||
Zone.patchEventTargetMethods(WS.prototype); | ||
window.WebSocket = function(a, b) { | ||
var socket = arguments.length > 1 ? new WS(a, b) : new WS(a); | ||
Zone.patchProperties(socket, ['onclose', 'onerror', 'onmessage', 'onopen']); | ||
return socket; | ||
var proxySocket; | ||
// Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance | ||
var onmessageDesc = Object.getOwnPropertyDescriptor(socket, 'onmessage'); | ||
if (onmessageDesc && onmessageDesc.configurable === false) { | ||
proxySocket = Object.create(socket); | ||
['addEventListener', 'removeEventListener', 'send', 'close'].forEach(function(propName) { | ||
proxySocket[propName] = function() { | ||
return socket[propName].apply(socket, arguments); | ||
}; | ||
}); | ||
} else { | ||
// we can patch the real socket | ||
proxySocket = socket; | ||
} | ||
Zone.patchProperties(proxySocket, ['onclose', 'onerror', 'onmessage', 'onopen']); | ||
return proxySocket; | ||
}; | ||
} | ||
}; | ||
@@ -676,11 +712,14 @@ | ||
Zone.init = function init () { | ||
if (typeof module !== 'undefined' && module && module.exports) { | ||
module.exports = new Zone(); | ||
} else { | ||
window.zone = new Zone(); | ||
} | ||
exports.zone = zone = new Zone(); | ||
Zone.patch(); | ||
}; | ||
if (window.Zone) { | ||
console.warn('Zone already exported on window the object!'); | ||
} | ||
Zone.init(); | ||
exports.Zone = Zone; | ||
}((typeof module !== 'undefined' && module && module.exports) ? | ||
module.exports : window)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
342244
9
45
5749
12