diff --git a/dist/nodejs-pal-builder.js b/dist/nodejs-pal-builder.js index 6dc620c..ddf50e0 100644 --- a/dist/nodejs-pal-builder.js +++ b/dist/nodejs-pal-builder.js @@ -66,18 +66,81 @@ function patchNotifyChange(window) { intersectMethod(element_proto, "removeAttributeNS", notify); } function ensurePerformance(window) { + const startOffset = Date.now ? Date.now() : +(new Date); + const _entries = []; + const _marksIndex = {}; + function _filterEntries(key, value) { + var i = 0, n = _entries.length, result = []; + for (; i < n; i++) { + if (_entries[i][key] == value) { + result.push(_entries[i]); + } + } + return result; + } + function _clearEntries(type, name) { + var i = _entries.length, entry; + while (i--) { + entry = _entries[i]; + if (entry.entryType == type && (name === void 0 || entry.name == name)) { + _entries.splice(i, 1); + } + } + } + ; if (window.performance === undefined) { window.performance = {}; } if (window.performance.now === undefined) { let nowOffset = Date.now(); - //if (performance.timing && performance.timing.navigationStart) { - // nowOffset = performance.timing.navigationStart; - //} window.performance.now = function now() { return Date.now() - nowOffset; }; } + if (!window.performance.mark) { + window.performance.mark = window.performance.webkitMark || function (name) { + const mark = { + name, + entryType: "mark", + startTime: window.performance.now(), + duration: 0 + }; + _entries.push(mark); + _marksIndex[name] = mark; + }; + } + if (!window.performance.measure) { + window.performance.measure = window.performance.webkitMeasure || function (name, startMark, endMark) { + startMark = _marksIndex[startMark].startTime; + endMark = _marksIndex[endMark].startTime; + _entries.push({ + name, + entryType: "measure", + startTime: startMark, + duration: endMark - startMark + }); + }; + } + if (!window.performance.getEntriesByType) { + window.performance.getEntriesByType = window.performance.webkitGetEntriesByType || function (type) { + return _filterEntries("entryType", type); + }; + } + if (!window.performance.getEntriesByName) { + window.performance.getEntriesByName = window.performance.webkitGetEntriesByName || function (name) { + return _filterEntries("name", name); + }; + } + if (!window.performance.clearMarks) { + window.performance.clearMarks = window.performance.webkitClearMarks || function (name) { + _clearEntries("mark", name); + }; + } + if (!window.performance.clearMeasures) { + window.performance.clearMeasures = window.performance.webkitClearMeasures || function (name) { + _clearEntries("measure", name); + }; + } } function ensureMutationObserver(window) { if (!window.MutationObserver) { diff --git a/dist/nodejs-pal-builder.js.map b/dist/nodejs-pal-builder.js.map index 1b1ebab..fc15f22 100644 --- a/dist/nodejs-pal-builder.js.map +++ b/dist/nodejs-pal-builder.js.map @@ -1 +1 @@ -{"version":3,"sources":["nodejs-pal-builder.ts"],"names":[],"mappings":";;AAKA,uDAAmD;AACnD,qDAAiD;AACjD,6CAAyC;AACzC,iCAA8B;AAC9B,qEAAiE;AACjE,qEAAiE;AAEjE,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B;IACE,IAAI,KAAK,GAAG,IAAI,aAAK,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,MAAM,GAAqB,KAAK,CAAC,MAAM,CAAC;IAE5C,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;QACnB,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC1B,aAAa,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEtC,IAAI,QAAQ,GAAG,IAAI,gCAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjD,IAAI,GAAG,GAAG,IAAI,sBAAS,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,OAAO,GAAG,IAAI,8BAAa,CAAC,MAAM,CAAC,CAAC;IAExC,MAAM,CAAC;QACL,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,QAAQ;QAClB,GAAG,EAAE,GAAG;QACR,OAAO,EAAE,OAAO;KACjB,CAAC;AACJ,CAAC;AAtBD,4BAsBC;AAED,IAAI,eAAe,GAAG,UAAU,KAAK,EAAE,YAAoB,EAAE,SAAmB;IAC9E,IAAI,GAAG,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAC/D,IAAI,MAAM,GAA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,CAAC,CAAC;IACpD,eAAe,CAAC,UAAU,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IACjD,eAAe,CAAC,UAAU,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IAEnD,IAAI,aAAa,GAAS,MAAO,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;IAE1D,eAAe,CAAC,aAAa,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IACvD,eAAe,CAAC,aAAa,EAAE,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAC1D,eAAe,CAAC,aAAa,EAAE,qBAAqB,EAAE,MAAM,CAAC,CAAC;IAC9D,eAAe,CAAC,aAAa,EAAE,mBAAmB,EAAE,MAAM,CAAC,CAAC;AAC9D,CAAC;AAGD,2BAA2B,MAAM;IAC/B,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC;QACrC,MAAM,CAAC,WAAW,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC;QACzC,IAAI,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE3B,iEAAiE;QACjE,mDAAmD;QACnD,GAAG;QAEH,MAAM,CAAC,WAAW,CAAC,GAAG,GAAG;YACvB,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;QAChC,CAAC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,gCAAgC,MAAM;IACpC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAC7B,MAAM,CAAC,gBAAgB,GAAG,oCAAgB,CAAC;IAC7C,CAAC;AACH,CAAC","file":"nodejs-pal-builder.js","sourcesContent":["import { initializePAL } from 'aurelia-pal';\nimport { IPlatform } from './platform';\nimport { IGlobal } from './global';\nimport { IDom } from './dom';\nimport { IFeature } from './feature';\nimport { NodeJsPlatform } from './nodejs-platform';\nimport { NodeJsFeature } from './nodejs-feature';\nimport { NodeJsDom } from './nodejs-dom';\nimport { JSDOM } from 'jsdom';\nimport { MutationObserver } from './polyfills/mutation-observer';\nimport { MutationNotifier } from './polyfills/mutation-observer';\n\nlet _patchedjsdom = false;\n\nexport function buildPal(): { global: IGlobal, platform: IPlatform, dom: IDom, feature: IFeature } {\n var jsdom = new JSDOM(undefined, {});\n var global: IGlobal = jsdom.window;\n\n if (!_patchedjsdom) {\n patchNotifyChange(global);\n _patchedjsdom = true;\n }\n\n ensurePerformance(global.window);\n ensureMutationObserver(global.window);\n\n var platform = new NodeJsPlatform(global, jsdom);\n var dom = new NodeJsDom(global);\n var feature = new NodeJsFeature(global);\n\n return {\n global: global,\n platform: platform,\n dom: dom,\n feature: feature\n };\n}\n\nlet intersectSetter = function (proto, propertyName: string, intersect: Function) {\n let old = Object.getOwnPropertyDescriptor(proto, propertyName);\n let oldSet = old.set;\n let newSet = function set(V) {\n oldSet.call(this, V);\n intersect(this);\n };\n Object.defineProperty(proto, propertyName, {\n set: newSet,\n get: old.get,\n configurable: old.configurable,\n enumerable: old.enumerable\n });\n};\n\nlet intersectMethod = function (proto, methodName: string, intersect: Function) {\n let orig = proto[methodName];\n proto[methodName] = function (...args) {\n var ret = orig.apply(this, args);\n intersect(this);\n return ret;\n };\n};\n\nfunction patchNotifyChange(window: Window) {\n let notifyInstance = MutationNotifier.getInstance();\n let notify = function (node: Node) { notifyInstance.notifyChanged(node); };\n\n let node_proto = (window)._core.Node.prototype;\n\n intersectMethod(node_proto, \"appendChild\", notify);\n intersectMethod(node_proto, \"insertBefore\", notify);\n intersectMethod(node_proto, \"removeChild\", notify);\n intersectMethod(node_proto, \"replaceChild\", notify);\n intersectSetter(node_proto, \"nodeValue\", notify);\n intersectSetter(node_proto, \"textContent\", notify);\n\n let element_proto = (window)._core.Element.prototype;\n\n intersectMethod(element_proto, \"setAttribute\", notify);\n intersectMethod(element_proto, \"removeAttribute\", notify);\n intersectMethod(element_proto, \"removeAttributeNode\", notify);\n intersectMethod(element_proto, \"removeAttributeNS\", notify);\n}\n\n\nfunction ensurePerformance(window) {\n if (window.performance === undefined) {\n window.performance = {};\n }\n\n if (window.performance.now === undefined) {\n let nowOffset = Date.now();\n\n //if (performance.timing && performance.timing.navigationStart) {\n // nowOffset = performance.timing.navigationStart;\n //}\n\n window.performance.now = function now() {\n return Date.now() - nowOffset;\n };\n }\n}\n\nfunction ensureMutationObserver(window) {\n if (!window.MutationObserver) {\n window.MutationObserver = MutationObserver;\n }\n}\n"],"sourceRoot":"../src/"} \ No newline at end of file +{"version":3,"sources":["nodejs-pal-builder.ts"],"names":[],"mappings":";;AAKA,uDAAmD;AACnD,qDAAiD;AACjD,6CAAyC;AACzC,iCAA8B;AAC9B,qEAAiE;AACjE,qEAAiE;AAEjE,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B;IACE,IAAI,KAAK,GAAG,IAAI,aAAK,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,MAAM,GAAqB,KAAK,CAAC,MAAM,CAAC;IAE5C,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;QACnB,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC1B,aAAa,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEtC,IAAI,QAAQ,GAAG,IAAI,gCAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjD,IAAI,GAAG,GAAG,IAAI,sBAAS,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,OAAO,GAAG,IAAI,8BAAa,CAAC,MAAM,CAAC,CAAC;IAExC,MAAM,CAAC;QACL,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,QAAQ;QAClB,GAAG,EAAE,GAAG;QACR,OAAO,EAAE,OAA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AAW,CAAC,UAAU,CAAC,CAAC,CAAC;QACnC,MAAM,CAAC,WAAW,CAAC,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,gBAAgB,IAAI,UAAU,IAAI;YACnF,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC9B,CAAC,CAAC;IACJ,CAAC;IAGD,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;QACtC,MAAM,CAAC,WAAW,CAAC,aAAa,GAAG,MAAM,CAAC,WAAW,CAAC,mBAAmB,IAAI,UAAU,IAAI;YACzF,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QACjC,CAAC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,gCAAgC,MAAM;IACpC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAC7B,MAAM,CAAC,gBAAgB,GAAG,oCAAgB,CAAC;IAC7C,CAAC;AACH,CAAC","file":"nodejs-pal-builder.js","sourcesContent":["import { initializePAL } from 'aurelia-pal';\nimport { IPlatform } from './platform';\nimport { IGlobal } from './global';\nimport { IDom } from './dom';\nimport { IFeature } from './feature';\nimport { NodeJsPlatform } from './nodejs-platform';\nimport { NodeJsFeature } from './nodejs-feature';\nimport { NodeJsDom } from './nodejs-dom';\nimport { JSDOM } from 'jsdom';\nimport { MutationObserver } from './polyfills/mutation-observer';\nimport { MutationNotifier } from './polyfills/mutation-observer';\n\nlet _patchedjsdom = false;\n\nexport function buildPal(): { global: IGlobal, platform: IPlatform, dom: IDom, feature: IFeature } {\n var jsdom = new JSDOM(undefined, {});\n var global: IGlobal = jsdom.window;\n\n if (!_patchedjsdom) {\n patchNotifyChange(global);\n _patchedjsdom = true;\n }\n\n ensurePerformance(global.window);\n ensureMutationObserver(global.window);\n\n var platform = new NodeJsPlatform(global, jsdom);\n var dom = new NodeJsDom(global);\n var feature = new NodeJsFeature(global);\n\n return {\n global: global,\n platform: platform,\n dom: dom,\n feature: feature\n };\n}\n\nlet intersectSetter = function (proto, propertyName: string, intersect: Function) {\n let old = Object.getOwnPropertyDescriptor(proto, propertyName);\n let oldSet = old.set;\n let newSet = function set(V) {\n oldSet.call(this, V);\n intersect(this);\n };\n Object.defineProperty(proto, propertyName, {\n set: newSet,\n get: old.get,\n configurable: old.configurable,\n enumerable: old.enumerable\n });\n};\n\nlet intersectMethod = function (proto, methodName: string, intersect: Function) {\n let orig = proto[methodName];\n proto[methodName] = function (...args) {\n var ret = orig.apply(this, args);\n intersect(this);\n return ret;\n };\n};\n\nfunction patchNotifyChange(window: Window) {\n let notifyInstance = MutationNotifier.getInstance();\n let notify = function (node: Node) { notifyInstance.notifyChanged(node); };\n\n let node_proto = (window)._core.Node.prototype;\n\n intersectMethod(node_proto, \"appendChild\", notify);\n intersectMethod(node_proto, \"insertBefore\", notify);\n intersectMethod(node_proto, \"removeChild\", notify);\n intersectMethod(node_proto, \"replaceChild\", notify);\n intersectSetter(node_proto, \"nodeValue\", notify);\n intersectSetter(node_proto, \"textContent\", notify);\n\n let element_proto = (window)._core.Element.prototype;\n\n intersectMethod(element_proto, \"setAttribute\", notify);\n intersectMethod(element_proto, \"removeAttribute\", notify);\n intersectMethod(element_proto, \"removeAttributeNode\", notify);\n intersectMethod(element_proto, \"removeAttributeNS\", notify);\n}\n\n\nfunction ensurePerformance(window) {\n const startOffset = Date.now ? Date.now() : + (new Date);\n const _entries = [];\n const _marksIndex = {};\n\n function _filterEntries(key, value) {\n var i = 0, n = _entries.length, result = [];\n for (; i < n; i++) {\n if (_entries[i][key] == value) {\n result.push(_entries[i]);\n }\n }\n return result;\n }\n\n function _clearEntries(type, name) {\n var i = _entries.length, entry;\n while (i--) {\n entry = _entries[i];\n if (entry.entryType == type && (name === void 0 || entry.name == name)) {\n _entries.splice(i, 1);\n }\n }\n };\n\n if (window.performance === undefined) {\n window.performance = {};\n }\n\n if (window.performance.now === undefined) {\n let nowOffset = Date.now();\n\n window.performance.now = function now() {\n return Date.now() - nowOffset;\n };\n }\n\n if (!window.performance.mark) {\n window.performance.mark = window.performance.webkitMark || function (name) {\n const mark = {\n name,\n entryType: \"mark\",\n startTime: window.performance.now(),\n duration: 0\n };\n\n _entries.push(mark);\n _marksIndex[name] = mark;\n };\n }\n\n\n if (!window.performance.measure) {\n window.performance.measure = window.performance.webkitMeasure || function (name, startMark, endMark) {\n startMark = _marksIndex[startMark].startTime;\n endMark = _marksIndex[endMark].startTime;\n\n _entries.push({\n name,\n entryType: \"measure\",\n startTime: startMark,\n duration: endMark - startMark\n });\n };\n }\n\n\n if (!window.performance.getEntriesByType) {\n window.performance.getEntriesByType = window.performance.webkitGetEntriesByType || function (type) {\n return _filterEntries(\"entryType\", type);\n };\n }\n\n\n if (!window.performance.getEntriesByName) {\n window.performance.getEntriesByName = window.performance.webkitGetEntriesByName || function (name) {\n return _filterEntries(\"name\", name);\n };\n }\n\n\n if (!window.performance.clearMarks) {\n window.performance.clearMarks = window.performance.webkitClearMarks || function (name) {\n _clearEntries(\"mark\", name);\n };\n }\n\n\n if (!window.performance.clearMeasures) {\n window.performance.clearMeasures = window.performance.webkitClearMeasures || function (name) {\n _clearEntries(\"measure\", name);\n };\n }\n}\n\nfunction ensureMutationObserver(window) {\n if (!window.MutationObserver) {\n window.MutationObserver = MutationObserver;\n }\n}\n"],"sourceRoot":"../src/"} \ No newline at end of file diff --git a/dist/performance.d.ts b/dist/performance.d.ts index a4f2777..a706580 100644 --- a/dist/performance.d.ts +++ b/dist/performance.d.ts @@ -7,4 +7,51 @@ export interface IPerformance { * @return The timestamp, measured in milliseconds, accurate to one thousandth of a millisecond. */ now(): number; + /** + * Removes the given mark from the browser's performance entry buffer. + * + * @param {string} [markName] A DOMString representing the name of the timestamp. If this argument is omitted, all performance entries with an entry type of "mark" will be removed. + * @memberof IPerformance + */ + clearMarks(markName?: string): void; + /** + * Removes the given measure from the browser's performance entry buffer. + * + * @param {string} [measureName] A DOMString representing the name of the timestamp. If this argument is omitted, all performance entries with an entry type of "measure" will be removed. + * @memberof IPerformance + */ + clearMeasures(measureName?: string): void; + /** + * Returns a list of PerformanceEntry objects based on the given name and entry type. + * + * @param {string} name The name of the entry to retrieve + * @param {string} [entryType] The type of entry to retrieve such as "mark". The valid entry types are listed in PerformanceEntry.entryType. + * @returns {*} + * @memberof IPerformance + */ + getEntriesByName(name: string, entryType?: string): any; + /** + * Returns a list of PerformanceEntry objects of the given entry type. + * + * @param {string} entryType The type of entry to retrieve such as "mark". The valid entry types are listed in PerformanceEntry.entryType. + * @returns {*} + * @memberof IPerformance + */ + getEntriesByType(entryType: string): any; + /** + * Creates a timestamp in the browser's performance entry buffer with the given name. + * + * @param {string} markName a DOMString representing the name of the mark + * @memberof IPerformance + */ + mark(markName: string): void; + /** + * Creates a named timestamp in the browser's performance entry buffer between two specified marks (known as the start mark and end mark, respectively). + * + * @param {string} measureName a DOMString representing the name of the measure. + * @param {string} [startMarkName] A DOMString representing the name of the measure's starting mark. May also be the name of a PerformanceTiming property. + * @param {string} [endMarkName] A DOMString representing the name of the measure's ending mark. May also be the name of a PerformanceTiming property. + * @memberof IPerformance + */ + measure(measureName: string, startMarkName?: string, endMarkName?: string): void; } diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 57366bf..e4de039 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,13 @@ + +# [1.0.0-beta.3.2.0](https://github.com/aurelia/pal-nodejs/compare/1.0.0-beta.3.1.0...1.0.0-beta.3.2.0) (2018-03-06) + + +### Features + +* **performance:** update performance API ([1508a8b](https://github.com/aurelia/pal-nodejs/commit/1508a8b)) + + + # [1.0.0-beta.3.1.0](https://github.com/aurelia/pal-nodejs/compare/1.0.0-beta.3.0.0...1.0.0-beta.3.1.0) (2018-03-03) diff --git a/package.json b/package.json index 879abf0..30c54c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-pal-nodejs", - "version": "1.0.0-beta.3.1.0", + "version": "1.0.0-beta.3.2.0", "description": "The Node.js-specific implementation of Aurelia's platform abstraction layer.", "keywords": [ "aurelia",