Skip to content

Commit

Permalink
merge master into opbeat-zone
Browse files Browse the repository at this point in the history
  • Loading branch information
hmdhk committed Jun 13, 2017
2 parents d18e2c2 + 3511159 commit 33a12ad
Show file tree
Hide file tree
Showing 31 changed files with 439 additions and 54 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
<a name="0.8.12"></a>
## [0.8.12](https://github.com/angular/zone.js/compare/v0.8.11...0.8.12) (2017-06-07)


### Bug Fixes

* **doc:** fix [#793](https://github.com/angular/zone.js/issues/793), fix confuseing bluebird patch doc ([#794](https://github.com/angular/zone.js/issues/794)) ([0c5da04](https://github.com/angular/zone.js/commit/0c5da04))
* **patch:** fix [#791](https://github.com/angular/zone.js/issues/791), fix mediaQuery/Notification patch uses wrong global ([#792](https://github.com/angular/zone.js/issues/792)) ([67634ae](https://github.com/angular/zone.js/commit/67634ae))
* **toString:** fix [#802](https://github.com/angular/zone.js/issues/802), fix ios 9 MutationObserver toString error ([#803](https://github.com/angular/zone.js/issues/803)) ([68aa03e](https://github.com/angular/zone.js/commit/68aa03e))
* **xhr:** inner onreadystatechange should not triigger Zone callback ([#800](https://github.com/angular/zone.js/issues/800)) ([7bd1418](https://github.com/angular/zone.js/commit/7bd1418))


### Features

* **patch:** fix [#696](https://github.com/angular/zone.js/issues/696), patch HTMLCanvasElement.toBlob as MacroTask ([#788](https://github.com/angular/zone.js/issues/788)) ([7ca3995](https://github.com/angular/zone.js/commit/7ca3995))
* **patch:** fix [#758](https://github.com/angular/zone.js/issues/758), patch cordova.exec success/error with zone.wrap ([#789](https://github.com/angular/zone.js/issues/789)) ([857929d](https://github.com/angular/zone.js/commit/857929d))



<a name="0.8.11"></a>
## [0.8.11](https://github.com/angular/zone.js/compare/v0.8.10...0.8.11) (2017-05-19)

Expand Down
31 changes: 28 additions & 3 deletions NON-STANDARD-APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ Browser Usage:

After those steps, window.Promise will become a ZoneAware Bluebird Promise.

Node Usage:
Node Sample Usage:

```
require('zone-node.js');
require('zone.js');
const Bluebird = require('bluebird');
require('zone-bluebird.js');
require('zone.js/dist/zone-bluebird');
Zone[Zone['__symbol__']('bluebird')](Bluebird);
Zone.current.fork({
name: 'bluebird'
}).run(() => {
Bluebird.resolve(1).then(r => {
console.log('result ', r, 'Zone', Zone.current.name);
});
});
```

In NodeJS environment, you can choose to use Bluebird Promise as global.Promise
Expand All @@ -67,6 +74,24 @@ remove the comment of the following line
//import './extra/bluebird.spec';
```

## Others

* Cordova

patch `cordova.exec` API

`cordova.exec(success, error, service, action, args);`

`success` and `error` will be patched with `Zone.wrap`.

to load the patch, you should load in the following order.

```
<script src="zone.js"></script>
<script src="cordova.js"></script>
<script src="zone-patch-cordova.js"></script>
```

## Usage

By default, those APIs' support will not be loaded in zone.js or zone-node.js,
Expand Down
2 changes: 1 addition & 1 deletion dist/webapis-media-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Zone.__load_patch('mediaQuery', function (global, Zone, api) {
if (!global['MediaQueryList']) {
return;
}
api.patchEventTargetMethods(_global['MediaQueryList'].prototype, 'addListener', 'removeListener', function (self, args) {
api.patchEventTargetMethods(global['MediaQueryList'].prototype, 'addListener', 'removeListener', function (self, args) {
return {
useCapturing: false,
eventName: 'mediaQuery',
Expand Down
2 changes: 1 addition & 1 deletion dist/webapis-media-query.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/webapis-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* found in the LICENSE file at https://angular.io/license
*/
Zone.__load_patch('notification', function (global, Zone, api) {
var Notification = _global['Notification'];
var Notification = global['Notification'];
if (!Notification || !Notification.prototype) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/webapis-notification.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 24 additions & 5 deletions dist/zone-mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ var Zone$1 = (function (global) {
scheduleMicroTask: scheduleMicroTask,
showUncaughtError: function () { return !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; },
patchEventTargetMethods: function () { return false; },
patchOnProperties: noop
patchOnProperties: noop,
patchMethod: function () { return noop; }
};
var _currentZoneFrame = { parent: null, zone: new Zone(null, null) };
var _currentTask = null;
Expand Down Expand Up @@ -1556,8 +1557,14 @@ Zone.__load_patch('toString', function (global, Zone, api) {
var originalFunctionToString = Function.prototype.toString;
Function.prototype.toString = function () {
if (typeof this === 'function') {
if (this[zoneSymbol('OriginalDelegate')]) {
return originalFunctionToString.apply(this[zoneSymbol('OriginalDelegate')], arguments);
var originalDelegate = this[zoneSymbol('OriginalDelegate')];
if (originalDelegate) {
if (typeof originalDelegate === 'function') {
return originalFunctionToString.apply(this[zoneSymbol('OriginalDelegate')], arguments);
}
else {
return Object.prototype.toString.call(originalDelegate);
}
}
if (this === Promise) {
var nativePromise = global[zoneSymbol('Promise')];
Expand Down Expand Up @@ -2278,6 +2285,15 @@ Zone.__load_patch('on_property', function (global, Zone, api) {
propertyPatch();
registerElementPatch(global);
});
Zone.__load_patch('canvas', function (global, Zone, api) {
var HTMLCanvasElement = global['HTMLCanvasElement'];
if (typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement.prototype &&
HTMLCanvasElement.prototype.toBlob) {
patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', function (self, args) {
return { name: 'HTMLCanvasElement.toBlob', target: self, callbackIndex: 0, args: args };
});
}
});
Zone.__load_patch('XHR', function (global, Zone, api) {
// Treat XMLHTTPRequest as a macrotask.
patchXHR(global);
Expand All @@ -2295,8 +2311,10 @@ Zone.__load_patch('XHR', function (global, Zone, api) {
var data = task.data;
// remove existing event listener
var listener = data.target[XHR_LISTENER];
var oriAddListener = data.target[zoneSymbol('addEventListener')];
var oriRemoveListener = data.target[zoneSymbol('removeEventListener')];
if (listener) {
data.target.removeEventListener('readystatechange', listener);
oriRemoveListener.apply(data.target, ['readystatechange', listener]);
}
var newListener = data.target[XHR_LISTENER] = function () {
if (data.target.readyState === data.target.DONE) {
Expand All @@ -2308,7 +2326,7 @@ Zone.__load_patch('XHR', function (global, Zone, api) {
}
}
};
data.target.addEventListener('readystatechange', newListener);
oriAddListener.apply(data.target, ['readystatechange', newListener]);
var storedTask = data.target[XHR_TASK];
if (!storedTask) {
data.target[XHR_TASK] = task;
Expand Down Expand Up @@ -2390,6 +2408,7 @@ Zone.__load_patch('PromiseRejectionEvent', function (global, Zone, api) {
Zone.__load_patch('util', function (global, Zone, api) {
api.patchEventTargetMethods = patchEventTargetMethods;
api.patchOnProperties = patchOnProperties;
api.patchMethod = patchMethod;
});

/**
Expand Down
13 changes: 10 additions & 3 deletions dist/zone-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ var Zone$1 = (function (global) {
scheduleMicroTask: scheduleMicroTask,
showUncaughtError: function () { return !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; },
patchEventTargetMethods: function () { return false; },
patchOnProperties: noop
patchOnProperties: noop,
patchMethod: function () { return noop; }
};
var _currentZoneFrame = { parent: null, zone: new Zone(null, null) };
var _currentTask = null;
Expand Down Expand Up @@ -1342,8 +1343,14 @@ Zone.__load_patch('toString', function (global, Zone, api) {
var originalFunctionToString = Function.prototype.toString;
Function.prototype.toString = function () {
if (typeof this === 'function') {
if (this[zoneSymbol('OriginalDelegate')]) {
return originalFunctionToString.apply(this[zoneSymbol('OriginalDelegate')], arguments);
var originalDelegate = this[zoneSymbol('OriginalDelegate')];
if (originalDelegate) {
if (typeof originalDelegate === 'function') {
return originalFunctionToString.apply(this[zoneSymbol('OriginalDelegate')], arguments);
}
else {
return Object.prototype.toString.call(originalDelegate);
}
}
if (this === Promise) {
var nativePromise = global[zoneSymbol('Promise')];
Expand Down
35 changes: 35 additions & 0 deletions dist/zone-patch-cordova.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
Zone.__load_patch('cordova', function (global, Zone, api) {
if (global.cordova) {
var nativeExec_1 = api.patchMethod(global.cordova, 'exec', function (delegate) { return function (self, args) {
if (args.length > 0 && typeof args[0] === 'function') {
args[0] = Zone.current.wrap(args[0], 'cordova.exec.success');
}
if (args.length > 1 && typeof args[1] === 'function') {
args[1] = Zone.current.wrap(args[1], 'cordova.exec.error');
}
return nativeExec_1.apply(self, args);
}; });
}
});

})));
1 change: 1 addition & 0 deletions dist/zone-patch-cordova.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 46 additions & 6 deletions dist/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ var Zone$1 = (function (global) {
scheduleMicroTask: scheduleMicroTask,
showUncaughtError: function () { return !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; },
patchEventTargetMethods: function () { return false; },
patchOnProperties: noop
patchOnProperties: noop,
patchMethod: function () { return noop; }
};
var _currentZoneFrame = { parent: null, zone: new Zone(null, null) };
var _currentTask = null;
Expand Down Expand Up @@ -1429,7 +1430,28 @@ function patchMethod(target, name, patchFn) {
return delegate;
}
// TODO: @JiaLiPassion, support cancel task later if necessary

function patchMacroTask(obj, funcName, metaCreator) {
var setNative = null;
function scheduleTask(task) {
var data = task.data;
data.args[data.callbackIndex] = function () {
task.invoke.apply(this, arguments);
};
setNative.apply(data.target, data.args);
return task;
}
setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
var meta = metaCreator(self, args);
if (meta.callbackIndex >= 0 && typeof args[meta.callbackIndex] === 'function') {
var task = Zone.current.scheduleMacroTask(meta.name, args[meta.callbackIndex], meta, scheduleTask, null);
return task;
}
else {
// cause an error by calling it directly.
return delegate.apply(self, args);
}
}; });
}

function findEventTask(target, evtName) {
var eventTasks = target[zoneSymbol('eventTasks')];
Expand Down Expand Up @@ -1464,8 +1486,14 @@ Zone.__load_patch('toString', function (global, Zone, api) {
var originalFunctionToString = Function.prototype.toString;
Function.prototype.toString = function () {
if (typeof this === 'function') {
if (this[zoneSymbol('OriginalDelegate')]) {
return originalFunctionToString.apply(this[zoneSymbol('OriginalDelegate')], arguments);
var originalDelegate = this[zoneSymbol('OriginalDelegate')];
if (originalDelegate) {
if (typeof originalDelegate === 'function') {
return originalFunctionToString.apply(this[zoneSymbol('OriginalDelegate')], arguments);
}
else {
return Object.prototype.toString.call(originalDelegate);
}
}
if (this === Promise) {
var nativePromise = global[zoneSymbol('Promise')];
Expand Down Expand Up @@ -2186,6 +2214,15 @@ Zone.__load_patch('on_property', function (global, Zone, api) {
propertyPatch();
registerElementPatch(global);
});
Zone.__load_patch('canvas', function (global, Zone, api) {
var HTMLCanvasElement = global['HTMLCanvasElement'];
if (typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement.prototype &&
HTMLCanvasElement.prototype.toBlob) {
patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', function (self, args) {
return { name: 'HTMLCanvasElement.toBlob', target: self, callbackIndex: 0, args: args };
});
}
});
Zone.__load_patch('XHR', function (global, Zone, api) {
// Treat XMLHTTPRequest as a macrotask.
patchXHR(global);
Expand All @@ -2203,8 +2240,10 @@ Zone.__load_patch('XHR', function (global, Zone, api) {
var data = task.data;
// remove existing event listener
var listener = data.target[XHR_LISTENER];
var oriAddListener = data.target[zoneSymbol('addEventListener')];
var oriRemoveListener = data.target[zoneSymbol('removeEventListener')];
if (listener) {
data.target.removeEventListener('readystatechange', listener);
oriRemoveListener.apply(data.target, ['readystatechange', listener]);
}
var newListener = data.target[XHR_LISTENER] = function () {
if (data.target.readyState === data.target.DONE) {
Expand All @@ -2216,7 +2255,7 @@ Zone.__load_patch('XHR', function (global, Zone, api) {
}
}
};
data.target.addEventListener('readystatechange', newListener);
oriAddListener.apply(data.target, ['readystatechange', newListener]);
var storedTask = data.target[XHR_TASK];
if (!storedTask) {
data.target[XHR_TASK] = task;
Expand Down Expand Up @@ -2298,6 +2337,7 @@ Zone.__load_patch('PromiseRejectionEvent', function (global, Zone, api) {
Zone.__load_patch('util', function (global, Zone, api) {
api.patchEventTargetMethods = patchEventTargetMethods;
api.patchOnProperties = patchOnProperties;
api.patchMethod = patchMethod;
});

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/zone.min.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ gulp.task('build/webapis-shadydom.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/shadydom.ts', 'webapis-shadydom.min.js', true, cb);
});

gulp.task('build/zone-patch-cordova.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/cordova.ts', 'zone-patch-cordova.js', false, cb);
});

gulp.task('build/zone-patch-cordova.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/cordova.ts', 'zone-patch-cordova.min.js', true, cb);
});

gulp.task('build/bluebird.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/bluebird.ts', 'zone-bluebird.js', false, cb);
});
Expand Down Expand Up @@ -204,6 +212,8 @@ gulp.task('build', [
'build/webapis-notification.min.js',
'build/webapis-shadydom.js',
'build/webapis-shadydom.min.js',
'build/zone-patch-cordova.js',
'build/zone-patch-cordova.min.js',
'build/zone-mix.js',
'build/bluebird.js',
'build/bluebird.min.js',
Expand Down
2 changes: 1 addition & 1 deletion karma-build.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module.exports = function (config) {
require('./karma-base.conf.js')(config);
config.files.push('build/test/wtf_mock.js');
config.files.push('build/test/custom_error.js');
config.files.push('build/test/test_fake_polyfill.js');
config.files.push('build/lib/zone.js');
config.files.push('build/lib/common/promise.js');
config.files.push('build/lib/common/error-rewrite.js');
Expand Down
Loading

0 comments on commit 33a12ad

Please sign in to comment.