porffor 0.24.12 → 0.24.14

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.
@@ -114,11 +114,6 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
114
114
  params.push(valtypeBinary, Valtype.i32);
115
115
  }
116
116
 
117
- if (inst.at(-1) === 'constr') {
118
- inst.pop();
119
- params.unshift(Valtype.i32);
120
- }
121
-
122
117
  let returns = [ valtypeBinary, Valtype.i32 ];
123
118
  if (inst.at(-1) === 'no_type_return') {
124
119
  inst.pop();
@@ -172,8 +167,9 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
172
167
  const func = funcs[i];
173
168
  let name = func.name;
174
169
 
175
- const typedParams = !func.internal || func.typedParams;
176
- let argc = Math.floor(typedParams ? func.params.length / 2 : func.params.length);
170
+ let argc = func.params.length;
171
+ if (func.constr) argc -= 4;
172
+ if (!func.internal || func.typedParams) argc = Math.floor(argc / 2);
177
173
 
178
174
  // hack: argc-- for prototype methods to remove _this hack from count
179
175
  if (name.includes('_prototype_')) argc--;
@@ -181,7 +177,7 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
181
177
  bytes.push(argc % 256, (argc / 256 | 0) % 256);
182
178
 
183
179
  let flags = 0b00000000; // 8 flag bits
184
- if (func.returnType != null) flags |= 0b1;
180
+ if (func.returnType != null) flags |= 0b01;
185
181
  if (func.constr) flags |= 0b10;
186
182
  bytes.push(flags);
187
183
 
@@ -198,10 +198,24 @@ i32.const 128
198
198
  return`;
199
199
  }
200
200
 
201
- Porffor.wasm`
201
+ const funcFlags: i32 = Porffor.funcLut.flags(get);
202
+ if (funcFlags & 0b10) {
203
+ // constructor func, add new.target, this args
204
+ Porffor.wasm`
205
+ f64.const 0
206
+ i32.const 0
207
+ local.get ${_this}
208
+ f64.convert_i32_u
209
+ local.get ${_this+1}
210
+ local.get ${get}
211
+ call_indirect 2 0
212
+ return`;
213
+ } else {
214
+ Porffor.wasm`
202
215
  local.get ${get}
203
216
  call_indirect 0 0
204
217
  return`;
218
+ }
205
219
  }
206
220
 
207
221
  // data descriptor
@@ -262,11 +276,26 @@ export const __Porffor_object_set = (_this: object, key: any, value: any): any =
262
276
  return value;
263
277
  }
264
278
 
279
+ const funcFlags: i32 = Porffor.funcLut.flags(set);
280
+ if (funcFlags & 0b10) {
281
+ // constructor func, add new.target, this args
282
+ Porffor.wasm`
283
+ f64.const 0
284
+ i32.const 0
285
+ local.get ${_this}
286
+ f64.convert_i32_u
287
+ i32.const 7
288
+ local.get ${value}
289
+ local.get ${value+1}
290
+ local.get ${set}
291
+ call_indirect 3 0`;
292
+ } else {
265
293
  Porffor.wasm`
266
294
  local.get ${value}
267
295
  local.get ${value+1}
268
296
  local.get ${set}
269
297
  call_indirect 1 0`;
298
+ }
270
299
 
271
300
  return value;
272
301
  }
@@ -1,6 +1,6 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
- export const __ArrayBuffer_isView = function (value: any): boolean {
3
+ export const __ArrayBuffer_isView = (value: any): boolean => {
4
4
  if (value.buffer) return true;
5
5
  return false;
6
6
  };
@@ -516,17 +516,17 @@ export const __Porffor_dirObject = (obj: any, colors: boolean, depth: i32, showH
516
516
 
517
517
  printStatic('{ ');
518
518
 
519
- const keys = __Map_prototype_keys(obj);
519
+ const keys = __Object_keys(obj);
520
520
  const keysLen = keys.length - 1;
521
521
  for (let i = 0; i <= keysLen; i++) {
522
522
  const key = keys[i];
523
523
  __Porffor_consolePrint(key);
524
524
  printStatic(': ');
525
525
 
526
- const value = __Map_prototype_get(obj, key);
526
+ const value = __Porffor_object_get(obj, key);
527
527
  __Porffor_dirObject(value, colors, depth - 1, showHidden);
528
528
 
529
- if (i != keysLen) printStatic(',');
529
+ if (i != keysLen) printStatic(', ');
530
530
  }
531
531
 
532
532
  printStatic(' }');
@@ -1056,6 +1056,21 @@ export const BuiltinFuncs = function() {
1056
1056
  ]
1057
1057
  };
1058
1058
 
1059
+ this.__Porffor_funcLut_flags = {
1060
+ params: [ Valtype.i32 ],
1061
+ returns: [ Valtype.i32 ],
1062
+ returnType: TYPES.number,
1063
+ wasm: (scope, { allocPage }) => [
1064
+ [ Opcodes.local_get, 0 ],
1065
+ ...number(128, Valtype.i32),
1066
+ [ Opcodes.i32_mul ],
1067
+ ...number(2, Valtype.i32),
1068
+ [ Opcodes.i32_add ],
1069
+ [ Opcodes.i32_load8_u, 0, ...unsignedLEB128(allocPage(scope, 'func lut') * pageSize) ]
1070
+ ],
1071
+ table: true
1072
+ };
1073
+
1059
1074
  this.__Porffor_funcLut_length = {
1060
1075
  params: [ Valtype.i32 ],
1061
1076
  returns: [ Valtype.i32 ],
@@ -189,6 +189,8 @@ export default function({ builtinFuncs }, Prefs) {
189
189
  });
190
190
  }
191
191
 
192
+ object('globalThis', {})
193
+
192
194
  if (Prefs.logMissingObjects) for (const x of Object.keys(builtinFuncs).concat(Object.keys(this))) {
193
195
  if (!x.startsWith('__')) continue;
194
196