OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 (function(global, binding, v8) { |
| 6 'use strict'; |
| 7 |
| 8 const defineProperty = global.Object.defineProperty; |
| 9 |
| 10 const _x = binding.domPointX = v8.createPrivateSymbol('[[x]]'); |
| 11 const _y = binding.domPointY = v8.createPrivateSymbol('[[y]]'); |
| 12 const _z = binding.domPointZ = v8.createPrivateSymbol('[[z]]'); |
| 13 const _w = binding.domPointW = v8.createPrivateSymbol('[[w]]'); |
| 14 |
| 15 function ensureDOMPoint(obj) { |
| 16 if (!(_x in obj)) |
| 17 throw new TypeError('Illegal invocation'); |
| 18 } |
| 19 |
| 20 class DOMPointReadOnly { |
| 21 constructor(x = 0, y = 0, z = 0, w = 1) { |
| 22 this[_x] = +x; |
| 23 this[_y] = +y; |
| 24 this[_z] = +z; |
| 25 this[_w] = +w; |
| 26 } |
| 27 |
| 28 get x() { |
| 29 ensureDOMPoint(this); |
| 30 return this[_x]; |
| 31 } |
| 32 |
| 33 get y() { |
| 34 ensureDOMPoint(this); |
| 35 return this[_y]; |
| 36 } |
| 37 |
| 38 get z() { |
| 39 ensureDOMPoint(this); |
| 40 return this[_z]; |
| 41 } |
| 42 |
| 43 get w() { |
| 44 ensureDOMPoint(this); |
| 45 return this[_w]; |
| 46 } |
| 47 |
| 48 static fromPoint(init) { |
| 49 return new DOMPointReadOnly(init.x, init.y, init.z, init.w); |
| 50 } |
| 51 } |
| 52 |
| 53 binding.createDOMPointReadOnly = (x, y, z, w) => |
| 54 new DOMPointReadOnly(x, y, z, w); |
| 55 binding.ensureDOMPoint = ensureDOMPoint; |
| 56 |
| 57 defineProperty(global, 'DOMPointReadOnly', { |
| 58 value: DOMPointReadOnly, |
| 59 configurable: true, |
| 60 enumerable: false, |
| 61 writable: true |
| 62 }); |
| 63 }); |
OLD | NEW |