From 624d341bc6e71fbd41ffad142d99c908fb90164c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 25 Sep 2020 11:19:59 +0200 Subject: [PATCH 01/14] prototypes for idb and promises in older browsers --- prototypes/idb-promises.html | 181 +++++++++++++++ prototypes/promifill.js | 433 +++++++++++++++++++++++++++++++++++ 2 files changed, 614 insertions(+) create mode 100644 prototypes/idb-promises.html create mode 100644 prototypes/promifill.js diff --git a/prototypes/idb-promises.html b/prototypes/idb-promises.html new file mode 100644 index 00000000..a4d6f2f4 --- /dev/null +++ b/prototypes/idb-promises.html @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + diff --git a/prototypes/promifill.js b/prototypes/promifill.js new file mode 100644 index 00000000..ea256b54 --- /dev/null +++ b/prototypes/promifill.js @@ -0,0 +1,433 @@ +"use strict"; + +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var PENDING = void 0, + FULFILLED = true, + REJECTED = false; + +var Promifill = /*#__PURE__*/function () { + _createClass(Promifill, [{ + key: "state", + get: function get() { + return PENDING; + } + }, { + key: "value", + get: function get() { + return void 0; + } + }, { + key: "settled", + get: function get() { + return false; + } + }]); + + function Promifill(executor) { + var _this = this; + + _classCallCheck(this, Promifill); + + if (typeof executor != "function") { + throw new TypeError("Promise resolver ".concat(Object.prototype.toString.call(executor), " is not a function")); + } + + defineProperty(this, "chain", []); + defineProperty(this, "observers", []); + var secret = []; + + var resolve = function resolve(value, bypassKey) { + if (_this.settled && bypassKey !== secret) { + return; + } + + defineProperty(_this, "settled", true); + var then_ = value && value.then; + var thenable = typeof then_ == "function"; + + if (thenable) { + defineProperty(value, "preventThrow", true); + } + + if (thenable && value.state === PENDING) { + then_.call(value, function (v) { + return resolve(v, secret); + }, function (r) { + return reject(r, secret); + }); + } else { + defineProperty(_this, "value", thenable ? value.value : value); + defineProperty(_this, "state", thenable ? value.state : FULFILLED); + schedule(_this.observers.map(function (observer) { + return { + handler: _this.state === FULFILLED ? observer.onfulfill : observer.onreject, + value: _this.value + }; + })); + + if (_this.state === REJECTED) { + raiseUnhandledPromiseRejectionException(_this.value, _this); + } + } + }; + + var reject = function reject(reason, bypassKey) { + if (_this.settled && bypassKey !== secret) { + return; + } + + defineProperty(_this, "settled", true); + defineProperty(_this, "value", reason); + defineProperty(_this, "state", REJECTED); + schedule(_this.observers.map(function (observer) { + return { + handler: observer.onreject, + value: _this.value + }; + })); + raiseUnhandledPromiseRejectionException(_this.value, _this); + }; + + try { + executor(resolve, reject); + } catch (error) { + reject(error); + } + } + + _createClass(Promifill, [{ + key: "then", + value: function then(onfulfill, onreject) { + var _this2 = this; + + var chainedPromise = new this.constructor(function (resolve, reject) { + var internalOnfulfill = function internalOnfulfill(value) { + try { + resolve(typeof onfulfill == "function" ? onfulfill(value) : value); + } catch (error) { + reject(error); + } + }; + + var internalOnreject = function internalOnreject(reason) { + try { + if (typeof onreject == "function") { + resolve(onreject(reason)); + } else { + reject(reason); + } + } catch (error) { + reject(error); + } + }; + + if (_this2.state === PENDING) { + _this2.observers.push({ + onfulfill: internalOnfulfill, + onreject: internalOnreject + }); + } else { + schedule([{ + handler: _this2.state === FULFILLED ? internalOnfulfill : internalOnreject, + value: _this2.value + }]); + } + }); + this.chain.push(chainedPromise); + return chainedPromise; + } + }, { + key: "catch", + value: function _catch(onreject) { + return this.then(null, onreject); + } + }, { + key: "finally", + value: function _finally(oncomplete) { + var _this3 = this; + + var chainedPromise = new this.constructor(function (resolve, reject) { + var internalOncomplete = function internalOncomplete() { + try { + oncomplete(); + + if (_this3.state === FULFILLED) { + resolve(_this3.value); + } else { + reject(_this3.value); + } + } catch (error) { + reject(error); + } + }; + + if (_this3.state === PENDING) { + _this3.observers.push({ + onfulfill: internalOncomplete, + onreject: internalOncomplete + }); + } else { + schedule([{ + handler: internalOncomplete + }]); + } + }); + this.chain.push(chainedPromise); + return chainedPromise; + } + }], [{ + key: "resolve", + value: function resolve(value) { + return value && value.constructor === Promifill ? value : new Promifill(function (resolve) { + resolve(value); + }); + } + }, { + key: "reject", + value: function reject(reason) { + return new Promifill(function (_, reject) { + reject(reason); + }); + } + }, { + key: "all", + value: function all(iterable) { + return new Promifill(function (resolve, reject) { + validateIterable(iterable); + var iterableSize = 0; + var values = []; + + if (isEmptyIterable(iterable)) { + return resolve(values); + } + + var add = function add(value, index) { + values[index] = value; + + if (values.filter(function () { + return true; + }).length === iterableSize) { + resolve(values); + } + }; + + var _iterator = _createForOfIteratorHelper(iterable), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var item = _step.value; + + (function (entry, index) { + Promifill.resolve(entry).then(function (value) { + return add(value, index); + }, reject); + })(item, iterableSize++); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + }); + } + }, { + key: "race", + value: function race(iterable) { + return new Promifill(function (resolve, reject) { + validateIterable(iterable); + + if (isEmptyIterable(iterable)) { + return; + } + + var _iterator2 = _createForOfIteratorHelper(iterable), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var entry = _step2.value; + Promifill.resolve(entry).then(resolve, reject); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + }); + } + }]); + + return Promifill; +}(); + +var defineProperty = function defineProperty(obj, propName, propValue) { + Object.defineProperty(obj, propName, { + value: propValue + }); +}; + +var defer = function defer(handler) { + return function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + setTimeout.apply(void 0, [handler, 0].concat(args)); + }; +}; + +var thrower = function thrower(error) { + throw error instanceof Error ? error : new Error(error); +}; + +var raiseUnhandledPromiseRejectionException = defer(function (error, promise) { + if (promise.preventThrow || promise.chain.length > 0) { + return; + } + + thrower(error); +}); + +var MutationObserverStrategy = /*#__PURE__*/function () { + function MutationObserverStrategy(handler) { + _classCallCheck(this, MutationObserverStrategy); + + var observer = new MutationObserver(handler); + var node = this.node = document.createTextNode(""); + observer.observe(node, { + characterData: true + }); + } + + _createClass(MutationObserverStrategy, [{ + key: "trigger", + value: function trigger() { + this.node.data = this.node.data === 1 ? 0 : 1; + } + }]); + + return MutationObserverStrategy; +}(); + +var NextTickStrategy = /*#__PURE__*/function () { + function NextTickStrategy(handler) { + _classCallCheck(this, NextTickStrategy); + + this.scheduleNextTick = function () { + return process.nextTick(handler); + }; + } + + _createClass(NextTickStrategy, [{ + key: "trigger", + value: function trigger() { + this.scheduleNextTick(); + } + }]); + + return NextTickStrategy; +}(); + +var BetterThanNothingStrategy = /*#__PURE__*/function () { + function BetterThanNothingStrategy(handler) { + _classCallCheck(this, BetterThanNothingStrategy); + + this.scheduleAsap = function () { + return setTimeout(handler, 0); + }; + } + + _createClass(BetterThanNothingStrategy, [{ + key: "trigger", + value: function trigger() { + this.scheduleAsap(); + } + }]); + + return BetterThanNothingStrategy; +}(); + +var getStrategy = function getStrategy() { + if (typeof window != "undefined" && typeof window.MutationObserver == "function") { + return MutationObserverStrategy; + } + + if (typeof global != "undefined" && typeof process != "undefined" && typeof process.nextTick == "function") { + return NextTickStrategy; + } + + return BetterThanNothingStrategy; +}; + +var schedule = function () { + var microtasks = []; + + var run = function run() { + var handler, value; + + while (microtasks.length > 0 && (_microtasks$shift = microtasks.shift(), handler = _microtasks$shift.handler, value = _microtasks$shift.value, _microtasks$shift)) { + var _microtasks$shift; + + handler(value); + } + }; + + var Strategy = getStrategy(); + var ctrl = new Strategy(run); + return function (observers) { + if (observers.length == 0) { + return; + } + + microtasks = microtasks.concat(observers); + observers.length = 0; + ctrl.trigger(); + }; +}(); + +var isIterable = function isIterable(subject) { + return subject != null && typeof subject[Symbol.iterator] == "function"; +}; + +var validateIterable = function validateIterable(subject) { + if (isIterable(subject)) { + return; + } + + throw new TypeError("Cannot read property 'Symbol(Symbol.iterator)' of ".concat(Object.prototype.toString.call(subject), ".")); +}; + +var isEmptyIterable = function isEmptyIterable(subject) { + var _iterator3 = _createForOfIteratorHelper(subject), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var _ = _step3.value; + // eslint-disable-line no-unused-vars + return false; + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + + return true; +}; + +//if (!window.Promise) { + window.Promise = Promifill; +//} From becdf656a4034842372bf95b704da2f22ab0b324 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 25 Sep 2020 16:52:26 +0200 Subject: [PATCH 02/14] nicer error messages when decrypting with a worker --- src/utils/WorkerPool.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/WorkerPool.js b/src/utils/WorkerPool.js index 56feaf8c..2f0e89b8 100644 --- a/src/utils/WorkerPool.js +++ b/src/utils/WorkerPool.js @@ -103,7 +103,9 @@ export class WorkerPool { if (message.type === "success") { request._resolve(message.payload); } else if (message.type === "error") { - request._reject(new Error(message.stack)); + const err = new Error(message.message); + err.stack = message.stack; + request._reject(err); } request._dispose(); } From 64290d5ae628d227c9a2c01debbe0cb1d426d6d9 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 25 Sep 2020 16:53:19 +0200 Subject: [PATCH 03/14] flush promises manually in idb event handler --- src/legacy-polyfill.js | 10 + src/matrix/storage/idb/utils.js | 27 ++- src/utils/Promifill.js | 380 ++++++++++++++++++++++++++++++++ 3 files changed, 411 insertions(+), 6 deletions(-) create mode 100644 src/utils/Promifill.js diff --git a/src/legacy-polyfill.js b/src/legacy-polyfill.js index 80be7a61..30bb8f6d 100644 --- a/src/legacy-polyfill.js +++ b/src/legacy-polyfill.js @@ -15,6 +15,10 @@ limitations under the License. */ // polyfills needed for IE11 + +const hasNativePromise = typeof window.Promise === "function"; + +// TODO: don't include a polyfill for promises as we already provide one import "core-js/stable"; import "regenerator-runtime/runtime"; import "mdn-polyfills/Element.prototype.closest"; @@ -24,6 +28,12 @@ import "mdn-polyfills/Element.prototype.closest"; // it will also include the file supporting *all* the encodings, // weighing a good extra 500kb :-( import "text-encoding"; +import {Promifill} from "./utils/Promifill.js"; + +// console.log("hasNativePromise", hasNativePromise); +// if (!hasNativePromise) { + window.Promise = Promifill; +// } // TODO: contribute this to mdn-polyfills if (!Element.prototype.remove) { diff --git a/src/matrix/storage/idb/utils.js b/src/matrix/storage/idb/utils.js index 7cdc30fd..41d472d9 100644 --- a/src/matrix/storage/idb/utils.js +++ b/src/matrix/storage/idb/utils.js @@ -16,7 +16,7 @@ limitations under the License. import { StorageError } from "../common.js"; -class WrappedDOMException extends StorageError { +class IDBRequestError extends StorageError { constructor(request) { const source = request?.source; const storeName = source?.name || ""; @@ -50,15 +50,27 @@ export function openDatabase(name, createObjectStore, version) { export function reqAsPromise(req) { return new Promise((resolve, reject) => { - req.addEventListener("success", event => resolve(event.target.result)); - req.addEventListener("error", event => reject(new WrappedDOMException(event.target))); + req.addEventListener("success", event => { + resolve(event.target.result); + Promise.flushQueue && Promise.flushQueue(); + }); + req.addEventListener("error", () => { + reject(new IDBRequestError(req)); + Promise.flushQueue && Promise.flushQueue(); + }); }); } export function txnAsPromise(txn) { return new Promise((resolve, reject) => { - txn.addEventListener("complete", resolve); - txn.addEventListener("abort", event => reject(new WrappedDOMException(event.target))); + txn.addEventListener("complete", () => { + resolve(); + Promise.flushQueue && Promise.flushQueue(); + }); + txn.addEventListener("abort", () => { + reject(new IDBRequestError(txn)); + Promise.flushQueue && Promise.flushQueue(); + }); }); } @@ -66,13 +78,15 @@ export function iterateCursor(cursorRequest, processValue) { // TODO: does cursor already have a value here?? return new Promise((resolve, reject) => { cursorRequest.onerror = () => { - reject(new StorageError("Query failed", cursorRequest.error)); + reject(new IDBRequestError(cursorRequest)); + Promise.flushQueue && Promise.flushQueue(); }; // collect results cursorRequest.onsuccess = (event) => { const cursor = event.target.result; if (!cursor) { resolve(false); + Promise.flushQueue && Promise.flushQueue(); return; // end of results } const result = processValue(cursor.value, cursor.key); @@ -81,6 +95,7 @@ export function iterateCursor(cursorRequest, processValue) { if (done) { resolve(true); + Promise.flushQueue && Promise.flushQueue(); } else if(jumpTo) { cursor.continue(jumpTo); } else { diff --git a/src/utils/Promifill.js b/src/utils/Promifill.js new file mode 100644 index 00000000..d4111c45 --- /dev/null +++ b/src/utils/Promifill.js @@ -0,0 +1,380 @@ +"use strict"; + +const [PENDING, FULFILLED, REJECTED] = + [void 0, true, false]; + +export class Promifill { + get state () { + return PENDING; + } + + get value () { + return void 0; + } + + get settled () { + return false; + } + + constructor (executor) { + if (typeof executor != "function") { + throw new TypeError(`Promise resolver ${Object.prototype.toString.call(executor)} is not a function`); + } + + defineProperty(this, "chain", []); + defineProperty(this, "observers", []); + + const secret = []; + + const resolve = + (value, bypassKey) => { + if (this.settled && bypassKey !== secret) { + return; + } + + defineProperty(this, "settled", true); + + const then_ = value && value.then; + const thenable = typeof then_ == "function"; + + if (thenable) { + defineProperty(value, "preventThrow", true); + } + + if (thenable && value.state === PENDING) { + then_.call( + value, + (v) => + resolve(v, secret), + (r) => + reject(r, secret) + ); + } else { + defineProperty(this, "value", + thenable + ? value.value + : value); + defineProperty(this, "state", + thenable + ? value.state + : FULFILLED); + + schedule( + this.observers.map((observer) => ( + { + handler: this.state === FULFILLED + ? observer.onfulfill + : observer.onreject, + value: this.value + })) + ); + + if (this.state === REJECTED) { + raiseUnhandledPromiseRejectionException(this.value, this); + } + } + }; + + const reject = + (reason, bypassKey) => { + if (this.settled && bypassKey !== secret) { + return; + } + + defineProperty(this, "settled", true); + + defineProperty(this, "value", reason); + defineProperty(this, "state", REJECTED); + + schedule( + this.observers.map((observer) => ( + { + handler: observer.onreject, + value: this.value + })) + ); + + raiseUnhandledPromiseRejectionException(this.value, this); + }; + + try { + executor(resolve, reject); + } catch (error) { + reject(error); + } + } + + then (onfulfill, onreject) { + const chainedPromise = new this.constructor((resolve, reject) => { + const internalOnfulfill = + (value) => { + try { + resolve( + typeof onfulfill == "function" + ? onfulfill(value) + : value + ); + } catch (error) { + reject(error); + } + }; + + const internalOnreject = + (reason) => { + try { + if (typeof onreject == "function") { + resolve(onreject(reason)); + } else { + reject(reason); + } + } catch (error) { + reject(error); + } + }; + + if (this.state === PENDING) { + this.observers.push({ onfulfill: internalOnfulfill, onreject: internalOnreject }); + } else { + schedule( + [{ + handler: this.state === FULFILLED + ? internalOnfulfill + : internalOnreject, + value: this.value + }] + ); + } + }); + + this.chain.push(chainedPromise); + return chainedPromise; + } + + catch (onreject) { + return this.then(null, onreject); + } + + finally (oncomplete) { + const chainedPromise = new this.constructor((resolve, reject) => { + const internalOncomplete = + () => { + try { + oncomplete(); + if (this.state === FULFILLED) { + resolve(this.value); + } else { + reject(this.value); + } + } catch (error) { + reject(error); + } + }; + + if (this.state === PENDING) { + this.observers.push({ onfulfill: internalOncomplete, onreject: internalOncomplete }); + } else { + schedule([{ + handler: internalOncomplete + }]); + } + }); + + this.chain.push(chainedPromise); + return chainedPromise; + } + + static resolve (value) { + return value && value.constructor === Promifill + ? value + : new Promifill((resolve) => { + resolve(value); + }); + } + + static reject (reason) { + return new Promifill((_, reject) => { + reject(reason); + }); + } + + static all (iterable) { + return new Promifill((resolve, reject) => { + validateIterable(iterable); + + let iterableSize = 0; + const values = []; + + if (isEmptyIterable(iterable)) { + return resolve(values); + } + + const add = + (value, index) => { + values[index] = value; + if (values.filter(() => true).length === iterableSize) { + resolve(values); + } + }; + + for (let item of iterable) { + ((entry, index) => { + Promifill.resolve(entry) + .then( + (value) => + add(value, index), + reject + ); + })(item, iterableSize++); + } + }); + } + + static race (iterable) { + return new Promifill((resolve, reject) => { + validateIterable(iterable); + + if (isEmptyIterable(iterable)) { + return; + } + + for (let entry of iterable) { + Promifill.resolve(entry) + .then(resolve, reject); + } + }); + } + + static flushQueue() { + console.log("flushing promise queue sync"); + schedule.flushQueue(); + } +} + +const defineProperty = + (obj, propName, propValue) => { + Object.defineProperty(obj, propName, { value: propValue }); + }; + +const defer = + (handler) => + (...args) => { + setTimeout(handler, 0, ...args); + }; + +const thrower = + (error) => { + throw error instanceof Error + ? error + : new Error(error); + }; + +const raiseUnhandledPromiseRejectionException = + defer((error, promise) => { + if (promise.preventThrow || promise.chain.length > 0) { + return; + } + thrower(error); + }); + +class MutationObserverStrategy { + constructor (handler) { + const observer = new MutationObserver(handler); + const node = this.node = + document.createTextNode(""); + observer.observe(node, { characterData: true }); + } + + trigger () { + this.node.data = this.node.data === 1 + ? 0 + : 1; + } +} + +class NextTickStrategy { + constructor (handler) { + this.scheduleNextTick = + () => process.nextTick(handler); + } + + trigger () { + this.scheduleNextTick(); + } +} + +class BetterThanNothingStrategy { + constructor (handler) { + this.scheduleAsap = + () => setTimeout(handler, 0); + } + + trigger () { + this.scheduleAsap(); + } +} + +const getStrategy = + () => { + if (typeof window != "undefined" && typeof window.MutationObserver == "function") { + return MutationObserverStrategy; + } + if (typeof global != "undefined" && typeof process != "undefined" && typeof process.nextTick == "function") { + return NextTickStrategy; + } + + return BetterThanNothingStrategy; + }; + +const schedule = + (() => { + let microtasks = []; + + const run = + () => { + let handler, value; + while (microtasks.length > 0 && ({ handler, value } = microtasks.shift())) { + handler(value); + } + }; + + const Strategy = getStrategy(); + const ctrl = new Strategy(run); + + const scheduleFn = (observers) => { + if (observers.length == 0) { + return; + } + + microtasks = microtasks.concat(observers); + observers.length = 0; + + ctrl.trigger(); + }; + + scheduleFn.flushQueue = function() { + run(); + }; + + return scheduleFn; + })(); + +const isIterable = + (subject) => subject != null && typeof subject[Symbol.iterator] == "function"; + +const validateIterable = + (subject) => { + if (isIterable(subject)) { + return; + } + + throw new TypeError(`Cannot read property 'Symbol(Symbol.iterator)' of ${Object.prototype.toString.call(subject)}.`); + }; + +const isEmptyIterable = + (subject) => { + for (let _ of subject) { // eslint-disable-line no-unused-vars + return false; + } + + return true; + }; From 9498524369a7f5f31c01745f84f3c083589881f9 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 25 Sep 2020 16:53:56 +0200 Subject: [PATCH 04/14] add flushing manually to prototype --- prototypes/idb-promises.html | 97 +++++++----------------------------- prototypes/promifill.js | 21 ++++++-- 2 files changed, 33 insertions(+), 85 deletions(-) diff --git a/prototypes/idb-promises.html b/prototypes/idb-promises.html index a4d6f2f4..e53d00e1 100644 --- a/prototypes/idb-promises.html +++ b/prototypes/idb-promises.html @@ -5,87 +5,20 @@ - - +