|
1 | 1 | import { __TS__CloneDescriptor } from "./CloneDescriptor"; |
| 2 | +import { __TS__DescriptorGet } from "./DescriptorGet"; |
| 3 | +import { __TS__DescriptorSet } from "./DescriptorSet"; |
2 | 4 |
|
3 | | -function descriptorIndex(this: any, key: string): void { |
4 | | - const value = rawget(this, key); |
5 | | - if (value !== null) { |
6 | | - return value; |
7 | | - } |
8 | | - |
9 | | - let metatable = getmetatable(this); |
10 | | - while (metatable) { |
11 | | - const rawResult = rawget(metatable, key as any); |
12 | | - if (rawResult !== undefined) { |
13 | | - return rawResult; |
14 | | - } |
| 5 | +const getmetatable = _G.getmetatable; |
15 | 6 |
|
16 | | - const descriptors = rawget(metatable, "_descriptors"); |
17 | | - if (descriptors) { |
18 | | - const descriptor: PropertyDescriptor = descriptors[key]; |
19 | | - if (descriptor !== undefined) { |
20 | | - if (descriptor.get) { |
21 | | - return descriptor.get.call(this); |
22 | | - } |
23 | | - |
24 | | - return descriptor.value; |
25 | | - } |
26 | | - } |
27 | | - |
28 | | - metatable = getmetatable(metatable); |
29 | | - } |
| 7 | +function descriptorIndex(this: any, key: string): void { |
| 8 | + return __TS__DescriptorGet.call(this, getmetatable(this), key); |
30 | 9 | } |
31 | 10 |
|
32 | 11 | function descriptorNewIndex(this: any, key: string, value: any): void { |
33 | | - let metatable = getmetatable(this); |
34 | | - while (metatable) { |
35 | | - const descriptors = rawget(metatable, "_descriptors"); |
36 | | - if (descriptors) { |
37 | | - const descriptor: PropertyDescriptor = descriptors[key]; |
38 | | - if (descriptor !== undefined) { |
39 | | - if (descriptor.set) { |
40 | | - descriptor.set.call(this, value); |
41 | | - } else { |
42 | | - if (descriptor.writable === false) { |
43 | | - throw `Cannot assign to read only property '${key}' of object '${this}'`; |
44 | | - } |
45 | | - |
46 | | - descriptor.value = value; |
47 | | - } |
48 | | - return; |
49 | | - } |
50 | | - } |
51 | | - |
52 | | - metatable = getmetatable(metatable); |
53 | | - } |
54 | | - |
55 | | - rawset(this, key, value); |
| 12 | + return __TS__DescriptorSet.call(this, getmetatable(this), key, value); |
56 | 13 | } |
57 | 14 |
|
58 | 15 | // It's also used directly in class transform to add descriptors to the prototype |
|
0 commit comments