porffor 0.30.7 → 0.30.9

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.
@@ -0,0 +1,15 @@
1
+ const underlyingFuncObjs: Map = new Map();
2
+ 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 = Porffor.allocate();
8
+ underlyingFuncObjs.set(funcI32, underlying);
9
+ }
10
+
11
+ return underlying;
12
+ }
13
+
14
+ return obj;
15
+ };
@@ -16,19 +16,22 @@ import type {} from './porffor.d.ts';
16
16
  // enumerable - 0b0100
17
17
  // writable - 0b1000
18
18
 
19
- export const __Porffor_object_preventExtensions = (obj: object): void => {
19
+ export const __Porffor_object_preventExtensions = (obj: any): void => {
20
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
20
21
  let rootFlags: i32 = Porffor.wasm.i32.load8_u(obj, 0, 4);
21
22
  rootFlags |= 0b0001;
22
23
  Porffor.wasm.i32.store8(obj, rootFlags, 0, 4);
23
24
  };
24
25
 
25
- export const __Porffor_object_isInextensible = (obj: object): boolean => {
26
+ export const __Porffor_object_isInextensible = (obj: any): boolean => {
27
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
26
28
  const out: boolean = Porffor.wasm.i32.load8_u(obj, 0, 4) & 0b0001;
27
29
  return out;
28
30
  };
29
31
 
30
32
 
31
- export const __Porffor_object_overrideAllFlags = (obj: object, overrideOr: i32, overrideAnd: i32): void => {
33
+ export const __Porffor_object_overrideAllFlags = (obj: any, overrideOr: i32, overrideAnd: i32): void => {
34
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
32
35
  let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
33
36
 
34
37
  const size: i32 = Porffor.wasm.i32.load(obj, 0, 0);
@@ -41,7 +44,8 @@ export const __Porffor_object_overrideAllFlags = (obj: object, overrideOr: i32,
41
44
  }
42
45
  };
43
46
 
44
- export const __Porffor_object_checkAllFlags = (obj: object, dataAnd: i32, accessorAnd: i32, dataExpected: i32, accessorExpected: i32): boolean => {
47
+ export const __Porffor_object_checkAllFlags = (obj: any, dataAnd: i32, accessorAnd: i32, dataExpected: i32, accessorExpected: i32): boolean => {
48
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
45
49
  let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
46
50
 
47
51
  const size: i32 = Porffor.wasm.i32.load(obj, 0, 0);
@@ -101,8 +105,9 @@ export const __Porffor_object_accessorSet = (entryPtr: i32): Function => {
101
105
  };
102
106
 
103
107
 
104
- export const __Porffor_object_lookup = (obj: object, target: any): i32 => {
108
+ export const __Porffor_object_lookup = (obj: any, target: any): i32 => {
105
109
  if (Porffor.wasm`local.get ${obj}` == 0) return -1;
110
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
106
111
 
107
112
  const targetType: i32 = Porffor.wasm`local.get ${target+1}`;
108
113
 
@@ -171,14 +176,9 @@ f64.convert_i32_u
171
176
  i32.const 1
172
177
  return`;
173
178
  }
174
-
175
- // undefined
176
- Porffor.wasm`
177
- f64.const 0
178
- i32.const 128
179
- return`;
180
179
  }
181
180
 
181
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
182
182
  const entryPtr: i32 = __Porffor_object_lookup(obj, key);
183
183
  if (entryPtr == -1) {
184
184
  Porffor.wasm`
@@ -244,9 +244,10 @@ export const __Porffor_object_writeKey = (ptr: i32, key: any): void => {
244
244
  Porffor.wasm.i32.store(ptr, keyEnc, 0, 0);
245
245
  };
246
246
 
247
- export const __Porffor_object_set = (obj: object, key: any, value: any): any => {
247
+ export const __Porffor_object_set = (obj: any, key: any, value: any): any => {
248
248
  if (Porffor.wasm`local.get ${obj}` == 0) throw new TypeError('Cannot set property of null');
249
249
 
250
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
250
251
  let entryPtr: i32 = __Porffor_object_lookup(obj, key);
251
252
  let flags: i32;
252
253
  if (entryPtr == -1) {
@@ -326,7 +327,8 @@ export const __Porffor_object_set = (obj: object, key: any, value: any): any =>
326
327
  return value;
327
328
  };
328
329
 
329
- export const __Porffor_object_define = (obj: object, key: any, value: any, flags: i32): void => {
330
+ export const __Porffor_object_define = (obj: any, key: any, value: any, flags: i32): void => {
331
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
330
332
  let entryPtr: i32 = __Porffor_object_lookup(obj, key);
331
333
  if (entryPtr == -1) {
332
334
  // add new entry
@@ -393,6 +395,23 @@ local.set ${err}`;
393
395
 
394
396
  export const __Porffor_object_delete = (obj: any, key: any): boolean => {
395
397
  if (Porffor.wasm`local.get ${obj}` == 0) throw new TypeError('Cannot delete property of null');
398
+
399
+ if (Porffor.wasm`local.get ${obj+1}` == Porffor.TYPES.function) {
400
+ let tmp: bytestring = '';
401
+ tmp = 'name';
402
+ if (key == tmp) {
403
+ __Porffor_funcLut_deleteName(obj);
404
+ return true;
405
+ }
406
+
407
+ tmp = 'length';
408
+ if (key == tmp) {
409
+ __Porffor_funcLut_deleteLength(obj);
410
+ return true;
411
+ }
412
+ }
413
+
414
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
396
415
  if (Porffor.rawType(obj) != Porffor.TYPES.object) {
397
416
  // todo: support non-pure objects
398
417
  return true;
@@ -458,6 +477,15 @@ export const __Porffor_object_isObject = (arg: any): boolean => {
458
477
  );
459
478
  };
460
479
 
480
+ export const __Porffor_object_isObjectOrNull = (arg: any): boolean => {
481
+ const t: i32 = Porffor.wasm`local.get ${arg+1}`;
482
+ return Porffor.fastAnd(
483
+ t > 0x05,
484
+ t != Porffor.TYPES.string,
485
+ t != Porffor.TYPES.bytestring,
486
+ );
487
+ };
488
+
461
489
  export const __Porffor_object_isObjectOrSymbol = (arg: any): boolean => {
462
490
  const t: i32 = Porffor.wasm`local.get ${arg+1}`;
463
491
  return Porffor.fastAnd(
@@ -174,10 +174,10 @@ export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
174
174
  let tmp: bytestring = '';
175
175
 
176
176
  tmp = 'name';
177
- if (p == tmp) return true;
177
+ if (p == tmp) return !__Porffor_funcLut_isNameDeleted(_this);
178
178
 
179
179
  tmp = 'length';
180
- if (p == tmp) return true;
180
+ if (p == tmp) return !__Porffor_funcLut_isLengthDeleted(_this);
181
181
 
182
182
  return false;
183
183
  }
@@ -603,13 +603,12 @@ export const __Object_defineProperties = (target: any, props: any) => {
603
603
  };
604
604
 
605
605
  export const __Object_create = (proto: any, props: any) => {
606
- if (!Porffor.object.isObject(proto)) {
607
- if (proto !== null) throw new TypeError('Prototype should be an object or null');
608
- }
606
+ if (!Porffor.object.isObjectOrNull(proto)) throw new TypeError('Prototype should be an object or null');
609
607
 
610
608
  const out: object = {};
611
609
 
612
- // todo: set prototype when supported
610
+ // set prototype
611
+ out.__proto__ = proto;
613
612
 
614
613
  if (props !== undefined) __Object_defineProperties(out, props);
615
614
 
@@ -635,6 +634,34 @@ export const __Object_groupBy = (items: any, callbackFn: any) => {
635
634
  };
636
635
 
637
636
 
637
+ export const __Object_getPrototypeOf = (obj: any) => {
638
+ if (obj == null) throw new TypeError('Object is nullish, expected object');
639
+
640
+ // todo: support non-pure-objects
641
+ if (Porffor.rawType(obj) != Porffor.TYPES.object) {
642
+ return {};
643
+ }
644
+
645
+ return obj.__proto__;
646
+ };
647
+
648
+ export const __Object_setPrototypeOf = (obj: any, proto: any) => {
649
+ if (obj == null) throw new TypeError('Object is nullish, expected object');
650
+ if (!Porffor.object.isObjectOrNull(proto)) throw new TypeError('Prototype should be an object or null');
651
+
652
+ // todo: support non-pure-objects
653
+ if (Porffor.rawType(obj) != Porffor.TYPES.object) {
654
+ return obj;
655
+ }
656
+
657
+ // todo: throw when this fails?
658
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf#exceptions
659
+ obj.__proto__ = proto;
660
+
661
+ return obj;
662
+ };
663
+
664
+
638
665
  export const __Object_prototype_toString = (_this: any) => {
639
666
  let out: bytestring = Porffor.allocate();
640
667
 
@@ -60,6 +60,7 @@ type PorfforGlobal = {
60
60
  isEnumerable(entryPtr: i32): boolean;
61
61
 
62
62
  isObject(arg: any): boolean;
63
+ isObjectOrNull(arg: any): boolean;
63
64
  isObjectOrSymbol(arg: any): boolean;
64
65
 
65
66
  expr: {
@@ -66,6 +66,23 @@ export const __Reflect_preventExtensions = (target: any) => {
66
66
  }
67
67
  };
68
68
 
69
+ export const __Reflect_getPrototypeOf = (target: any) => {
70
+ if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
71
+
72
+ return Object.getPrototypeOf(target);
73
+ };
74
+
75
+ export const __Reflect_setPrototypeOf = (target: any, proto: any) => {
76
+ if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
77
+
78
+ try {
79
+ Object.setPrototypeOf(target, proto);
80
+ return true;
81
+ } catch {
82
+ return false;
83
+ }
84
+ };
85
+
69
86
  export const __Reflect_ownKeys = (target: any) => {
70
87
  if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
71
88
 
@@ -1090,5 +1090,65 @@ export const BuiltinFuncs = function() {
1090
1090
  table: true
1091
1091
  };
1092
1092
 
1093
+ this.__Porffor_funcLut_deleteLength = {
1094
+ params: [ Valtype.i32 ],
1095
+ returns: [],
1096
+ wasm: (scope, { allocPage }) => [
1097
+ [ Opcodes.local_get, 0 ],
1098
+ ...number(128, Valtype.i32),
1099
+ [ Opcodes.i32_mul ],
1100
+ ...number(2, Valtype.i32),
1101
+ [ Opcodes.i32_add ],
1102
+ ...number(0, Valtype.i32),
1103
+ [ Opcodes.i32_store16, 0, ...unsignedLEB128(allocPage(scope, 'func lut') * pageSize) ],
1104
+
1105
+ [ Opcodes.local_get, 0 ],
1106
+ ...number(1, Valtype.i32),
1107
+ [ Opcodes.i32_store8, 0, ...unsignedLEB128(allocPage(scope, 'func length deletion table') * pageSize) ]
1108
+ ],
1109
+ table: true
1110
+ };
1111
+
1112
+ this.__Porffor_funcLut_deleteName = {
1113
+ params: [ Valtype.i32 ],
1114
+ returns: [],
1115
+ wasm: (scope, { allocPage }) => [
1116
+ [ Opcodes.local_get, 0 ],
1117
+ ...number(128, Valtype.i32),
1118
+ [ Opcodes.i32_mul ],
1119
+ ...number(5, Valtype.i32),
1120
+ [ Opcodes.i32_add ],
1121
+ ...number(0, Valtype.i32),
1122
+ [ Opcodes.i32_store, 0, ...unsignedLEB128(allocPage(scope, 'func lut') * pageSize) ],
1123
+
1124
+ [ Opcodes.local_get, 0 ],
1125
+ ...number(1, Valtype.i32),
1126
+ [ Opcodes.i32_store8, 0, ...unsignedLEB128(allocPage(scope, 'func name deletion table') * pageSize) ],
1127
+ ],
1128
+ table: true
1129
+ };
1130
+
1131
+ this.__Porffor_funcLut_isLengthDeleted = {
1132
+ params: [ Valtype.i32 ],
1133
+ returns: [ Valtype.i32 ],
1134
+ returnType: TYPES.boolean,
1135
+ wasm: (scope, { allocPage }) => [
1136
+ [ Opcodes.local_get, 0 ],
1137
+ [ Opcodes.i32_load8_u, 0, ...unsignedLEB128(allocPage(scope, 'func length deletion table') * pageSize) ]
1138
+ ],
1139
+ table: true
1140
+ };
1141
+
1142
+ this.__Porffor_funcLut_isNameDeleted = {
1143
+ params: [ Valtype.i32 ],
1144
+ returns: [ Valtype.i32 ],
1145
+ returnType: TYPES.boolean,
1146
+ wasm: (scope, { allocPage }) => [
1147
+ [ Opcodes.local_get, 0 ],
1148
+ [ Opcodes.i32_load8_u, 0, ...unsignedLEB128(allocPage(scope, 'func name deletion table') * pageSize) ]
1149
+ ],
1150
+ table: true
1151
+ };
1152
+
1093
1153
  PrecompiledBuiltins.BuiltinFuncs.call(this);
1094
1154
  };