Skip to content

Commit

Permalink
feat(operator): to primitive impl for dom point
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Jul 30, 2023
1 parent d143b53 commit 7170acb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { cachedValueOf, defineVectorLength } from "./operator.js";

export const hijackDOMPoint = (DOMPoint) => {
try {
cachedValueOf(DOMPoint);
defineVectorLength(DOMPoint, 4);
} catch (e) {
console.error('error while hijackDOMPoint');
console.error(e);
}
};

18 changes: 14 additions & 4 deletions src/operator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isNumber } from './utils/math';
import { hijackDOMPoint } from "./dom.js";

const X = 0;
const Y = 1;
Expand Down Expand Up @@ -194,16 +195,20 @@ export function operatorCalc (alg, result) {
export function cachedValueOf (VectorClass, getSource) {
const Vector = VectorClass.prototype;
Vector[GET_SOURCE] = getSource;
const name = 'valueOf';
const org = Vector[name];
const org = Vector[Symbol.toPrimitive] || function (hint) {
if (hint === 'string') {
return this.toString();
}
return this.valueOf();
};

Vector[name] = function () {
Vector[Symbol.toPrimitive] = function (hint) {
if (inProgress === X) {
inVector = inVector ? maxVector(inVector, this) : this;
collect[elCount - 1] = this;
}
if (inProgress === DEFAULT) {
return org.call(this);
return org.call(this, hint);
}
return getVectorValue(this, inProgress);
};
Expand Down Expand Up @@ -277,3 +282,8 @@ export function cachedFactory (VectorClass) {
export function cachedFunction (fun) {
return bindCache(fun);
}

if (typeof DOMPoint !== 'undefined' ) {
// eslint-disable-next-line no-undef
hijackDOMPoint(DOMPoint);
}

0 comments on commit 7170acb

Please sign in to comment.