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 Uint8Array constructor validation

+15 -7
+4 -1
examples/spec/buffer.js
··· 1 - import { test, summary } from './helpers.js'; 1 + import { test, testThrows, summary } from './helpers.js'; 2 2 3 3 console.log('Buffer Tests\n'); 4 4 ··· 12 12 test('Uint8Array length', u8.length, 8); 13 13 test('Uint8Array byteLength', u8.byteLength, 8); 14 14 test('Uint8Array BYTES_PER_ELEMENT', u8.BYTES_PER_ELEMENT, 1); 15 + test('Uint8Array with new', new Uint8Array(5).length, 5); 16 + test('Uint8Array via Reflect.construct', Reflect.construct(Uint8Array, [5]).length, 5); 17 + testThrows('Uint8Array without new throws', () => Uint8Array(5)); 15 18 16 19 const i16 = new Int16Array(4); 17 20 test('Int16Array length', i16.length, 4);
+2 -2
src/modules/observable.c
··· 387 387 return js_mkerr_typed(js, JS_ERR_TYPE, "Iterator must return an object"); 388 388 } 389 389 390 - jsval_t nextMethod = js_get(js, iterator, "next"); 390 + jsval_t nextMethod = js_getprop_fallback(js, iterator, "next"); 391 391 if (!is_callable(nextMethod)) { 392 392 return js_mkerr_typed(js, JS_ERR_TYPE, "Iterator must have a next method"); 393 393 } ··· 411 411 } 412 412 413 413 if (is_special_object(subscription) && subscription_closed(js, subscription)) { 414 - jsval_t returnMethod = js_get(js, iterator, "return"); 414 + jsval_t returnMethod = js_getprop_fallback(js, iterator, "return"); 415 415 if (is_callable(returnMethod)) js_call_with_this(js, returnMethod, iterator, NULL, 0); 416 416 return js_mkundef(); 417 417 }
+9 -4
src/modules/textcodec.c
··· 17 17 18 18 if (nargs > 0 && vtype(args[0]) == T_STR) { 19 19 str = js_getstr(js, args[0], &str_len); 20 - if (!str) { 21 - str = ""; 22 - str_len = 0; 23 - } 20 + if (!str) { str = ""; str_len = 0; } 24 21 } 25 22 26 23 jsval_t glob = js_glob(js); 27 24 jsval_t uint8array_ctor = js_get(js, glob, "Uint8Array"); 28 25 26 + if (vtype(uint8array_ctor) != T_FUNC && vtype(uint8array_ctor) != T_CFUNC) { 27 + return js_mkerr_typed(js, JS_ERR_TYPE, "Uint8Array constructor missing"); 28 + } 29 + 29 30 jsval_t len_arg = js_mknum((double)str_len); 31 + jsval_t saved_new_target = js->new_target; 32 + 33 + js->new_target = uint8array_ctor; 30 34 jsval_t arr = js_call(js, uint8array_ctor, &len_arg, 1); 31 35 36 + js->new_target = saved_new_target; 32 37 if (vtype(arr) == T_ERR) return arr; 33 38 34 39 if (str_len > 0) {