Chromium Code Reviews| Index: third_party/WebKit/Source/modules/geometry/DOMPoint.js |
| diff --git a/third_party/WebKit/Source/modules/geometry/DOMPoint.js b/third_party/WebKit/Source/modules/geometry/DOMPoint.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e53da067d8446d788ff683c1fd930a45bcb72091 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/geometry/DOMPoint.js |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +(function(global, binding, v8) { |
| + 'use strict'; |
| + |
| + const defineProperty = global.Object.defineProperty; |
| + |
| + const xSymbol = v8.createPrivateSymbol('[[x]]'); |
| + const ySymbol = v8.createPrivateSymbol('[[y]]'); |
| + const zSymbol = v8.createPrivateSymbol('[[z]]'); |
| + const wSymbol = v8.createPrivateSymbol('[[w]]'); |
| + |
| + class DOMPointReadOnly { |
| + constructor(x = 0, y = 0, z = 0, w = 1) { |
| + this[xSymbol] = x; |
| + this[ySymbol] = y; |
| + this[zSymbol] = z; |
| + this[wSymbol] = w; |
| + } |
| + |
| + get x() { |
| + return this[xSymbol]; |
|
domenic
2016/02/22 18:29:23
I realized something else that we need to do for s
zino
2016/02/23 16:13:25
Thank you for comment first!
But I'm so sorry. I
|
| + } |
| + |
| + get y() { |
| + return this[ySymbol]; |
| + } |
| + |
| + get z() { |
| + return this[zSymbol]; |
| + } |
| + |
| + get w() { |
| + return this[wSymbol]; |
| + } |
| + |
| + static fromPoint(init) { |
| + return new DOMPointReadOnly(init.x, init.y, init.z, init.w); |
| + } |
| + } |
| + |
| + class DOMPoint extends DOMPointReadOnly { |
|
zino
2016/02/22 09:51:01
BTW, I didn't found a way to share private symbols
domenic
2016/02/22 18:29:23
That's pretty reasonable, except you should use `b
|
| + constructor(x = 0, y = 0, z = 0, w = 1) { |
| + super(x, y, z, w); |
| + } |
| + |
| + get x() { |
| + return this[xSymbol]; |
| + } |
| + |
| + set x(x) { |
| + this[xSymbol] = x; |
|
zino
2016/02/23 16:13:25
Is it correct to set NaN if x isn't Number.
e.g.
|
| + } |
| + |
| + get y() { |
| + return this[ySymbol]; |
| + } |
| + |
| + set y(y) { |
| + this[ySymbol] = y; |
| + } |
| + |
| + get z() { |
| + return this[zSymbol]; |
| + } |
| + |
| + set z(z) { |
| + this[zSymbol] = z; |
| + } |
| + |
| + get w() { |
| + return this[wSymbol]; |
| + } |
| + |
| + set w(w) { |
| + this[wSymbol] = w; |
| + } |
| + |
| + static fromPoint(init) { |
| + return new DOMPoint(init.x, init.y, init.z, init.w); |
| + } |
| + } |
| + |
| + binding.createDOMPointReadOnly = (x, y, z, w) => new DOMPointReadOnly(x, y, z, w); |
| + binding.createDOMPoint = (x, y, z, w) => new DOMPoint(x, y, z, w); |
| + binding.updateDOMPoint = function(obj, x, y, z, w) { |
| + if (obj instanceof DOMPoint) { |
|
domenic
2016/02/22 18:29:23
A better test (that can't be fooled by author code
|
| + obj[xSymbol] = x; |
| + obj[ySymbol] = y; |
| + obj[zSymbol] = z; |
| + obj[wSymbol] = w; |
| + } |
| + }; |
| + |
| + defineProperty(global, 'DOMPointReadOnly', { |
| + value: DOMPointReadOnly, |
| + configurable: true, |
| + enumerable: false, |
| + writable: true |
| + }); |
| + |
| + defineProperty(global, 'DOMPoint', { |
| + value: DOMPoint, |
| + configurable: true, |
| + enumerable: false, |
| + writable: true |
| + }); |
| +}); |