porffor 0.35.3 → 0.36.0
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.
@@ -6,12 +6,16 @@ export const __Porffor_object_getObject = (obj: any): any => {
|
|
6
6
|
if (underlying == null) {
|
7
7
|
underlying = {};
|
8
8
|
|
9
|
-
|
10
|
-
const
|
11
|
-
|
9
|
+
// set prototype and prototype.constructor if constructor
|
10
|
+
const flags: i32 = __Porffor_funcLut_flags(funcI32);
|
11
|
+
if (flags & 0b10) { // constructor
|
12
|
+
const proto = {};
|
13
|
+
const key1: bytestring = 'prototype';
|
14
|
+
__Porffor_object_expr_initWithFlags(underlying, key1, proto, 0b1000);
|
12
15
|
|
13
|
-
|
14
|
-
|
16
|
+
const key2: bytestring = 'constructor';
|
17
|
+
__Porffor_object_expr_initWithFlags(proto, key2, obj, 0b1010);
|
18
|
+
}
|
15
19
|
|
16
20
|
underlyingFuncObjs.set(funcI32, underlying);
|
17
21
|
}
|
@@ -18,6 +18,7 @@ export const __Object_keys = (obj: any): any[] => {
|
|
18
18
|
if (obj == null) throw new TypeError('Argument is nullish, expected object');
|
19
19
|
const out: any[] = Porffor.allocate();
|
20
20
|
|
21
|
+
obj = __Porffor_object_getObject(obj);
|
21
22
|
const t: i32 = Porffor.rawType(obj);
|
22
23
|
if (t == Porffor.TYPES.object) {
|
23
24
|
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
|
@@ -82,9 +83,9 @@ local.set ${key}`;
|
|
82
83
|
|
83
84
|
export const __Object_values = (obj: any): any[] => {
|
84
85
|
if (obj == null) throw new TypeError('Argument is nullish, expected object');
|
85
|
-
|
86
86
|
const out: any[] = Porffor.allocate();
|
87
87
|
|
88
|
+
obj = __Porffor_object_getObject(obj);
|
88
89
|
const t: i32 = Porffor.rawType(obj);
|
89
90
|
if (t == Porffor.TYPES.object) {
|
90
91
|
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 5;
|
@@ -177,7 +178,7 @@ export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
|
|
177
178
|
const tmp2: bytestring = 'length';
|
178
179
|
if (p == tmp2) return !__Porffor_funcLut_isLengthDeleted(_this);
|
179
180
|
|
180
|
-
return
|
181
|
+
return Porffor.object.lookup(_this, p) != -1;
|
181
182
|
}
|
182
183
|
|
183
184
|
const keys: any[] = __Object_keys(_this);
|
@@ -193,10 +194,6 @@ export const __Porffor_object_in = (obj: any, prop: any) => {
|
|
193
194
|
return true;
|
194
195
|
}
|
195
196
|
|
196
|
-
if (Porffor.rawType(obj) != Porffor.TYPES.object) {
|
197
|
-
return false;
|
198
|
-
}
|
199
|
-
|
200
197
|
let lastProto = obj;
|
201
198
|
while (true) {
|
202
199
|
obj = obj.__proto__;
|
@@ -225,7 +222,6 @@ export const __Porffor_object_instanceof = (obj: any, constr: any) => {
|
|
225
222
|
if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
|
226
223
|
lastProto = obj;
|
227
224
|
|
228
|
-
console.log(obj === Object.prototype);
|
229
225
|
if (obj === checkProto) return true;
|
230
226
|
}
|
231
227
|
|
@@ -266,8 +262,8 @@ export const __Porffor_object_assignAll = (target: any, source: any) => {
|
|
266
262
|
export const __Object_prototype_propertyIsEnumerable = (_this: any, prop: any) => {
|
267
263
|
const p: any = ecma262.ToPropertyKey(prop);
|
268
264
|
|
269
|
-
const
|
270
|
-
if (
|
265
|
+
const obj: any = __Porffor_object_getObject(_this);
|
266
|
+
if (Porffor.rawType(obj) == Porffor.TYPES.object) {
|
271
267
|
const entryPtr: i32 = Porffor.object.lookup(_this, p);
|
272
268
|
if (entryPtr == -1) return false;
|
273
269
|
|
@@ -366,23 +362,24 @@ export const __Object_isSealed = (obj: any): any => {
|
|
366
362
|
export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): any => {
|
367
363
|
const p: any = ecma262.ToPropertyKey(prop);
|
368
364
|
|
369
|
-
const
|
370
|
-
if (
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
365
|
+
const entryPtr: i32 = Porffor.object.lookup(obj, p);
|
366
|
+
if (entryPtr == -1) {
|
367
|
+
if (Porffor.rawType(obj) == Porffor.TYPES.function) {
|
368
|
+
// hack: function .name and .length
|
369
|
+
const v = obj[p];
|
370
|
+
if (v != null) {
|
371
|
+
const out: object = {};
|
372
|
+
out.writable = false;
|
373
|
+
out.enumerable = false;
|
374
|
+
out.configurable = true;
|
375
|
+
|
376
|
+
out.value = v;
|
377
|
+
return out;
|
378
|
+
}
|
381
379
|
}
|
382
|
-
}
|
383
380
|
|
384
|
-
|
385
|
-
|
381
|
+
return undefined;
|
382
|
+
}
|
386
383
|
|
387
384
|
const out: object = {};
|
388
385
|
|
@@ -27,7 +27,7 @@ export default function({ builtinFuncs }, Prefs) {
|
|
27
27
|
|
28
28
|
let ptr;
|
29
29
|
if (existingFunc) {
|
30
|
-
ptr =
|
30
|
+
ptr = builtin(name, true);
|
31
31
|
} else {
|
32
32
|
ptr = allocPage(scope, `builtin object: ${name}`);
|
33
33
|
}
|
@@ -90,15 +90,12 @@ export default function({ builtinFuncs }, Prefs) {
|
|
90
90
|
};
|
91
91
|
|
92
92
|
if (existingFunc) {
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
...originalWasm(...args)
|
100
|
-
];
|
101
|
-
};
|
93
|
+
this[name] = (scope, { builtin, funcRef }) => [
|
94
|
+
[ Opcodes.call, builtin('#get_' + name) ],
|
95
|
+
[ Opcodes.drop ],
|
96
|
+
...funcRef(name)
|
97
|
+
];
|
98
|
+
this[name].type = TYPES.function;
|
102
99
|
} else {
|
103
100
|
this[name] = (scope, { builtin }) => [
|
104
101
|
[ Opcodes.call, builtin('#get_' + name) ],
|
@@ -109,10 +106,9 @@ export default function({ builtinFuncs }, Prefs) {
|
|
109
106
|
|
110
107
|
for (const x in props) {
|
111
108
|
const d = props[x];
|
109
|
+
const k = prefix + x;
|
112
110
|
|
113
|
-
if (Object.hasOwn(d, 'value')) {
|
114
|
-
const k = prefix + x;
|
115
|
-
|
111
|
+
if (Object.hasOwn(d, 'value') && !Object.hasOwn(builtinFuncs, k) && !Object.hasOwn(this, k)) {
|
116
112
|
if (typeof d.value === 'number') {
|
117
113
|
this[k] = number(d.value);
|
118
114
|
this[k].type = TYPES.number;
|
@@ -159,7 +155,7 @@ export default function({ builtinFuncs }, Prefs) {
|
|
159
155
|
const builtinFuncKeys = Object.keys(builtinFuncs);
|
160
156
|
const autoFuncKeys = name => {
|
161
157
|
const prefix = makePrefix(name);
|
162
|
-
return builtinFuncKeys.filter(x => x.startsWith(prefix)).map(x => x.slice(prefix.length));
|
158
|
+
return builtinFuncKeys.filter(x => x.startsWith(prefix)).map(x => x.slice(prefix.length)).filter(x => !x.startsWith('prototype_'));
|
163
159
|
};
|
164
160
|
const autoFuncs = name => props({
|
165
161
|
writable: true,
|
@@ -209,7 +205,6 @@ export default function({ builtinFuncs }, Prefs) {
|
|
209
205
|
}
|
210
206
|
|
211
207
|
|
212
|
-
// todo: support when existing func
|
213
208
|
object('Number', {
|
214
209
|
...props({
|
215
210
|
writable: false,
|
@@ -227,9 +222,13 @@ export default function({ builtinFuncs }, Prefs) {
|
|
227
222
|
MIN_SAFE_INTEGER: valtype === 'i32' ? -2147483648 : -9007199254740991,
|
228
223
|
|
229
224
|
EPSILON: 2.220446049250313e-16
|
230
|
-
})
|
225
|
+
}),
|
226
|
+
|
227
|
+
...autoFuncs('Number')
|
231
228
|
});
|
232
229
|
|
230
|
+
object('Object', autoFuncs('Object'));
|
231
|
+
|
233
232
|
|
234
233
|
// these technically not spec compliant as it should be classes or non-enumerable but eh
|
235
234
|
object('navigator', {
|
@@ -305,8 +304,8 @@ export default function({ builtinFuncs }, Prefs) {
|
|
305
304
|
}
|
306
305
|
if (!t) continue;
|
307
306
|
|
308
|
-
if (!done.has(name)) {
|
309
|
-
console.log(name
|
307
|
+
if (!done.has(name) && !done.has('__' + name)) {
|
308
|
+
console.log(name, !!builtinFuncs[name]);
|
310
309
|
done.add(name);
|
311
310
|
}
|
312
311
|
}
|