MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix __proto__ assignment

+77 -17
+1 -1
meson.build
··· 79 79 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 80 80 81 81 version_conf = configuration_data() 82 - version_conf.set('ANT_VERSION', '0.2.2.38') 82 + version_conf.set('ANT_VERSION', '0.2.2.39') 83 83 version_conf.set('ANT_GIT_HASH', git_hash) 84 84 version_conf.set('ANT_BUILD_DATE', build_date) 85 85
+17 -3
src/ant.c
··· 4316 4316 jsval_t obj = mkval(T_OBJ, obj_off); 4317 4317 if (is_proxy(js, obj)) return proxy_get(js, obj, key_str, len); 4318 4318 4319 + if (len == STR_PROTO_LEN && memcmp(key_str, STR_PROTO, STR_PROTO_LEN) == 0) { 4320 + jsval_t proto = get_slot(js, obj, SLOT_PROTO); 4321 + if (vtype(proto) != T_UNDEF) return proto; 4322 + return get_prototype_for_type(js, vtype(obj)); 4323 + } 4324 + 4319 4325 jsval_t accessor_result; 4320 4326 if (try_accessor_getter(js, obj, key_str, len, &accessor_result)) { 4321 4327 return accessor_result; ··· 4428 4434 4429 4435 jsoff_t key_len; 4430 4436 const char *key_str = (const char *)&js->mem[vstr(js, key, &key_len)]; 4437 + 4438 + if (key_len == STR_PROTO_LEN && memcmp(key_str, STR_PROTO, STR_PROTO_LEN) == 0) { 4439 + uint8_t vt = vtype(val); 4440 + if (vt == T_OBJ || vt == T_NULL) { 4441 + set_slot(js, obj, SLOT_PROTO, val); 4442 + return val; 4443 + } 4444 + return val; 4445 + } 4431 4446 4432 4447 jsval_t setter_result; 4433 4448 if (try_accessor_setter(js, obj, key_str, key_len, val, &setter_result)) { ··· 4761 4776 } 4762 4777 4763 4778 if (plen == STR_PROTO_LEN && memcmp(ptr, STR_PROTO, STR_PROTO_LEN) == 0) { 4764 - jsval_t proto = get_slot(js, l, SLOT_PROTO); 4765 - if (vtype(proto) != T_UNDEF) return proto; 4766 - return get_prototype_for_type(js, t); 4779 + jsval_t key = js_mkstr(js, ptr, plen); 4780 + return mkpropref((jsoff_t)vdata(l), (jsoff_t)vdata(key)); 4767 4781 } 4768 4782 4769 4783 jsoff_t own_off = lkp(js, l, ptr, plen);
+59 -13
src/modules/buffer.c
··· 271 271 double num_val = js_type(value) == JS_NUM ? js_getnum(value) : 0; 272 272 uint8_t *data = ta_data->buffer->data + ta_data->byte_offset; 273 273 274 - switch (ta_data->type) { 275 - case TYPED_ARRAY_INT8: ((int8_t*)data)[index] = (int8_t)num_val; break; 276 - case TYPED_ARRAY_UINT8: 277 - case TYPED_ARRAY_UINT8_CLAMPED: ((uint8_t*)data)[index] = (uint8_t)num_val; break; 278 - case TYPED_ARRAY_INT16: ((int16_t*)data)[index] = (int16_t)num_val; break; 279 - case TYPED_ARRAY_UINT16: ((uint16_t*)data)[index] = (uint16_t)num_val; break; 280 - case TYPED_ARRAY_INT32: ((int32_t*)data)[index] = (int32_t)num_val; break; 281 - case TYPED_ARRAY_UINT32: ((uint32_t*)data)[index] = (uint32_t)num_val; break; 282 - case TYPED_ARRAY_FLOAT32: ((float*)data)[index] = (float)num_val; break; 283 - case TYPED_ARRAY_FLOAT64: ((double*)data)[index] = num_val; break; 284 - default: return false; 285 - } 286 - return true; 274 + static const void *dispatch[] = { 275 + &&S_INT8, &&S_UINT8, &&S_UINT8, &&S_INT16, &&S_UINT16, 276 + &&S_INT32, &&S_UINT32, &&S_FLOAT32, &&S_FLOAT64, &&S_FAIL, &&S_FAIL 277 + }; 278 + 279 + if (ta_data->type > TYPED_ARRAY_BIGUINT64) goto S_FAIL; 280 + goto *dispatch[ta_data->type]; 281 + 282 + S_INT8: ((int8_t*)data)[index] = (int8_t)num_val; goto S_DONE; 283 + S_UINT8: data[index] = (uint8_t)num_val; goto S_DONE; 284 + S_INT16: ((int16_t*)data)[index] = (int16_t)num_val; goto S_DONE; 285 + S_UINT16: ((uint16_t*)data)[index] = (uint16_t)num_val; goto S_DONE; 286 + S_INT32: ((int32_t*)data)[index] = (int32_t)num_val; goto S_DONE; 287 + S_UINT32: ((uint32_t*)data)[index] = (uint32_t)num_val; goto S_DONE; 288 + S_FLOAT32: ((float*)data)[index] = (float)num_val; goto S_DONE; 289 + S_FLOAT64: ((double*)data)[index] = num_val; goto S_DONE; 290 + S_FAIL: return false; 291 + S_DONE: return true; 287 292 } 288 293 289 294 static jsval_t create_typed_array(struct js *js, TypedArrayType type, ArrayBufferData *buffer, size_t byte_offset, size_t length, const char *type_name) { ··· 349 354 } 350 355 351 356 return create_typed_array(js, type, buffer, byte_offset, length, type_name); 357 + } 358 + 359 + int arg_type = js_type(args[0]); 360 + if (arg_type == JS_OBJ) { 361 + jsval_t len_val = js_get(js, args[0], "length"); 362 + if (js_type(len_val) == JS_NUM) { 363 + size_t length = (size_t)js_getnum(len_val); 364 + size_t element_size = get_element_size(type); 365 + ArrayBufferData *buffer = create_array_buffer_data(length * element_size); 366 + if (!buffer) return js_mkerr(js, "Failed to allocate buffer"); 367 + 368 + jsval_t result = create_typed_array(js, type, buffer, 0, length, type_name); 369 + uint8_t *data = buffer->data; 370 + 371 + static const void *write_dispatch[] = { 372 + &&W_INT8, &&W_UINT8, &&W_UINT8, &&W_INT16, &&W_UINT16, 373 + &&W_INT32, &&W_UINT32, &&W_FLOAT32, &&W_FLOAT64, &&W_DONE, &&W_DONE 374 + }; 375 + 376 + for (size_t i = 0; i < length; i++) { 377 + char idx_str[16]; 378 + snprintf(idx_str, sizeof(idx_str), "%zu", i); 379 + jsval_t elem = js_get(js, args[0], idx_str); 380 + double val = js_type(elem) == JS_NUM ? js_getnum(elem) : 0; 381 + 382 + if (type > TYPED_ARRAY_BIGUINT64) goto W_DONE; 383 + goto *write_dispatch[type]; 384 + 385 + W_INT8: ((int8_t*)data)[i] = (int8_t)val; goto W_NEXT; 386 + W_UINT8: data[i] = (uint8_t)val; goto W_NEXT; 387 + W_INT16: ((int16_t*)data)[i] = (int16_t)val; goto W_NEXT; 388 + W_UINT16: ((uint16_t*)data)[i] = (uint16_t)val; goto W_NEXT; 389 + W_INT32: ((int32_t*)data)[i] = (int32_t)val; goto W_NEXT; 390 + W_UINT32: ((uint32_t*)data)[i] = (uint32_t)val; goto W_NEXT; 391 + W_FLOAT32: ((float*)data)[i] = (float)val; goto W_NEXT; 392 + W_FLOAT64: ((double*)data)[i] = val; goto W_NEXT; 393 + W_NEXT:; 394 + } 395 + W_DONE: 396 + return result; 397 + } 352 398 } 353 399 354 400 return js_mkerr(js, "Invalid TypedArray constructor arguments");