porffor 0.36.5 → 0.36.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,64 @@
1
- const underlyingFuncObjs: Map = new Map();
1
+ const underlyingKeys: any[] = new Array(0);
2
+ const underlyingVals: any[] = new Array(0);
2
3
  export const __Porffor_object_getObject = (obj: any): any => {
3
- if (Porffor.rawType(obj) == Porffor.TYPES.function) {
4
- const funcI32: i32 = Porffor.wasm`local.get ${obj}`;
5
- let underlying: object = underlyingFuncObjs.get(funcI32);
6
- if (underlying == null) {
7
- underlying = {};
8
-
9
- // set prototype and prototype.constructor if constructor
10
- const flags: i32 = __Porffor_funcLut_flags(funcI32);
11
- if (flags & 0b10) { // constructor
12
- const proto = {};
13
- const key1: bytestring = 'prototype';
14
- __Porffor_object_expr_initWithFlags(underlying, key1, proto, 0b1000);
15
-
16
- const key2: bytestring = 'constructor';
17
- __Porffor_object_expr_initWithFlags(proto, key2, obj, 0b1010);
4
+ const t: i32 = Porffor.rawType(obj);
5
+ if (t == Porffor.TYPES.object) return obj;
6
+
7
+ if (Porffor.fastAnd(t > 0x05, t != Porffor.TYPES.string, t != Porffor.TYPES.bytestring, t != Porffor.TYPES.undefined)) {
8
+ let idx: i32 = underlyingKeys.indexOf(obj);
9
+ if (idx == -1) {
10
+ const underlying: object = {};
11
+
12
+ if (t == Porffor.TYPES.function) {
13
+ const flags: i32 = __Porffor_funcLut_flags(obj);
14
+ if (flags & 0b10) { // constructor
15
+ // set prototype and prototype.constructor if function and constructor
16
+ const proto = {};
17
+ const key1: bytestring = 'prototype';
18
+ __Porffor_object_expr_initWithFlags(underlying, key1, proto, 0b1000);
19
+
20
+ const key2: bytestring = 'constructor';
21
+ __Porffor_object_expr_initWithFlags(proto, key2, obj, 0b1010);
22
+ }
23
+ }
24
+
25
+ Porffor.array.fastPush(underlyingVals, underlying);
26
+ idx = Porffor.array.fastPush(underlyingKeys, obj) - 1;
27
+ }
28
+
29
+ return underlyingVals[idx];
30
+ }
31
+
32
+ return obj;
33
+ };
34
+
35
+ export const __Porffor_object_makeObject = (obj: any): any => {
36
+ const t: i32 = Porffor.rawType(obj);
37
+ if (t == Porffor.TYPES.object) return obj;
38
+
39
+ if (Porffor.fastAnd(t > 0x05, t != Porffor.TYPES.string, t != Porffor.TYPES.bytestring, t != Porffor.TYPES.undefined)) {
40
+ let idx: i32 = underlyingKeys.indexOf(obj);
41
+ if (idx == -1) {
42
+ const underlying: object = {};
43
+
44
+ if (t == Porffor.TYPES.function) {
45
+ const flags: i32 = __Porffor_funcLut_flags(obj);
46
+ if (flags & 0b10) { // constructor
47
+ // set prototype and prototype.constructor if function and constructor
48
+ const proto = {};
49
+ const key1: bytestring = 'prototype';
50
+ __Porffor_object_expr_initWithFlags(underlying, key1, proto, 0b1000);
51
+
52
+ const key2: bytestring = 'constructor';
53
+ __Porffor_object_expr_initWithFlags(proto, key2, obj, 0b1010);
54
+ }
18
55
  }
19
56
 
20
- underlyingFuncObjs.set(funcI32, underlying);
57
+ Porffor.array.fastPush(underlyingVals, underlying);
58
+ idx = Porffor.array.fastPush(underlyingKeys, obj) - 1;
21
59
  }
22
60
 
23
- return underlying;
61
+ return underlyingVals[idx];
24
62
  }
25
63
 
26
64
  return obj;
@@ -18,7 +18,7 @@ import type {} from './porffor.d.ts';
18
18
 
19
19
  export const __Porffor_object_preventExtensions = (obj: any): void => {
20
20
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
21
- obj = __Porffor_object_getObject(obj);
21
+ obj = __Porffor_object_makeObject(obj);
22
22
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return;
23
23
  }
24
24
 
@@ -124,7 +124,7 @@ export const __Porffor_object_accessorSet = (entryPtr: i32): Function => {
124
124
  export const __Porffor_object_lookup = (obj: any, target: any): i32 => {
125
125
  if (Porffor.wasm`local.get ${obj}` == 0) return -1;
126
126
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
127
- obj = __Porffor_object_getObject(obj);
127
+ obj = __Porffor_object_makeObject(obj);
128
128
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return -1;
129
129
  }
130
130
 
@@ -171,8 +171,6 @@ export const __Porffor_object_lookup = (obj: any, target: any): i32 => {
171
171
  };
172
172
 
173
173
  export const __Porffor_object_get = (obj: any, key: any): any => {
174
- if (Porffor.wasm`local.get ${obj}` == 0) throw new TypeError('Cannot get property of null');
175
-
176
174
  const trueType: i32 = Porffor.wasm`local.get ${obj+1}`;
177
175
  if (trueType == Porffor.TYPES.function) {
178
176
  const tmp1: bytestring = 'name';
@@ -197,7 +195,10 @@ return`;
197
195
  }
198
196
  }
199
197
 
200
- if (trueType != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
198
+ if (trueType != Porffor.TYPES.object) obj = __Porffor_object_makeObject(obj);
199
+
200
+ if (Porffor.wasm`local.get ${obj}` == 0) throw new TypeError('Cannot get property of null');
201
+
201
202
  let entryPtr: i32 = __Porffor_object_lookup(obj, key);
202
203
  if (entryPtr == -1) {
203
204
  if (Porffor.wasm`local.get ${obj+1}` == Porffor.TYPES.object) {
@@ -289,13 +290,13 @@ export const __Porffor_object_writeKey = (ptr: i32, key: any): void => {
289
290
  };
290
291
 
291
292
  export const __Porffor_object_set = (obj: any, key: any, value: any): any => {
292
- if (Porffor.wasm`local.get ${obj}` == 0) throw new TypeError('Cannot set property of null');
293
-
294
293
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
295
- obj = __Porffor_object_getObject(obj);
294
+ obj = __Porffor_object_makeObject(obj);
296
295
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return value;
297
296
  }
298
297
 
298
+ if (Porffor.wasm`local.get ${obj}` == 0) throw new TypeError('Cannot set property of null');
299
+
299
300
  let entryPtr: i32 = __Porffor_object_lookup(obj, key);
300
301
  let flags: i32;
301
302
  if (entryPtr == -1) {
@@ -378,7 +379,7 @@ export const __Porffor_object_setStrict = (obj: any, key: any, value: any): any
378
379
  if (Porffor.wasm`local.get ${obj}` == 0) throw new TypeError('Cannot set property of null');
379
380
 
380
381
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
381
- obj = __Porffor_object_getObject(obj);
382
+ obj = __Porffor_object_makeObject(obj);
382
383
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return value;
383
384
  }
384
385
 
@@ -462,7 +463,7 @@ export const __Porffor_object_setStrict = (obj: any, key: any, value: any): any
462
463
 
463
464
  export const __Porffor_object_define = (obj: any, key: any, value: any, flags: i32): void => {
464
465
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
465
- obj = __Porffor_object_getObject(obj);
466
+ obj = __Porffor_object_makeObject(obj);
466
467
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return;
467
468
  }
468
469
 
@@ -699,7 +700,7 @@ export const __Porffor_object_isObjectOrSymbol = (arg: any): boolean => {
699
700
 
700
701
  // used for { foo: 5 }
701
702
  export const __Porffor_object_expr_init = (obj: any, key: any, value: any): void => {
702
- if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
703
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_makeObject(obj);
703
704
  let entryPtr: i32 = __Porffor_object_lookup(obj, key);
704
705
  if (entryPtr == -1) {
705
706
  // add new entry
@@ -724,7 +725,7 @@ export const __Porffor_object_expr_init = (obj: any, key: any, value: any): void
724
725
  };
725
726
 
726
727
  export const __Porffor_object_expr_initWithFlags = (obj: any, key: any, value: any, flags: i32): void => {
727
- if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
728
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_makeObject(obj);
728
729
  let entryPtr: i32 = __Porffor_object_lookup(obj, key);
729
730
  if (entryPtr == -1) {
730
731
  // add new entry
@@ -749,7 +750,7 @@ export const __Porffor_object_expr_initWithFlags = (obj: any, key: any, value: a
749
750
 
750
751
  // used for { get foo() {} }
751
752
  export const __Porffor_object_expr_get = (obj: any, key: any, get: any): void => {
752
- if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
753
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_makeObject(obj);
753
754
  let entryPtr: i32 = __Porffor_object_lookup(obj, key);
754
755
  let set: any = undefined;
755
756
  if (entryPtr == -1) {
@@ -779,7 +780,7 @@ export const __Porffor_object_expr_get = (obj: any, key: any, get: any): void =>
779
780
 
780
781
  // used for { set foo(v) {} }
781
782
  export const __Porffor_object_expr_set = (obj: any, key: any, set: any): void => {
782
- if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
783
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_makeObject(obj);
783
784
  let entryPtr: i32 = __Porffor_object_lookup(obj, key);
784
785
  let get: any = undefined;
785
786
  if (entryPtr == -1) {
@@ -18,7 +18,6 @@ export const __Object_keys = (obj: any): any[] => {
18
18
  if (obj == null) throw new TypeError('Argument is nullish, expected object');
19
19
  const out: any[] = Porffor.allocate();
20
20
 
21
- obj = __Porffor_object_getObject(obj);
22
21
  const t: i32 = Porffor.rawType(obj);
23
22
  if (t == Porffor.TYPES.object) {
24
23
  let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
@@ -65,16 +64,24 @@ local.set ${key}`;
65
64
  }
66
65
 
67
66
  out.length = i;
68
- } else if (Porffor.fastOr(
69
- t == Porffor.TYPES.array,
70
- t == Porffor.TYPES.bytestring,
71
- t == Porffor.TYPES.string
72
- )) {
73
- const len: i32 = obj.length;
74
- out.length = len;
67
+ } else {
68
+ if (Porffor.fastOr(
69
+ t == Porffor.TYPES.array,
70
+ t == Porffor.TYPES.bytestring,
71
+ t == Porffor.TYPES.string
72
+ )) {
73
+ const len: i32 = obj.length;
74
+ out.length = len;
75
+
76
+ for (let i: i32 = 0; i < len; i++) {
77
+ out[i] = __Number_prototype_toString(i);
78
+ }
79
+ }
75
80
 
76
- for (let i: i32 = 0; i < len; i++) {
77
- out[i] = __Number_prototype_toString(i);
81
+ obj = __Porffor_object_makeObject(obj);
82
+ if (Porffor.rawType(obj) == Porffor.TYPES.object) {
83
+ const objKeys: any[] = __Object_keys(obj);
84
+ for (const x of objKeys) Porffor.array.fastPush(out, x);
78
85
  }
79
86
  }
80
87
 
@@ -85,7 +92,6 @@ export const __Object_values = (obj: any): any[] => {
85
92
  if (obj == null) throw new TypeError('Argument is nullish, expected object');
86
93
  const out: any[] = Porffor.allocate();
87
94
 
88
- obj = __Porffor_object_getObject(obj);
89
95
  const t: i32 = Porffor.rawType(obj);
90
96
  if (t == Porffor.TYPES.object) {
91
97
  let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
@@ -112,16 +118,24 @@ local.set ${val+1}`;
112
118
  }
113
119
 
114
120
  out.length = i;
115
- } else if (Porffor.fastOr(
116
- t == Porffor.TYPES.array,
117
- t == Porffor.TYPES.bytestring,
118
- t == Porffor.TYPES.string
119
- )) {
120
- const len: i32 = obj.length;
121
- out.length = len;
121
+ } else {
122
+ if (Porffor.fastOr(
123
+ t == Porffor.TYPES.array,
124
+ t == Porffor.TYPES.bytestring,
125
+ t == Porffor.TYPES.string
126
+ )) {
127
+ const len: i32 = obj.length;
128
+ out.length = len;
129
+
130
+ for (let i: i32 = 0; i < len; i++) {
131
+ out[i] = obj[i];
132
+ }
133
+ }
122
134
 
123
- for (let i: i32 = 0; i < len; i++) {
124
- out[i] = obj[i];
135
+ obj = __Porffor_object_makeObject(obj);
136
+ if (Porffor.rawType(obj) == Porffor.TYPES.object) {
137
+ const objVals: any[] = __Object_values(obj);
138
+ for (const x of objVals) Porffor.array.fastPush(out, x);
125
139
  }
126
140
  }
127
141
 
@@ -181,6 +195,11 @@ export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
181
195
  return Porffor.object.lookup(_this, p) != -1;
182
196
  }
183
197
 
198
+ const obj: any = __Porffor_object_makeObject(_this);
199
+ if (Porffor.rawType(obj) == Porffor.TYPES.object) {
200
+ if (Porffor.object.lookup(obj, p) != -1) return true;
201
+ }
202
+
184
203
  const keys: any[] = __Object_keys(_this);
185
204
  return __Array_prototype_includes(keys, p);
186
205
  };
@@ -262,14 +281,19 @@ export const __Porffor_object_assignAll = (target: any, source: any) => {
262
281
  export const __Object_prototype_propertyIsEnumerable = (_this: any, prop: any) => {
263
282
  const p: any = ecma262.ToPropertyKey(prop);
264
283
 
265
- const obj: any = __Porffor_object_getObject(_this);
266
- if (Porffor.rawType(obj) == Porffor.TYPES.object) {
284
+ if (Porffor.rawType(_this) == Porffor.TYPES.object) {
267
285
  const entryPtr: i32 = Porffor.object.lookup(_this, p);
268
286
  if (entryPtr == -1) return false;
269
287
 
270
288
  return Porffor.object.isEnumerable(entryPtr);
271
289
  }
272
290
 
291
+ const obj: any = __Porffor_object_makeObject(_this);
292
+ if (Porffor.rawType(obj) == Porffor.TYPES.object) {
293
+ const entryPtr: i32 = Porffor.object.lookup(obj, p);
294
+ if (entryPtr != -1) return Porffor.object.isEnumerable(entryPtr);
295
+ }
296
+
273
297
  const keys: any[] = __Object_keys(_this);
274
298
  return __Array_prototype_includes(keys, p);
275
299
  };
@@ -413,7 +437,7 @@ export const __Object_getOwnPropertyDescriptors = (obj: any): any => {
413
437
  const out: object = {};
414
438
 
415
439
  if (Porffor.rawType(obj) != Porffor.TYPES.object) {
416
- obj = __Porffor_object_getObject(obj);
440
+ obj = __Porffor_object_makeObject(obj);
417
441
  if (Porffor.rawType(obj) != Porffor.TYPES.object) return out;
418
442
  }
419
443
 
@@ -475,16 +499,24 @@ local.set ${key}`;
475
499
  }
476
500
 
477
501
  out.length = i;
478
- } else if (Porffor.fastOr(
479
- t == Porffor.TYPES.array,
480
- t == Porffor.TYPES.bytestring,
481
- t == Porffor.TYPES.string
482
- )) {
483
- const len: i32 = obj.length;
484
- out.length = len;
502
+ } else {
503
+ if (Porffor.fastOr(
504
+ t == Porffor.TYPES.array,
505
+ t == Porffor.TYPES.bytestring,
506
+ t == Porffor.TYPES.string
507
+ )) {
508
+ const len: i32 = obj.length;
509
+ out.length = len;
510
+
511
+ for (let i: i32 = 0; i < len; i++) {
512
+ out[i] = __Number_prototype_toString(i);
513
+ }
514
+ }
485
515
 
486
- for (let i: i32 = 0; i < len; i++) {
487
- out[i] = __Number_prototype_toString(i);
516
+ obj = __Porffor_object_makeObject(obj);
517
+ if (Porffor.rawType(obj) == Porffor.TYPES.object) {
518
+ const objKeys: any[] = __Object_getOwnPropertyNames(obj);
519
+ for (const x of objKeys) Porffor.array.fastPush(out, x);
488
520
  }
489
521
  }
490
522
 
@@ -495,6 +527,7 @@ export const __Object_getOwnPropertySymbols = (obj: any): any[] => {
495
527
  if (obj == null) throw new TypeError('Argument is nullish, expected object');
496
528
  const out: any[] = Porffor.allocate();
497
529
 
530
+ obj = __Porffor_object_makeObject(obj);
498
531
  const t: i32 = Porffor.rawType(obj);
499
532
  if (t == Porffor.TYPES.object) {
500
533
  let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
@@ -132,16 +132,24 @@ local.set ${key}`;
132
132
  }
133
133
 
134
134
  out.length = i;
135
- } else if (Porffor.fastOr(
136
- t == Porffor.TYPES.array,
137
- t == Porffor.TYPES.bytestring,
138
- t == Porffor.TYPES.string
139
- )) {
140
- const len: i32 = target.length;
141
- out.length = len;
142
-
143
- for (let i: i32 = 0; i < len; i++) {
144
- out[i] = __Number_prototype_toString(i);
135
+ } else {
136
+ if (Porffor.fastOr(
137
+ t == Porffor.TYPES.array,
138
+ t == Porffor.TYPES.bytestring,
139
+ t == Porffor.TYPES.string
140
+ )) {
141
+ const len: i32 = obj.length;
142
+ out.length = len;
143
+
144
+ for (let i: i32 = 0; i < len; i++) {
145
+ out[i] = __Number_prototype_toString(i);
146
+ }
147
+ }
148
+
149
+ target = __Porffor_object_getObject(target);
150
+ if (Porffor.rawType(target) == Porffor.TYPES.object) {
151
+ const objKeys: any[] = __Reflect_ownKeys(target);
152
+ for (const x of objKeys) Porffor.array.fastPush(out, x);
145
153
  }
146
154
  }
147
155