porffor 0.55.22 → 0.55.24

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.
@@ -127,9 +127,9 @@ export const __Porffor_bigint_fromString = (n: string|bytestring): bigint => {
127
127
  return __Porffor_bigint_fromDigits(negative, result);
128
128
  };
129
129
 
130
- export const __Porffor_bigint_toString = (x: number, radix: any): string => {
130
+ export const __Porffor_bigint_toString = (x: number, radix: any): string|bytestring => {
131
131
  // todo: actually use bigint
132
- return __Number_prototype_toFixed(__Porffor_bigint_toNumber(x), radix);
132
+ return __Number_prototype_toString(Math.trunc(__Porffor_bigint_toNumber(x)), radix);
133
133
  };
134
134
 
135
135
  // todo: hook up all funcs below to codegen
@@ -181,7 +181,7 @@ export const __Porffor_print = (arg: any, colors: boolean = true, depth: number
181
181
 
182
182
  case Porffor.TYPES.function:
183
183
  Porffor.printStatic('[Function ');
184
- __Porffor_printString(__Porffor_funcLut_name(arg));
184
+ __Porffor_printString(__Porffor_funcLut_name(arg) || '(anonymous)');
185
185
  Porffor.printStatic(']');
186
186
  return;
187
187
 
@@ -13,7 +13,7 @@ export const __Function_prototype_toLocaleString = (_this: Function) => __Functi
13
13
 
14
14
  export const __Function_prototype_apply = (_this: Function, thisArg: any, argsArray: any) => {
15
15
  argsArray = Array.from(argsArray ?? []);
16
- return Reflect.apply(_this, thisArg, argsArray);
16
+ return Porffor.call(_this, argsArray, thisArg, null);
17
17
  };
18
18
 
19
19
  export const __Function_prototype_bind = (_this: Function, thisArg: any, argsArray: any) => {
@@ -3,8 +3,7 @@ import type {} from './porffor.d.ts';
3
3
  export const Object = function (value: any): any {
4
4
  if (value == null) {
5
5
  // if nullish, return new empty object
6
- const obj: object = Porffor.allocate();
7
- return obj;
6
+ return Porffor.allocate() as object;
8
7
  }
9
8
 
10
9
  // primitives into primitive objects
@@ -23,11 +22,11 @@ export const __Object_keys = (obj: any): any[] => {
23
22
  obj = __Porffor_object_underlying(obj);
24
23
  const t: i32 = Porffor.rawType(obj);
25
24
  if (t == Porffor.TYPES.object) {
26
- let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
27
- const endPtr: i32 = ptr + Porffor.wasm.i32.load(obj, 0, 0) * 14;
25
+ let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
26
+ const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
28
27
 
29
28
  let i: i32 = 0;
30
- for (; ptr < endPtr; ptr += 14) {
29
+ for (; ptr < endPtr; ptr += 18) {
31
30
  if (!Porffor.object.isEnumerable(ptr)) continue;
32
31
 
33
32
  let key: any;
@@ -35,7 +34,7 @@ export const __Object_keys = (obj: any): any[] => {
35
34
  local msb i32
36
35
  local.get ${ptr}
37
36
  i32.to_u
38
- i32.load 0 0
37
+ i32.load 0 4
39
38
  local.set raw
40
39
 
41
40
  local.get raw
@@ -79,11 +78,11 @@ export const __Object_values = (obj: any): any[] => {
79
78
  obj = __Porffor_object_underlying(obj);
80
79
  const t: i32 = Porffor.rawType(obj);
81
80
  if (t == Porffor.TYPES.object) {
82
- let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
83
- const endPtr: i32 = ptr + Porffor.wasm.i32.load(obj, 0, 0) * 14;
81
+ let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
82
+ const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
84
83
 
85
84
  let i: i32 = 0;
86
- for (; ptr < endPtr; ptr += 14) {
85
+ for (; ptr < endPtr; ptr += 18) {
87
86
  if (!Porffor.object.isEnumerable(ptr)) continue;
88
87
 
89
88
  let val: any;
@@ -92,11 +91,11 @@ local.get ${ptr}
92
91
  i32.to_u
93
92
  local.tee ptr32
94
93
 
95
- f64.load 0 4
94
+ f64.load 0 8
96
95
  local.set ${val}
97
96
 
98
97
  local.get ptr32
99
- i32.load8_u 0 13
98
+ i32.load8_u 0 17
100
99
  local.set ${val+1}`;
101
100
 
102
101
  out[i++] = val;
@@ -144,16 +143,17 @@ export const __Object_fromEntries = (iterable: any): object => {
144
143
 
145
144
 
146
145
  export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
146
+ if (_this == null) throw new TypeError('Argument is nullish, expected object');
147
147
  const p: any = ecma262.ToPropertyKey(prop);
148
148
 
149
149
  const t: i32 = Porffor.rawType(_this);
150
150
  if (t == Porffor.TYPES.object) {
151
- return Porffor.object.lookup(_this, p) != -1;
151
+ return Porffor.object.lookup(_this, p, __Porffor_object_hash(p)) != -1;
152
152
  }
153
153
 
154
154
  const obj: any = __Porffor_object_underlying(_this);
155
155
  if (Porffor.rawType(obj) == Porffor.TYPES.object) {
156
- if (Porffor.object.lookup(obj, p) != -1) return true;
156
+ if (Porffor.object.lookup(obj, p, __Porffor_object_hash(p)) != -1) return true;
157
157
  }
158
158
 
159
159
  const keys: any[] = __Object_keys(_this);
@@ -165,17 +165,19 @@ export const __Object_hasOwn = (obj: any, prop: any): boolean => {
165
165
  };
166
166
 
167
167
  export const __Porffor_object_in = (obj: any, prop: any): boolean => {
168
+ // todo: throw if obj is not an object
169
+
168
170
  if (__Object_prototype_hasOwnProperty(obj, prop)) {
169
171
  return true;
170
172
  }
171
173
 
172
174
  let lastProto = obj;
173
175
  while (true) {
174
- obj = obj.__proto__;
176
+ obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.rawType(obj));
175
177
  if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
176
- lastProto = obj;
177
178
 
178
179
  if (__Object_prototype_hasOwnProperty(obj, prop)) return true;
180
+ lastProto = obj;
179
181
  }
180
182
 
181
183
  return false;
@@ -192,11 +194,11 @@ export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: a
192
194
 
193
195
  let lastProto = obj;
194
196
  while (true) {
195
- obj = obj.__proto__;
197
+ obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.rawType(obj));
196
198
  if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
197
- lastProto = obj;
198
199
 
199
200
  if (obj === checkProto) return true;
201
+ lastProto = obj;
200
202
  }
201
203
 
202
204
  return false;
@@ -234,10 +236,12 @@ export const __Porffor_object_assignAll = (target: any, source: any): any => {
234
236
 
235
237
 
236
238
  export const __Object_prototype_propertyIsEnumerable = (_this: any, prop: any) => {
239
+ if (_this == null) throw new TypeError('Argument is nullish, expected object');
240
+
237
241
  const p: any = ecma262.ToPropertyKey(prop);
238
242
 
239
243
  if (Porffor.rawType(_this) == Porffor.TYPES.object) {
240
- const entryPtr: i32 = Porffor.object.lookup(_this, p);
244
+ const entryPtr: i32 = Porffor.object.lookup(_this, p, __Porffor_object_hash(p));
241
245
  if (entryPtr == -1) return false;
242
246
 
243
247
  return Porffor.object.isEnumerable(entryPtr);
@@ -245,7 +249,7 @@ export const __Object_prototype_propertyIsEnumerable = (_this: any, prop: any) =
245
249
 
246
250
  const obj: any = __Porffor_object_underlying(_this);
247
251
  if (Porffor.rawType(obj) == Porffor.TYPES.object) {
248
- const entryPtr: i32 = Porffor.object.lookup(obj, p);
252
+ const entryPtr: i32 = Porffor.object.lookup(obj, p, __Porffor_object_hash(p));
249
253
  if (entryPtr != -1) return Porffor.object.isEnumerable(entryPtr);
250
254
  }
251
255
 
@@ -275,11 +279,10 @@ export const __Object_is = (x: any, y: any): boolean => {
275
279
 
276
280
  export const __Object_preventExtensions = (obj: any): any => {
277
281
  Porffor.object.preventExtensions(obj);
278
-
279
282
  return obj;
280
283
  };
281
284
 
282
- export const __Object_isExtensible = (obj: any): any => {
285
+ export const __Object_isExtensible = (obj: any): boolean => {
283
286
  if (!Porffor.object.isObject(obj)) {
284
287
  return false;
285
288
  }
@@ -298,7 +301,7 @@ export const __Object_freeze = (obj: any): any => {
298
301
  return obj;
299
302
  };
300
303
 
301
- export const __Object_isFrozen = (obj: any): any => {
304
+ export const __Object_isFrozen = (obj: any): boolean => {
302
305
  if (!Porffor.object.isObject(obj)) {
303
306
  return true;
304
307
  }
@@ -323,7 +326,7 @@ export const __Object_seal = (obj: any): any => {
323
326
  return obj;
324
327
  };
325
328
 
326
- export const __Object_isSealed = (obj: any): any => {
329
+ export const __Object_isSealed = (obj: any): boolean => {
327
330
  if (!Porffor.object.isObject(obj)) {
328
331
  return true;
329
332
  }
@@ -339,9 +342,10 @@ export const __Object_isSealed = (obj: any): any => {
339
342
 
340
343
 
341
344
  export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|undefined => {
345
+ if (obj == null) throw new TypeError('Argument is nullish, expected object');
342
346
  const p: any = ecma262.ToPropertyKey(prop);
343
347
 
344
- const entryPtr: i32 = Porffor.object.lookup(obj, p);
348
+ const entryPtr: i32 = Porffor.object.lookup(obj, p, __Porffor_object_hash(p));
345
349
  if (entryPtr == -1) {
346
350
  if (Porffor.rawType(obj) == Porffor.TYPES.function) {
347
351
  // hack: function .name and .length
@@ -360,9 +364,8 @@ export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|u
360
364
  return undefined;
361
365
  }
362
366
 
367
+ const tail: i32 = Porffor.wasm.i32.load16_u(entryPtr, 0, 16);
363
368
  const out: object = {};
364
-
365
- const tail: i32 = Porffor.wasm.i32.load16_u(entryPtr, 0, 12);
366
369
  out.configurable = !!(tail & 0b0010);
367
370
  out.enumerable = !!(tail & 0b0100);
368
371
 
@@ -374,7 +377,7 @@ export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|u
374
377
  }
375
378
 
376
379
  // data descriptor
377
- const value: any = Porffor.wasm.f64.load(entryPtr, 0, 4);
380
+ const value: any = Porffor.wasm.f64.load(entryPtr, 0, 8);
378
381
  Porffor.wasm`
379
382
  local.get ${tail}
380
383
  i32.to_u
@@ -412,17 +415,17 @@ export const __Object_getOwnPropertyNames = (obj: any): any[] => {
412
415
  obj = __Porffor_object_underlying(obj);
413
416
  const t: i32 = Porffor.rawType(obj);
414
417
  if (t == Porffor.TYPES.object) {
415
- let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
416
- const endPtr: i32 = ptr + Porffor.wasm.i32.load(obj, 0, 0) * 14;
418
+ let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
419
+ const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
417
420
 
418
421
  let i: i32 = 0;
419
- for (; ptr < endPtr; ptr += 14) {
422
+ for (; ptr < endPtr; ptr += 18) {
420
423
  let key: any;
421
424
  Porffor.wasm`local raw i32
422
425
  local msb i32
423
426
  local.get ${ptr}
424
427
  i32.to_u
425
- i32.load 0 0
428
+ i32.load 0 4
426
429
  local.set raw
427
430
 
428
431
  local.get raw
@@ -467,17 +470,17 @@ export const __Object_getOwnPropertySymbols = (obj: any): any[] => {
467
470
  obj = __Porffor_object_underlying(obj);
468
471
  const t: i32 = Porffor.rawType(obj);
469
472
  if (t == Porffor.TYPES.object) {
470
- let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
471
- const endPtr: i32 = ptr + Porffor.wasm.i32.load(obj, 0, 0) * 14;
473
+ let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
474
+ const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
472
475
 
473
476
  let i: i32 = 0;
474
- for (; ptr < endPtr; ptr += 14) {
477
+ for (; ptr < endPtr; ptr += 18) {
475
478
  let key: any;
476
479
  Porffor.wasm`local raw i32
477
480
  local msb i32
478
481
  local.get ${ptr}
479
482
  i32.to_u
480
- i32.load 0 0
483
+ i32.load 0 4
481
484
  local.set raw
482
485
 
483
486
  local.get raw
@@ -609,9 +612,7 @@ export const __Object_create = (proto: any, props: any): object => {
609
612
  if (!Porffor.object.isObjectOrNull(proto)) throw new TypeError('Prototype should be an object or null');
610
613
 
611
614
  const out: object = {};
612
-
613
- // set prototype
614
- out.__proto__ = proto;
615
+ Porffor.object.setPrototype(out, proto);
615
616
 
616
617
  if (props !== undefined) __Object_defineProperties(out, props);
617
618
 
@@ -639,30 +640,24 @@ export const __Object_groupBy = (items: any, callbackFn: any): object => {
639
640
 
640
641
  export const __Object_getPrototypeOf = (obj: any): any => {
641
642
  if (obj == null) throw new TypeError('Object is nullish, expected object');
642
-
643
- return obj.__proto__;
643
+ return Porffor.object.getPrototypeWithHidden(obj, Porffor.rawType(obj));
644
644
  };
645
645
 
646
646
  export const __Object_setPrototypeOf = (obj: any, proto: any): any => {
647
647
  if (obj == null) throw new TypeError('Object is nullish, expected object');
648
648
  if (!Porffor.object.isObjectOrNull(proto)) throw new TypeError('Prototype should be an object or null');
649
649
 
650
- // todo: support non-pure-objects
651
- if (Porffor.rawType(obj) != Porffor.TYPES.object) {
652
- return obj;
653
- }
654
-
655
- // todo: throw when this fails?
656
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf#exceptions
657
- obj.__proto__ = proto;
650
+ // todo: if inextensible, throw if proto != current prototype
658
651
 
652
+ Porffor.object.setPrototype(obj, proto);
659
653
  return obj;
660
654
  };
661
655
 
662
656
  export const __Object_prototype_isPrototypeOf = (_this: any, obj: any) => {
663
657
  if (_this == null) throw new TypeError('This is nullish, expected object');
664
658
 
665
- return _this == obj.__proto__;
659
+ if (!Porffor.object.isObject(obj)) return false;
660
+ return _this == Porffor.object.getPrototypeWithHidden(obj, Porffor.rawType(obj));
666
661
  };
667
662
 
668
663
 
@@ -674,7 +669,7 @@ export const __Object_prototype_toString = (_this: any) => {
674
669
  let ovr: any = obj.toString;
675
670
  if (Porffor.rawType(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_toString) return ovr.call(_this);
676
671
 
677
- const entryPtr: i32 = Porffor.object.lookup(obj, 'toString');
672
+ const entryPtr: i32 = Porffor.object.lookup(obj, 'toString', __Porffor_object_hash('toString')); // todo: comptime
678
673
  if (entryPtr != -1) {
679
674
  ovr = Porffor.object.readValue(entryPtr);
680
675
  if (Porffor.rawType(ovr) == Porffor.TYPES.function) return ovr.call(_this);
@@ -721,7 +716,7 @@ export const __Object_prototype_valueOf = (_this: any) => {
721
716
  let ovr: any = obj.valueOf;
722
717
  if (Porffor.rawType(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_valueOf) return ovr.call(_this);
723
718
 
724
- const entryPtr: i32 = Porffor.object.lookup(obj, 'valueOf');
719
+ const entryPtr: i32 = Porffor.object.lookup(obj, 'valueOf', __Porffor_object_hash('valueOf')); // todo: comptime
725
720
  if (entryPtr != -1) {
726
721
  ovr = Porffor.object.readValue(entryPtr);
727
722
  if (Porffor.rawType(ovr) == Porffor.TYPES.function) return ovr.call(_this);
@@ -0,0 +1,47 @@
1
+ export default ({ TYPES, TYPE_NAMES }) => {
2
+ let out = `// @porf --valtype=i32
3
+ export const __Porffor_object_getPrototypeWithHidden = (obj: any, trueType: i32): any => {
4
+ const objectProto: any = __Porffor_object_getPrototype(obj);
5
+ if (Porffor.rawType(objectProto) == Porffor.TYPES.empty) {
6
+ if (Porffor.comptime.flag\`hasFunc.#get___String_prototype\`) {
7
+ if (Porffor.fastOr(
8
+ trueType == Porffor.TYPES.string,
9
+ trueType == Porffor.TYPES.bytestring,
10
+ trueType == Porffor.TYPES.stringobject
11
+ )) return __String_prototype;
12
+ }
13
+
14
+ if (Porffor.comptime.flag\`hasFunc.#get___Number_prototype\`) {
15
+ if (Porffor.fastOr(
16
+ trueType == Porffor.TYPES.number,
17
+ trueType == Porffor.TYPES.numberobject
18
+ )) return __Number_prototype;
19
+ }
20
+
21
+ if (Porffor.comptime.flag\`hasFunc.#get___Boolean_prototype\`) {
22
+ if (Porffor.fastOr(
23
+ trueType == Porffor.TYPES.boolean,
24
+ trueType == Porffor.TYPES.booleanobject
25
+ )) return __Boolean_prototype;
26
+ }`;
27
+
28
+ for (const x in TYPES) {
29
+ if (['empty', 'undefined', 'string', 'bytestring', 'stringobject', 'number', 'numberobject', 'boolean', 'booleanobject'].includes(x)) continue;
30
+
31
+ const name = TYPE_NAMES[TYPES[x]];
32
+ out += `
33
+ if (Porffor.comptime.flag\`hasFunc.#get___${name}_prototype\`) {
34
+ if (trueType == Porffor.TYPES.${x}) return __${name}_prototype;
35
+ }`;
36
+ }
37
+
38
+ // if (trueType == Porffor.TYPES.function) return __Function_prototype;
39
+ out += `
40
+ return __Object_prototype;
41
+ }
42
+
43
+ return objectProto;
44
+ };`;
45
+
46
+ return out;
47
+ };
@@ -91,17 +91,17 @@ export const __Reflect_ownKeys = (target: any) => {
91
91
  target = __Porffor_object_underlying(target);
92
92
  const t: i32 = Porffor.rawType(target);
93
93
  if (t == Porffor.TYPES.object) {
94
- let ptr: i32 = Porffor.wasm`local.get ${target}` + 5;
95
- const endPtr: i32 = ptr + Porffor.wasm.i32.load(target, 0, 0) * 14;
94
+ let ptr: i32 = Porffor.wasm`local.get ${target}` + 8;
95
+ const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(target, 0, 0) * 18;
96
96
 
97
97
  let i: i32 = 0;
98
- for (; ptr < endPtr; ptr += 14) {
98
+ for (; ptr < endPtr; ptr += 18) {
99
99
  let key: any;
100
100
  Porffor.wasm`local raw i32
101
101
  local msb i32
102
102
  local.get ${ptr}
103
103
  i32.to_u
104
- i32.load 0 0
104
+ i32.load 0 4
105
105
  local.set raw
106
106
 
107
107
  local.get raw
@@ -156,6 +156,9 @@ export const __ecma262_ToString = (argument: unknown): any => {
156
156
  if (type == Porffor.TYPES.number) return __Number_prototype_toString(argument, 10);
157
157
 
158
158
  // 8. If argument is a BigInt, return BigInt::toString(argument, 10).
159
+ if (Porffor.comptime.flag`hasType.bigint`) {
160
+ if (type == Porffor.TYPES.bigint) return __Porffor_bigint_toString(argument, 10);
161
+ }
159
162
 
160
163
  // hack: StringObject -> String
161
164
  if (type == Porffor.TYPES.stringobject) {