porffor 0.37.25 → 0.37.27

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.
@@ -532,6 +532,24 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any) => {
532
532
  if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
533
533
  if (!Porffor.object.isObject(desc)) throw new TypeError('Descriptor is a non-object');
534
534
 
535
+ if (Porffor.rawType(target) == Porffor.TYPES.array) {
536
+ const tmp1: bytestring = 'length';
537
+ const tmp2: bytestring = 'value';
538
+ if (prop === tmp1 && __Object_hasOwn(desc, tmp2)) {
539
+ const v: any = desc.value;
540
+ const n: number = ecma262.ToNumber(v);
541
+ if (Porffor.fastOr(
542
+ Number.isNaN(n), // NaN
543
+ Math.floor(n) != n, // non integer
544
+ n < 0, // negative
545
+ n >= 4294967296, // > 2**32 - 1
546
+ )) throw new RangeError('Invalid array length');
547
+
548
+ // set real array length
549
+ Porffor.wasm.i32.store(target, n, 0, 0);
550
+ }
551
+ }
552
+
535
553
  const p: any = ecma262.ToPropertyKey(prop);
536
554
 
537
555
  // base keys
@@ -106,6 +106,11 @@ export default function({ builtinFuncs }, Prefs) {
106
106
  const k = prefix + x;
107
107
 
108
108
  if (Object.hasOwn(d, 'value') && !Object.hasOwn(builtinFuncs, k) && !Object.hasOwn(this, k)) {
109
+ if (Array.isArray(d.value) || typeof d.value === 'function') {
110
+ this[k] = d.value;
111
+ continue;
112
+ }
113
+
109
114
  if (typeof d.value === 'number') {
110
115
  this[k] = number(d.value);
111
116
  this[k].type = TYPES.number;
@@ -196,6 +201,20 @@ export default function({ builtinFuncs }, Prefs) {
196
201
  // special case: Object.prototype.__proto__ = null
197
202
  if (x === '__Object_prototype') Object.defineProperty(props, '__proto__', { value: { value: null }, enumerable: true });
198
203
 
204
+ // add constructor for constructors
205
+ const name = x.slice(2, x.indexOf('_', 2));
206
+ if (builtinFuncs[name]?.constr) {
207
+ const value = (scope, { funcRef }) => funcRef(name);
208
+ value.type = TYPES.function;
209
+
210
+ props.constructor = {
211
+ value,
212
+ writable: true,
213
+ enumerable: false,
214
+ configurable: true
215
+ };
216
+ }
217
+
199
218
  object(x, props);
200
219
  }
201
220