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 xSymbol = v8.createPrivateSymbol('[[x]]'); | |
11 const ySymbol = v8.createPrivateSymbol('[[y]]'); | |
12 const zSymbol = v8.createPrivateSymbol('[[z]]'); | |
13 const wSymbol = v8.createPrivateSymbol('[[w]]'); | |
14 | |
15 class DOMPointReadOnly { | |
16 constructor(x = 0, y = 0, z = 0, w = 1) { | |
17 this[xSymbol] = x; | |
18 this[ySymbol] = y; | |
19 this[zSymbol] = z; | |
20 this[wSymbol] = w; | |
21 } | |
22 | |
23 get x() { | |
24 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
| |
25 } | |
26 | |
27 get y() { | |
28 return this[ySymbol]; | |
29 } | |
30 | |
31 get z() { | |
32 return this[zSymbol]; | |
33 } | |
34 | |
35 get w() { | |
36 return this[wSymbol]; | |
37 } | |
38 | |
39 static fromPoint(init) { | |
40 return new DOMPointReadOnly(init.x, init.y, init.z, init.w); | |
41 } | |
42 } | |
43 | |
44 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
| |
45 constructor(x = 0, y = 0, z = 0, w = 1) { | |
46 super(x, y, z, w); | |
47 } | |
48 | |
49 get x() { | |
50 return this[xSymbol]; | |
51 } | |
52 | |
53 set x(x) { | |
54 this[xSymbol] = x; | |
zino
2016/02/23 16:13:25
Is it correct to set NaN if x isn't Number.
e.g.
| |
55 } | |
56 | |
57 get y() { | |
58 return this[ySymbol]; | |
59 } | |
60 | |
61 set y(y) { | |
62 this[ySymbol] = y; | |
63 } | |
64 | |
65 get z() { | |
66 return this[zSymbol]; | |
67 } | |
68 | |
69 set z(z) { | |
70 this[zSymbol] = z; | |
71 } | |
72 | |
73 get w() { | |
74 return this[wSymbol]; | |
75 } | |
76 | |
77 set w(w) { | |
78 this[wSymbol] = w; | |
79 } | |
80 | |
81 static fromPoint(init) { | |
82 return new DOMPoint(init.x, init.y, init.z, init.w); | |
83 } | |
84 } | |
85 | |
86 binding.createDOMPointReadOnly = (x, y, z, w) => new DOMPointReadOnly(x, y, z, w); | |
87 binding.createDOMPoint = (x, y, z, w) => new DOMPoint(x, y, z, w); | |
88 binding.updateDOMPoint = function(obj, x, y, z, w) { | |
89 if (obj instanceof DOMPoint) { | |
domenic
2016/02/22 18:29:23
A better test (that can't be fooled by author code
| |
90 obj[xSymbol] = x; | |
91 obj[ySymbol] = y; | |
92 obj[zSymbol] = z; | |
93 obj[wSymbol] = w; | |
94 } | |
95 }; | |
96 | |
97 defineProperty(global, 'DOMPointReadOnly', { | |
98 value: DOMPointReadOnly, | |
99 configurable: true, | |
100 enumerable: false, | |
101 writable: true | |
102 }); | |
103 | |
104 defineProperty(global, 'DOMPoint', { | |
105 value: DOMPoint, | |
106 configurable: true, | |
107 enumerable: false, | |
108 writable: true | |
109 }); | |
110 }); | |
OLD | NEW |