Skip to content

Instantly share code, notes, and snippets.

@syg
syg / rabs.md
Last active June 18, 2020 00:25
ResizableArrayBuffer and GrowableSharedArrayBuffer

ResizableArrayBuffer and GrowableSharedArrayBuffer

WebAssembly and Web APIs that heavily use buffers (e.g., WebGPU, WebAudio) benefit from having more expressive buffers in addition to the current fixed-size ArrayBuffer and SharedArrayBuffer.

This proposal introduces two new buffer objects, as well as an extension to TypedArrays that lets the programmer create views that track the length of their underlying buffers.

WebAssembly's JS integration would then expose a ResizableArrayBuffer or a GrowableSharedArrayBuffer to avoid having to update all JS views when wasm memory grows.

APIs like WebGPU that wish to re-point ArrayBuffers can vend ResizableArrayBuffers instead, and can explain re-pointing under the hood as an atomic resizing + overwriting of contents.

let gListenersFR = new FinalizationRegistry(
({ socket, wrapper }) => socket.removeEventListener('message', wrapper));
class EventAccumulator {
constructor(socket) {
this.events = [];
this.listener = (ev) => { this.events.push(ev); };
let weakRef = new WeakRef(this.listener);
let wrapper = (ev) => { weakRef.deref()?.(ev); };
socket.addEventListener('message', wrapper);
@syg
syg / gc-embed.md
Created March 9, 2018 01:15 — forked from hotsphink/gc-embed.md
Spidermonkey GC API for Embedders

Managing pointers into the GC heap as an embedder

When you have GC pointers (pointers to JS objects, strings, etc.; anything stored directly in the GC heap), you need to handle them specially if they could ever be stored during a collection. I'll first describe what you need to do, then how to do it, and finally why and what happens if you get it wrong.

tracing - strong GC references must be traced so that the GC knows what to keep alive.

pre-write barriers aka delete barrier - if you overwrite a GC pointer, you'll need to let the GC know.

post-write barriers - after storing a GC pointer somewhere, you need to inform the GC of the new value (or more specifically, the address of the new value.)

diff --git a/src/profiler/heap-snapshot-generator.cc b/src/profiler/heap-snapshot-generator.cc
index c80877f623..fad693d3be 100644
--- a/src/profiler/heap-snapshot-generator.cc
+++ b/src/profiler/heap-snapshot-generator.cc
@@ -953,6 +953,7 @@ const char* V8HeapExplorer::GetSystemEntryName(HeapObject* object) {
case NAME##_TYPE: return "system / "#Name;
STRUCT_LIST(MAKE_STRUCT_CASE)
#undef MAKE_STRUCT_CASE
+ case WEAK_CELL_TYPE: return "system / WeakCell";
default: return "system";
pikashu ~/moz/central/js/src/Debug master
% cat test.js
var a = 'a';
var b = 'b';
function f(c = ({[eval("var global='g'")]: a},
{[eval("print(global); global")]: b}))
{
}
f();
Legacy Generators
=================
Allowed only in versioned JS >= 1.7
The syntax and semantics as currently supported by SpiderMonkey are as follows.
Syntax and static semantics
---------------------------
commit 8fa2597ffad99a337cc7aa1c258b240b8e961add
Author: Shu-yu Guo <shu@rfrn.org>
Date: Fri Apr 24 16:20:04 2015 -0700
WIP tree-model inverted
diff --git a/browser/devtools/performance/modules/recording-utils.js b/browser/devtools/performance/modules/recording-utils.js
index 1b570f3..3d0710c 100644
--- a/browser/devtools/performance/modules/recording-utils.js
+++ b/browser/devtools/performance/modules/recording-utils.js
"mirType": "Object",
"site": "Receiver",
"types": [
{
"keyedBy": "alloc site",
"line": 5,
"location": "file:///home/shu/example-other.js",
"name": "[object Uint8Array]"
}
--
This file has been truncated, but you can view the full file.
Richards: 335
----
Score (version 9): 335
{
"libs": "[{\"start\":4194304,\"end\":4417764,\"offset\":0,\"name\":\"\",\"breakpadId\":\"\"},{\"start\":140735774629888,\"end\":140735774634215,\"offset\":0,\"name\":\"linux-vdso.so.1\",\"breakpadId\":\"\"},{\"start\":140634688413696,\"end\":140634690630800,\"offset\":0,\"name\":\"/usr/lib/libpthread.so.0\",\"breakpadId\":\"2BC6EF306368D5340311DCCBC3863DD30\"},{\"start\":140634692669440,\"end\":140634692678584,\"offset\":0,\"name\":\"/home/shu/moz/central/obj-dbg/dist/bin/libmozalloc.so\",\"breakpadId\":\"5F9232AE3A23CA46462270D26E2B90EE0\"},{\"start\":140634692648960,\"end\":140634692667268,\"offset\":0,\"name\":\"/home/shu/moz/central/obj-dbg/dist/bin/libplds4.so\",\"breakpadId\":\"4694690653514C68BECB35B6EFBBD37B0\"},{\"start\":140634692616192,\"end\":140634692642009,\"offset\":0,\"name\":\"/home/shu/moz/central/obj-dbg/dist/bin/libplc4.so\",\"breakpadId\":\"ACA3B80B118CC67919FE85BE81D1E0D30\"},{\"start\":140634692239360,\"end\":140634692614312,\"offset\":0,\"n