porffor 0.60.11 → 0.60.12

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.
@@ -489,6 +489,9 @@ i32.load 0 4
489
489
  local.set ${obj}
490
490
  i32.load8_u 0 3
491
491
  local.set ${obj+1}`;
492
+
493
+ // if undefined, prototype is object.prototype
494
+ if (Porffor.type(obj) == Porffor.TYPES.undefined) obj = __Object_prototype;
492
495
  } else obj = __Porffor_object_getPrototype(obj);
493
496
  if (Porffor.type(obj) != Porffor.TYPES.object) obj = __Porffor_object_underlying(obj);
494
497
 
@@ -555,6 +558,9 @@ i32.load 0 4
555
558
  local.set ${obj}
556
559
  i32.load8_u 0 3
557
560
  local.set ${obj+1}`;
561
+
562
+ // if undefined, prototype is object.prototype
563
+ if (Porffor.type(obj) == Porffor.TYPES.undefined) obj = __Object_prototype;
558
564
  } else obj = __Porffor_object_getPrototype(obj);
559
565
  if (Porffor.type(obj) != Porffor.TYPES.object) obj = __Porffor_object_underlying(obj);
560
566
 
@@ -1,5 +1,14 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
+ // `eval` is invalid syntax so work around
4
+ export const _eval = (source: string) => {
5
+ throw new SyntaxError('Dynamic code evaluation is not supported');
6
+ };
7
+
8
+ export const Function = function (source: string) {
9
+ throw new SyntaxError('Dynamic code evaluation is not supported');
10
+ };
11
+
3
12
  export const __Function_prototype_toString = (_this: Function) => {
4
13
  const out: bytestring = Porffor.allocate();
5
14
 
@@ -23,7 +23,7 @@ export const __Porffor_object_getHiddenPrototype = (trueType: i32): any => {
23
23
  }`;
24
24
 
25
25
  for (const x in TYPES) {
26
- if (['undefined', 'string', 'bytestring', 'stringobject', 'number', 'numberobject', 'boolean', 'booleanobject'].includes(x)) continue;
26
+ if (['object', 'undefined', 'string', 'bytestring', 'stringobject', 'number', 'numberobject', 'boolean', 'booleanobject'].includes(x)) continue;
27
27
 
28
28
  const name = TYPE_NAMES[TYPES[x]];
29
29
  out += `
@@ -989,26 +989,16 @@ export const __Porffor_regex_interpret = (regexp: RegExp, input: i32, isTest: bo
989
989
  const sticky: boolean = (flags & 0b00100000) != 0;
990
990
 
991
991
  const inputLen: i32 = Porffor.wasm.i32.load(input, 0, 0);
992
- let searchStart: i32 = 0;
992
+ let lastIndex: i32 = 0;
993
993
  if (global || sticky) {
994
- searchStart = Porffor.wasm.i32.load16_u(regexp, 0, 8);
995
- }
996
-
997
- if (searchStart > inputLen) {
998
- if (global || sticky) Porffor.wasm.i32.store16(regexp, 0, 0, 8);
999
- return null;
994
+ lastIndex = Porffor.wasm.i32.load16_u(regexp, 0, 8);
1000
995
  }
1001
996
 
1002
997
  // todo: free all at the end (or statically allocate but = [] causes memory corruption)
1003
998
  const backtrackStack: i32[] = Porffor.allocate();
1004
999
  const captures: i32[] = Porffor.allocateBytes(6144);
1005
1000
 
1006
- for (let i: i32 = searchStart; i <= inputLen; i++) {
1007
- if (sticky && i != searchStart) {
1008
- if (isTest) return false;
1009
- return null;
1010
- }
1011
-
1001
+ for (let i: i32 = lastIndex; i <= inputLen; i++) {
1012
1002
  backtrackStack.length = 0;
1013
1003
  captures.length = 0;
1014
1004
 
@@ -1378,7 +1368,7 @@ export const __Porffor_regex_interpret = (regexp: RegExp, input: i32, isTest: bo
1378
1368
 
1379
1369
  const matchStart: i32 = i;
1380
1370
  if (global || sticky) {
1381
- Porffor.wasm.i32.store(regexp, finalSp, 0, 8);
1371
+ Porffor.wasm.i32.store16(regexp, finalSp, 0, 8); // write last index
1382
1372
  }
1383
1373
 
1384
1374
  const result: any[] = Porffor.allocateBytes(4096);
@@ -1404,10 +1394,16 @@ export const __Porffor_regex_interpret = (regexp: RegExp, input: i32, isTest: bo
1404
1394
 
1405
1395
  return result;
1406
1396
  }
1397
+
1398
+ if (sticky) { // sticky, do not go forward in string
1399
+ Porffor.wasm.i32.store16(regexp, 0, 0, 8); // failed, write 0 last index
1400
+ if (isTest) return false;
1401
+ return null;
1402
+ }
1407
1403
  }
1408
1404
 
1409
1405
  if (global || sticky) {
1410
- Porffor.wasm.i32.store(regexp, 0, 0, 8);
1406
+ Porffor.wasm.i32.store16(regexp, 0, 0, 8); // failed, write 0 last index
1411
1407
  }
1412
1408
 
1413
1409
  if (isTest) return false;
@@ -1419,6 +1415,10 @@ export const __RegExp_prototype_source$get = (_this: RegExp) => {
1419
1415
  return Porffor.wasm.i32.load(_this, 0, 0) as bytestring;
1420
1416
  };
1421
1417
 
1418
+ export const __RegExp_prototype_lastIndex$get = (_this: RegExp) => {
1419
+ return Porffor.wasm.i32.load16_u(_this, 0, 8);
1420
+ };
1421
+
1422
1422
  // 22.2.6.4 get RegExp.prototype.flags
1423
1423
  // https://tc39.es/ecma262/multipage/text-processing.html#sec-get-regexp.prototype.flags
1424
1424
  export const __RegExp_prototype_flags$get = (_this: RegExp) => {