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.

get active coro for current vm

+39 -1
+7
src/modules/buffer.c
··· 473 473 return js_bool(data->is_detached); 474 474 } 475 475 476 + // ArrayBuffer.isView(value) 477 + static ant_value_t js_arraybuffer_isView(ant_t *js, ant_value_t *args, int nargs) { 478 + if (nargs < 1) return js_false; 479 + return js_bool(buffer_is_dataview(args[0]) || buffer_get_typedarray_data(args[0]) != NULL); 480 + } 481 + 476 482 static ant_value_t typedarray_index_getter(ant_t *js, ant_value_t obj, const char *key, size_t key_len) { 477 483 if (key_len == 0 || key_len > 10) return js_mkundef(); 478 484 ··· 2566 2572 js_mkprop_fast(js, arraybuffer_ctor_obj, "prototype", 9, arraybuffer_proto); 2567 2573 js_mkprop_fast(js, arraybuffer_ctor_obj, "name", 4, ANT_STRING("ArrayBuffer")); 2568 2574 js_set_descriptor(js, arraybuffer_ctor_obj, "name", 4, 0); 2575 + js_set(js, arraybuffer_ctor_obj, "isView", js_mkfun(js_arraybuffer_isView)); 2569 2576 js_define_species_getter(js, arraybuffer_ctor_obj); 2570 2577 ant_value_t arraybuffer_ctor = js_obj_to_func(arraybuffer_ctor_obj); 2571 2578 js_set(js, arraybuffer_proto, "constructor", arraybuffer_ctor);
+16 -1
src/silver/ops/async.h
··· 100 100 coro->active_parent = NULL; 101 101 } 102 102 103 + static inline coroutine_t *sv_async_get_active_coro_for_vm(ant_t *js, sv_vm_t *vm) { 104 + if (!js || !js->active_async_coro) return NULL; 105 + 106 + coroutine_t *fallback = js->active_async_coro; 107 + if (!vm) return fallback; 108 + 109 + for (coroutine_t *it = fallback; it; it = it->active_parent) { 110 + if (it->owner_vm == vm) return it; 111 + } 112 + 113 + return fallback; 114 + } 115 + 103 116 static inline void sv_async_init_activation( 104 117 coroutine_t *coro, ant_t *js, sv_vm_t *owner_vm, ant_value_t promise, 105 118 ant_value_t this_val, ant_value_t super_val, ant_value_t new_target, ··· 614 627 return promise; 615 628 } 616 629 630 + 631 + 617 632 static inline ant_value_t sv_await_value(sv_vm_t *vm, ant_t *js, ant_value_t value) { 618 633 value = js_promise_assimilate_awaitable(js, value); 619 634 if (is_err(value)) return value; ··· 626 641 if (current_mco) { 627 642 sv_coro_header_t *hdr = (sv_coro_header_t *)mco_get_user_data(current_mco); 628 643 if (hdr) coro = hdr->coro; 629 - } else if (js->active_async_coro) coro = js->active_async_coro; 644 + } else coro = sv_async_get_active_coro_for_vm(js, vm); 630 645 631 646 if (!coro) 632 647 return js_mkerr(js, "await can only be used inside async functions");
+16
tests/test_arraybuffer_isview.cjs
··· 1 + const assert = require('assert'); 2 + 3 + assert.equal(typeof ArrayBuffer.isView, 'function'); 4 + 5 + const buffer = new ArrayBuffer(16); 6 + const u8 = new Uint8Array(buffer); 7 + const dv = new DataView(buffer); 8 + 9 + assert.equal(ArrayBuffer.isView(u8), true); 10 + assert.equal(ArrayBuffer.isView(dv), true); 11 + assert.equal(ArrayBuffer.isView(buffer), false); 12 + assert.equal(ArrayBuffer.isView({}), false); 13 + assert.equal(ArrayBuffer.isView(null), false); 14 + assert.equal(ArrayBuffer.isView(undefined), false); 15 + 16 + console.log('ArrayBuffer.isView regression checks passed');