porffor 0.22.3 → 0.22.5
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.
- package/compiler/builtins/object.ts +3 -4
- package/compiler/codegen.js +23 -2
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -50,7 +50,7 @@ if 127
|
|
50
50
|
|
51
51
|
local.get raw
|
52
52
|
i32.const 1073741823
|
53
|
-
i32.and
|
53
|
+
i32.and ;; unset 2 MSBs
|
54
54
|
else
|
55
55
|
i32.const 195
|
56
56
|
local.set ${key+1}
|
@@ -175,7 +175,6 @@ export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
|
|
175
175
|
};
|
176
176
|
|
177
177
|
export const __Object_hasOwn = (obj: any, prop: any) => {
|
178
|
-
// todo: not spec compliant lol
|
179
178
|
return __Object_prototype_hasOwnProperty(obj, prop);
|
180
179
|
};
|
181
180
|
|
@@ -483,7 +482,7 @@ if 127
|
|
483
482
|
|
484
483
|
local.get raw
|
485
484
|
i32.const 1073741823
|
486
|
-
i32.and
|
485
|
+
i32.and ;; unset 2 MSBs
|
487
486
|
else
|
488
487
|
i32.const 195
|
489
488
|
local.set ${key+1}
|
@@ -548,7 +547,7 @@ if 127
|
|
548
547
|
|
549
548
|
local.get raw
|
550
549
|
i32.const 1073741823
|
551
|
-
i32.and
|
550
|
+
i32.and ;; unset 2 MSBs
|
552
551
|
else
|
553
552
|
i32.const 195
|
554
553
|
local.set ${key+1}
|
package/compiler/codegen.js
CHANGED
@@ -1132,6 +1132,23 @@ const generateBinaryExp = (scope, decl, _global, _name) => {
|
|
1132
1132
|
return out;
|
1133
1133
|
}
|
1134
1134
|
|
1135
|
+
if (decl.operator === 'in') {
|
1136
|
+
// hack: a in b -> Object.hasOwn(b, a)
|
1137
|
+
// todo: not spec compliant, in should check prototype chain too (once we have it)
|
1138
|
+
|
1139
|
+
return generate(scope, {
|
1140
|
+
type: 'CallExpression',
|
1141
|
+
callee: {
|
1142
|
+
type: 'Identifier',
|
1143
|
+
name: '__Object_hasOwn'
|
1144
|
+
},
|
1145
|
+
arguments: [
|
1146
|
+
decl.right,
|
1147
|
+
decl.left
|
1148
|
+
]
|
1149
|
+
});
|
1150
|
+
}
|
1151
|
+
|
1135
1152
|
// opt: == null|undefined -> nullish
|
1136
1153
|
if (decl.operator === '==' || decl.operator === '!=') {
|
1137
1154
|
if (knownNullish(decl.right)) {
|
@@ -1441,6 +1458,7 @@ const getNodeType = (scope, node) => {
|
|
1441
1458
|
|
1442
1459
|
// check if this is a prototype function
|
1443
1460
|
// if so and there is only one impl (eg charCodeAt)
|
1461
|
+
// or all impls have the same return type
|
1444
1462
|
// use that return type as that is the only possibility
|
1445
1463
|
// (if non-matching type it would error out)
|
1446
1464
|
if (name.startsWith('__')) {
|
@@ -1448,7 +1466,10 @@ const getNodeType = (scope, node) => {
|
|
1448
1466
|
|
1449
1467
|
const func = spl[spl.length - 1];
|
1450
1468
|
const protoFuncs = Object.keys(prototypeFuncs).filter(x => x != TYPES.bytestring && prototypeFuncs[x][func] != null);
|
1451
|
-
if (
|
1469
|
+
if (
|
1470
|
+
protoFuncs.length === 1 ||
|
1471
|
+
(protoFuncs.length > 1 && protoFuncs.every(x => x.returnType === protoFuncs[0].returnType))
|
1472
|
+
) {
|
1452
1473
|
if (protoFuncs[0].returnType != null) return protoFuncs[0].returnType;
|
1453
1474
|
}
|
1454
1475
|
}
|
@@ -1513,7 +1534,7 @@ const getNodeType = (scope, node) => {
|
|
1513
1534
|
}
|
1514
1535
|
|
1515
1536
|
if (node.type === 'BinaryExpression') {
|
1516
|
-
if (['==', '===', '!=', '!==', '>', '>=', '<', '<=', 'instanceof'].includes(node.operator)) return TYPES.boolean;
|
1537
|
+
if (['==', '===', '!=', '!==', '>', '>=', '<', '<=', 'instanceof', 'in'].includes(node.operator)) return TYPES.boolean;
|
1517
1538
|
if (node.operator !== '+') return TYPES.number;
|
1518
1539
|
|
1519
1540
|
const leftType = getNodeType(scope, node.left);
|
package/package.json
CHANGED